本文整理汇总了C++中Genome::chromosome方法的典型用法代码示例。如果您正苦于以下问题:C++ Genome::chromosome方法的具体用法?C++ Genome::chromosome怎么用?C++ Genome::chromosome使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Genome
的用法示例。
在下文中一共展示了Genome::chromosome方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crossover
void Genome::crossover(const Genome &with,Genome &baby1,Genome &baby2)
{
baby1.setFitness(0.0);
baby2.setFitness(0.0);
int crossoverPoint = NeuralNetRandom::RandomInt(0,numberOfGenes()-1);
std::vector<double> newChromosome1;
std::vector<double> newChromosome2;
std::vector<double>::iterator myGenes = _chromosome.begin();
std::vector<double> otherChromosome = with.chromosome();
std::vector<double>::iterator otherGenes = otherChromosome.begin();
if (crossoverPoint > 0)
{
newChromosome1.assign(myGenes,myGenes+crossoverPoint+1);
newChromosome2.assign(otherGenes,otherGenes+crossoverPoint+1);
}
newChromosome1.insert(newChromosome1.end(),otherGenes+crossoverPoint,otherChromosome.end());
newChromosome2.insert(newChromosome2.end(),myGenes+crossoverPoint,_chromosome.end());
baby1.setChromosome(newChromosome1);
baby2.setChromosome(newChromosome2);
}
示例2: mutate
void Genome::mutate(Genome &theGenome)
{
std::vector<double> chromosome = theGenome.chromosome();
for (int i=0;i<(int)chromosome.size();++i)
{
if (NeuralNetRandom::RandomFloat() < MutationRate)
chromosome[i] += NeuralNetRandom::RandomClamped()*MaxMutationPerturbation;
}
theGenome.setChromosome(chromosome);
}
示例3: sex
void Genome::sex(const Genome &with,Genome &baby1,Genome &baby2)
{
if (_chromosome.size() != with.chromosome().size())
{
std::cerr << "Genome::sex - incompatible chromosomes!" << std::endl;
return;
}
if ((with==*this)||(NeuralNetRandom::RandomFloat()>CrossoverRate))
{
baby1 = *this;
baby2 = with;
}
else
{
crossover(with,baby1,baby2);
}
mutate(baby1);
mutate(baby2);
}
示例4: load_chromosomes
int load_chromosomes(Genome & genome, VariantMap & variants, GenomeMaps & genome_mask)
{
unsigned int eof = 0;
unsigned int chr = 0;
POS p;
BLOCK = 0;
char CHR_DESC_TMP_orig[1000];
strcpy(CHR_DESC_TMP_orig, CHR_DESC_TMP) ;
// alloc all seeds present in masked regions, do not add kmers
if (has_genome_mask && genome_mask_use_rep_seeds)
{
unsigned long int fp = ftell(GENOME_FP);
while (!eof) {
if (VERBOSE) {
printf("Start chromosome nb. %d\n", chr+1);
}
eof = load_chr();
p.chr = chr;
p.pos = 0;
BLOCK_TABLE[BLOCK] = p;
POSITION = 0;
if (VERBOSE) {
printf("\tLength %d\n", CHR_LENGTH);
}
if (strlen(GENOME_VARIANTS_FILE_NAME)==0)
index_chromosome_novariants(chr, genome, genome_mask, true, false, false);
else
index_chromosome(chr, genome, variants, genome_mask, true, false, false);
++BLOCK;
++chr;
}
// reset file handle & counters
fseek(GENOME_FP, fp, SEEK_SET) ;
eof = 0;
chr = 0;
BLOCK = 0;
strcpy(CHR_DESC_TMP, CHR_DESC_TMP_orig) ;
}
// alloc all seeds present in masked regions, do not add kmers
if (has_genome_mask && genome_mask_use_secondary_regions)
{
unsigned long int fp = ftell(GENOME_FP);
while (!eof) {
if (VERBOSE) {
printf("Start chromosome nb. %d\n", chr+1);
}
eof = load_chr();
p.chr = chr;
p.pos = 0;
BLOCK_TABLE[BLOCK] = p;
POSITION = 0;
if (VERBOSE) {
printf("\tLength %d\n", CHR_LENGTH);
}
if (strlen(GENOME_VARIANTS_FILE_NAME)==0)
index_chromosome_novariants(chr, genome, genome_mask, false, true, false);
else
index_chromosome(chr, genome, variants, genome_mask, false, true, false);
int num_hits=0 ;
int start_pos=0 ;
int num_regions=0 ;
int num_positions=0 ;
int winlen=0 ;
int num_hits_win = 0 ;
const int target_winlen=100 ;
for (unsigned int pos=0; pos<CHR_LENGTH; pos++)
{
char elem=genome_mask.CHR_MAP(genome.chromosome(chr), pos) ;
if ((elem & MASK_REGION_SECONDARY)>0)
{
start_pos=pos ;
num_hits++ ;
if (num_hits==secondary_min_num_hits)
num_regions++ ;
num_hits_win++ ;
}
else
num_hits=0 ;
winlen++ ;
if (winlen>=target_winlen)
{
if ((int)pos>=winlen)
if ((genome_mask.CHR_MAP(genome.chromosome(chr), pos-winlen) & MASK_REGION_SECONDARY)>0)
num_hits_win-=1 ;
winlen-- ;
//.........这里部分代码省略.........