double Genome::GetGeneticalDistanceFrom(const Genome& other) const { double totalWeightDifference = 0.0; size_t numberOfOverlapingGenes = 0; size_t sizeOfSmallerGenome = min(this->GetGeneCount(), other.GetGeneCount()); auto IsHistoricalMarkingSameAt = [&](size_t i) { return this->GetGeneAt(i).historicalMarking == other[i].historicalMarking; }; for (size_t i = 0; i < sizeOfSmallerGenome && IsHistoricalMarkingSameAt(i); ++i) { totalWeightDifference += (double)abs(this->GetGeneAt(i).weight - other[i].weight); ++numberOfOverlapingGenes; } auto numberOfDisjointGenes = this->GetGeneCount() + other.GetGeneCount() - (size_t)2 * numberOfOverlapingGenes; auto sizeOfBiggerGenome = max(this->GetGeneCount(), other.GetGeneCount()); // TODO jnf: Think how we'll handle the next line auto disjointGenesInfluence = (double)numberOfDisjointGenes /* / (double)sizeOfBiggerGenome*/; auto averageWeightDifference = totalWeightDifference / (double)numberOfOverlapingGenes; disjointGenesInfluence *= (double)parameters.advanced.speciation.importanceOfDisjointGenes; averageWeightDifference *= (double)parameters.advanced.speciation.importanceOfAverageWeightDifference; return disjointGenesInfluence + averageWeightDifference; }
Genome* AverageCombinator::combine(Genome *x, Genome *y) { srand ( time(NULL) ); int size = x->get_size( ); Genome *z = new Genome(); double chanceFactor = 0.5; for(int i = 0; i < size; i++) { double chance = (((double) rand()) / RAND_MAX+1); if(chance < chanceFactor) { double totalTime = x->get_gene(i)->getTime().getTimeInMinutes() + y->get_gene(i)->getTime().getTimeInMinutes(); Time t; t.addMinute(floor((totalTime / 2) + 0.5)); z->add_gene(x->get_gene(i)->getPlane(), t); } else if(chance < 0.75) { z->add_gene( x->get_gene(i)->getPlane(), x->get_gene(i)->getTime()); } else { z->add_gene( y->get_gene(i)->getPlane(), y->get_gene(i)->getTime()); } } return z; }
void DownPropagator::propagateFitnesses(Individual ** population, int populationSize) { int tempFitness; Genome * tempGenome; GeneNode ** tempPools; int tempGenomeLength; int * tempIndexes; for (int i = 0; i < populationSize; i++) { tempFitness = population[i]->getFitness(); tempGenome = population[i]->getGenome(); tempPools = tempGenome->getGeneNodes(); tempGenomeLength = tempGenome->getGenomeLength(); tempIndexes = tempGenome->getGenome(); for (int k = 0; k < tempGenomeLength; k++) { if (tempPools[k]->getFitnessAtIndex(tempIndexes[k]) < tempFitness) { tempPools[k]->setFitnessAtIndex(tempIndexes[k], tempFitness); } //TODO: Find a more efficient (read: not n^2) way to do //this tempPools[k]->propagateFitnesses(); } } }
Genome Breeder::replicateGenome(const DNA& parent) { Genome newGenome; const real32* parentWeights = parent.genome.readWeights(); real32* weights = newGenome.editWeights(); int32 mutationCount = 0; for (uint32 i = 0; i < newGenome.getLength(); i++) { const int32 dice = RandomGen::randomInt(0, parent.traits.mutationRate); if (dice >= 670) { weights[i] = parentWeights[i]; } else if (dice >= 335) { weights[i] = parentWeights[i] + RandomGen::randomFloat(-0.5f, 0.5f); mutationCount++; } else { weights[i] = Genome::randomGenomeWeight(); mutationCount++; } } std::stringstream sb; sb << "mutation count: " << mutationCount; Console::write(sb.str()); return newGenome; }
void LodExtract::writeSequences(const Genome* inParent, const vector<const Genome*>& inChildren) { vector<const Genome*> inGenomes = inChildren; inGenomes.push_back(inParent); const Genome* outParent = _outAlignment->openGenome(inParent->getName()); (void)outParent; assert(outParent != NULL && outParent->getNumBottomSegments() > 0); string buffer; for (hal_size_t i = 0; i < inGenomes.size(); ++i) { const Genome* inGenome = inGenomes[i]; Genome* outGenome = _outAlignment->openGenome(inGenome->getName()); if (inGenome == inParent || outGenome->getNumChildren() == 0) { SequenceIteratorConstPtr inSeqIt = inGenome->getSequenceIterator(); SequenceIteratorConstPtr end = inGenome->getSequenceEndIterator(); for (; inSeqIt != end; inSeqIt->toNext()) { const Sequence* inSequence = inSeqIt->getSequence(); if (inSequence->getSequenceLength() > 0) { Sequence* outSequence = outGenome->getSequence(inSequence->getName()); assert(outSequence != NULL); inSequence->getString(buffer); outSequence->setString(buffer); } } } } }
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); }
void FullRun::displayResult(void) { unsigned long numRecombinant = 0; unsigned long numLongRec = 0; for (unsigned long i = 0; i < childDataset->getSize(); i++) { Genome* child = childDataset->getGenome(i); if (child->getRecombinantType() != Genome::Na_REC) { numRecombinant++; } if (child->getRecombinantType() == Genome::LONG_REC) { numLongRec++; if (fileLongRecombinants != NULL) { fileLongRecombinants->writeLine(child->getAccession()); } } } Interface::instance() << "Number of triples tested : " << getNumTotalTriplets() << "\n" << "Number of p-values computed exactly : " << numComputedExactly << "\n" << "Number of p-values approximated (HS) : " << numApproximated << "\n" << "Number of p-values not computed : " << numSkipped << "\n" << endl << "Number of recombinant triplets : \t" << numRecombinantTriplets << "\n" << "Number of distinct recombinant sequences : \t" << numRecombinant << "\n"; if (cloStopAtFirstRecombinant) { Interface::instance() << "[[ search stopped when first one found ]]\n" << endl; } if (!cloNoBpCalculated) { Interface::instance() << "Number of distinct recombinant sequences at least " << cloMinLongRecombinantLength << "nt long : \t" << numLongRec << "\n" << "Longest of short recombinant segments : \t" << longestRecombinantSegment << "nt\n"; } Interface::instance().showOutput(true); Interface::instance() << Interface::SEPARATOR << endl; Interface::instance().showLog(true); char formatedPVal[20]; sprintf(formatedPVal, "%1.3e", static_cast<double> (stats::correction::dunnSidak(minPVal, getNumTripletsForCorrection())) ); Interface::instance() << "Rejection of the null hypothesis of clonal evolution at p = " << stats::correction::dunnSidak(minPVal, getNumTripletsForCorrection()) << "\n" << " p = " << formatedPVal << "\n" << " Uncorrected p = " << minPVal << "\n" << " Bonferroni p = " << stats::correction::bonferroni(minPVal, getNumTripletsForCorrection()) << "\n"; Interface::instance().showOutput(true); }
void GenomeMetaTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); MetaData *ancMeta = ancGenome->getMetaData(); ancMeta->set("Young", "Jeezy"); }
SolverEvolver::Genome SolverEvolver::random_genome() { Genome ret; for (int i = 0; i < ret.size(); ++i) { ret[i] = random_double(0.0f); } return std::move(ret); }
void Trainer::init() { for (unsigned int i = 0; i < N_AGENTS; i++) { Genome genome; genome.initRandomData(); Agent *agent = new Agent(genome); agents.push_back(agent); } }
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); }
void TopSegmentSequenceTest::createCallBack(Alignment *alignment) { Genome *ancGenome = alignment->addRootGenome("Anc0", 0); vector<Sequence::Info> seqVec(1); seqVec[0] = Sequence::Info("Sequence", 1000000, 5000, 700000); ancGenome->setDimensions(seqVec); ancGenome->setSubString("CACACATTC", 500, 9); TopSegmentIteratorPtr tsIt = ancGenome->getTopSegmentIterator(100); tsIt->getTopSegment()->setCoordinates(500, 9); }
int main() { const unsigned mutations=2; Genome::set_mutations_at_cloning(mutations); std::cout<<"[Cloning with "<<mutations<<" mutations.]"<<std::endl; Genome A; std::cout<<"HEALTHY GENOME: "<<std::endl<<" "<<A<<std::endl; std::cout<<" Bad mutations within first 10 years = "<<A.bad_mutations(10)<<std::endl; Genome B=A.clone(); std::cout<<"AFTER 1st CLONING: "<<std::endl<<" "<<B<<std::endl; std::cout<<" Bad mutations within the whole Genome = "<<B.bad_mutations(Genome::max_age-1)<<std::endl; for (unsigned i=0; i<5; ++i) { A=B.clone(); B=A.clone(); } std::cout<<"AFTER 10 MORE CLONINGS: "<<std::endl<<" "<<A<<std::endl; std::cout<<" Bad mutations within first 5 years = "<<A.bad_mutations(5)<<std::endl; std::cout<<"AFTER 1 MORE CLONING: "<<std::endl<<" "<<B<<std::endl; std::cout<<" Bad mutations within first 10 years = "<<A.bad_mutations(10)<<std::endl; for (unsigned i=0; i<50; ++i) { A=B.clone(); B=A.clone(); } std::cout<<"AFTER 100 MORE CLONINGS: "<<std::endl<<" "<<A<<std::endl; std::cout<<" Bad mutations within first 2 years = "<<A.bad_mutations(2)<<std::endl; std::cout<<"AFTER 1 MORE CLONING: "<<std::endl<<" "<<B<<std::endl; std::cout<<" Bad mutations within first 2 years = "<<A.bad_mutations(2)<<std::endl; return 0; }
Agent * add_agent(char * filename, Agent *mother) { Genome * myGenome; myGenome = new Genome(filename); Agent * newAgent; char portNum[256]; sprintf(portNum, "%i", curPort); int pid = myGenome->buildOrganismFromGenome(portNum); newAgent = new Agent(myGenome, pid, curPort++); agents.push_back(newAgent); printf("loaded %s on port %i (%p)\n", filename, newAgent->get_port(), newAgent); return newAgent; }
void FONSEModel::calculateLogLikelihoodRatioPerGroupingPerCategory(std::string grouping, Genome& genome, std::vector<double> &logAcceptanceRatioForAllMixtures) { int numGenes = genome.getGenomeSize(); //int numCodons = SequenceSummary::GetNumCodonsForAA(grouping); double likelihood = 0.0; double likelihood_proposed = 0.0; double mutation[5]; double selection[5]; double mutation_proposed[5]; double selection_proposed[5]; std::string curAA; Gene *gene; SequenceSummary *sequenceSummary; unsigned aaIndex = SequenceSummary::AAToAAIndex(grouping); #ifdef _OPENMP //#ifndef __APPLE__ #pragma omp parallel for private(mutation, selection, mutation_proposed, selection_proposed, curAA, gene, sequenceSummary) reduction(+:likelihood,likelihood_proposed) #endif for (unsigned i = 0u; i < numGenes; i++) { gene = &genome.getGene(i); sequenceSummary = gene->getSequenceSummary(); if (sequenceSummary->getAACountForAA(aaIndex) == 0) continue; // which mixture element does this gene belong to unsigned mixtureElement = parameter->getMixtureAssignment(i); // how is the mixture element defined. Which categories make it up unsigned mutationCategory = parameter->getMutationCategory(mixtureElement); unsigned selectionCategory = parameter->getSelectionCategory(mixtureElement); unsigned expressionCategory = parameter->getSynthesisRateCategory(mixtureElement); // get phi value, calculate likelihood conditional on phi double phiValue = parameter->getSynthesisRate(i, expressionCategory, false); // get current mutation and selection parameter parameter->getParameterForCategory(mutationCategory, FONSEParameter::dM, grouping, false, mutation); parameter->getParameterForCategory(selectionCategory, FONSEParameter::dOmega, grouping, false, selection); // get proposed mutation and selection parameter parameter->getParameterForCategory(mutationCategory, FONSEParameter::dM, grouping, true, mutation_proposed); parameter->getParameterForCategory(selectionCategory, FONSEParameter::dOmega, grouping, true, selection_proposed); likelihood += calculateLogLikelihoodRatioPerAA(*gene, grouping, mutation, selection, phiValue); likelihood_proposed += calculateLogLikelihoodRatioPerAA(*gene, grouping, mutation_proposed, selection_proposed, phiValue); } //likelihood_proposed = likelihood_proposed + calculateMutationPrior(grouping, true); //likelihood = likelihood + calculateMutationPrior(grouping, false); logAcceptanceRatioForAllMixtures[0] = (likelihood_proposed - likelihood); }
void GenomeUpdateTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); vector<Sequence::Info> seqVec(1); seqVec[0] = Sequence::Info("Sequence", 1000000, 5000, 700000); ancGenome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 10000005, 14000, 2000001); ancGenome->setDimensions(seqVec); }
int main() { Genome::set_mutations_at_cloning(Genome::max_age-Genome::max_age/4); Genome gene; Genome gene2=gene.clone(); cout<<gene; cout<<gene2; }
NeuralNetwork::NeuralNetwork(const Genome& genome, bool shouldMutate): parameters(genome.GetTrainingParameters()), genome(genome), inputNeurons(genome.GetTrainingParameters().numberOfInputs), outputNeurons(genome.GetTrainingParameters().numberOfOutputs) { if (shouldMutate) { MutateGenesAndBuildNetwork(); } else { BuildNetworkFromGenes(); } }
void Neatzsche_MPI::outputPopulation(Population * pop, unsigned int nodes, Coevolution * c, unsigned int i, bool lastgen) { unsigned int s = pop->getMembers()->size(); unsigned int n = (s-i)/nodes; bool uneven = (floor((s-i)/(double)n)!=(s-i)/(double)n); GeneSmall * gsv = NULL; NeuralNodeSmall * nsv = NULL; Genome * genome = NULL; int genes, nnodes; int sendtag = Neatzsche_MPI::MPI_Cont; string sftype; int sc=0; if(lastgen) sendtag = MPI_Stop; else sendtag = MPI_Cont; while(i < s) { if(uneven && (s-i)<(2*n)){ n = (s-i); } sc = (sc % (size-1))+1; MPI::COMM_WORLD.Send(&n,1,MPI_INT,sc,0);//send number of genomes incoming for(size_t i2 = 0; i2 < n && i < s; i2++, i++) { genome = pop->getMembers()->at(i)->getGenome(); genome->toSmall(nsv,gsv,&nnodes,&genes); MPI::COMM_WORLD.Send(&i,1,MPI_INT,sc,0);//send genome id.. MPI::COMM_WORLD.Send(&nnodes,1,MPI_INT,sc,0);//send number of nodes MPI::COMM_WORLD.Send(&genes,1,MPI_INT,sc,0);//send number of genes nodetype = Build_neuralnode_type(&nsv[0]); MPI::COMM_WORLD.Send(nsv,nnodes,nodetype,sc,0);//send node vector for(int i=0;i<nnodes;i++){ sftype = ""; sftype = genome->getNodes()->at(i)->getTFunc()->ftype; MPI::COMM_WORLD.Send(sftype.c_str(),sftype.length(),MPI::CHAR,sc,0);//send gene vector } genetype = Build_gene_type(&gsv[0]); MPI::COMM_WORLD.Send(gsv,genes,genetype,sc,0);//send gene vector if(nnodes>0) delete[] nsv; if(genes>0) delete[] gsv; } MPI::COMM_WORLD.Send(&sendtag,1,MPI::INT,sc,0);//send stop or not } }
void GenomeStringTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); hal_size_t seqLength = 28889943; Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); vector<Sequence::Info> seqVec(1); seqVec[0] = Sequence::Info("Sequence", seqLength, 5000, 700000); ancGenome->setDimensions(seqVec); _string = randomString(seqLength); ancGenome->setString(_string); }
void MappedSegmentMapDupeTest::createCallBack(AlignmentPtr alignment) { vector<Sequence::Info> seqVec(1); BottomSegmentIteratorPtr bi; BottomSegmentStruct bs; TopSegmentIteratorPtr ti; TopSegmentStruct ts; // setup simple case were there is an edge from a parent to // child and it is reversed Genome* parent = alignment->addRootGenome("parent"); Genome* child1 = alignment->addLeafGenome("child1", "parent", 1); Genome* child2 = alignment->addLeafGenome("child2", "parent", 1); seqVec[0] = Sequence::Info("Sequence", 3, 0, 1); parent->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 9, 3, 0); child1->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 9, 3, 0); child2->setDimensions(seqVec); parent->setString("CCC"); child1->setString("CCCTACGTG"); child2->setString("CCCTACGTG"); bi = parent->getBottomSegmentIterator(); bs.set(0, 3); bs._children.push_back(pair<hal_size_t, bool>(0, true)); bs._children.push_back(pair<hal_size_t, bool>(0, false)); bs.applyTo(bi); ti = child1->getTopSegmentIterator(); ts.set(0, 3, 0, true, NULL_INDEX, 1); ts.applyTo(ti); ti->toRight(); ts.set(3, 3, 0, true, NULL_INDEX, 2); ts.applyTo(ti); ti->toRight(); ts.set(6, 3, 0, true, NULL_INDEX, 0); ts.applyTo(ti); ti = child2->getTopSegmentIterator(); ts.set(0, 3, 0, false); ts.applyTo(ti); ti->toRight(); ts.set(3, 3, NULL_INDEX, true); ts.applyTo(ti); ti->toRight(); ts.set(6, 3, NULL_INDEX, false); ts.applyTo(ti); }
void SequenceCreateTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); size_t numSequences = 1000; vector<Sequence::Info> seqVec; for (size_t i = 0; i < numSequences; ++i) { hal_size_t len = 1 + i * 5 + i; seqVec.push_back(Sequence::Info("sequence" + std::to_string(i), len, i, i * 2)); } ancGenome->setDimensions(seqVec); }
void copyFromTopAlignment(AlignmentConstPtr topAlignment, AlignmentPtr mainAlignment, const string &genomeName) { Genome *mainReplacedGenome = mainAlignment->openGenome(genomeName); const Genome *topReplacedGenome = topAlignment->openGenome(genomeName); topReplacedGenome->copyTopDimensions(mainReplacedGenome); topReplacedGenome->copyTopSegments(mainReplacedGenome); mainReplacedGenome->fixParseInfo(); // Copy bot segments for the parent and top segments for the // siblings of the genome that's being replaced Genome *mainParent = mainReplacedGenome->getParent(); const Genome *topParent = topReplacedGenome->getParent(); topParent->copyBottomDimensions(mainParent); topParent->copyBottomSegments(mainParent); mainParent->fixParseInfo(); vector<string> siblings = mainAlignment->getChildNames(mainParent->getName()); for (size_t i = 0; i < siblings.size(); i++) { if (siblings[i] != genomeName) { Genome *mainChild = mainAlignment->openGenome(siblings[i]); const Genome *topChild = topAlignment->openGenome(siblings[i]); topChild->copyTopDimensions(mainChild); topChild->copyTopSegments(mainChild); mainChild->fixParseInfo(); } } }
std::vector<unsigned int> BlanketResolver::getIndices( Genome* blanket, Genome* target ) { std::vector<unsigned int> indices; unsigned int currentIndex = 0; for (unsigned int i = 0; i < blanket->genomeLength(); i++) { Genome* temp = blanket->getIndex<Genome*>(i); if (temp == target) indices.push_back(currentIndex); if (temp->isSameSpecies(target)) currentIndex++; } return indices; }
void FullRun::perform() { Run::perform(); // process common data verifyData(); setup(); loadPTable(pTableFile); Interface::instance() << Interface::SEPARATOR << endl; Interface::instance().showLog(true); progress(); Interface::instance() << Interface::SEPARATOR << endl; Interface::instance().showLog(true); if (!cloAllBpCalculated && !cloNoBpCalculated && !cloNo3sRecFile) { /* We calculate breakpoints for the best triplets */ for (unsigned long i = 0; i < childDataset->getSize(); i++) { Genome* child = childDataset->getGenome(i); Triplet* bestRecTriplet = child->getBestRecombinantTriplet(); if (bestRecTriplet != NULL) { recordRecombinantTriplet(bestRecTriplet); } } } if (isRandomMode && randomLoopNum > 1) { Interface::instance() << "Recombination sensitivity: " << recombinationSensitivity << "/" << randomLoopNum << "\n"; Interface::instance().showOutput(true); } else { displayResult(); Interface::instance() << Interface::SEPARATOR << endl; Interface::instance().showLog(true); savePValHistogram(); } /* Close all files */ if (fileSkippedTriplets) fileSkippedTriplets->close(); if (fileRecombinants) fileRecombinants->close(); if (fileLongRecombinants != NULL) fileLongRecombinants->close(); }
bool Neatzsche_MPI::readPopulation(Phenotypes * p, Coevolution * c, TransferFunctions * tfs) { MPI::Status status; MPI::Datatype ndt,gdt; int genomes,genes,nodes,id; MPI::COMM_WORLD.Recv(&genomes,1,MPI::INT,0,0);//Receive the number of genome NeuralNodeSmall * nns; GeneSmall * gs; Genome * genome = NULL; int stringc=0; char *strbuf; vector<string> * ftypes = NULL; for(int i=0;i<genomes;i++){ ftypes = new vector<string>(); MPI::COMM_WORLD.Recv(&id,1,MPI_INT,0,0); MPI::COMM_WORLD.Recv(&nodes,1,MPI_INT,0,0); MPI::COMM_WORLD.Recv(&genes,1,MPI_INT,0,0); // nns = (NeuralNodeSmall*)malloc(sizeof(NeuralNodeSmall)*nodes); // gs = (GeneSmall*)malloc(sizeof(GeneSmall)*genes); nns = new NeuralNodeSmall [nodes]; gs = new GeneSmall[genes]; nodetype = Build_neuralnode_type(&nns[0]); MPI::COMM_WORLD.Recv(nns,nodes,nodetype,0,0); for(int i=0;i<nodes;i++){//blargh, 1 int would be more usefull in this case:P MPI::COMM_WORLD.Probe(0, MPI_Cont, status); stringc = status.Get_count(MPI_CHAR); strbuf = (char*) malloc(sizeof(char)*stringc); MPI::COMM_WORLD.Recv(strbuf,stringc,MPI::CHAR,0,0);//receive the ftype of the node ftypes->push_back(string(strbuf).substr(0,stringc)); free(strbuf); } genetype = Build_gene_type(&gs[0]); MPI::COMM_WORLD.Recv(gs,genes,genetype,0,0); genome = new Genome(tfs); genome->fromSmall(id,nodes,nns,genes,gs,ftypes); delete ftypes; p->push_back(new Phenotype(genome)); if(nodes>0) delete[] nns; if(genes>0) delete[] gs; } unsigned int cont; MPI::COMM_WORLD.Recv(&cont,1,MPI::INT,0,0);//continue or stop? return cont == MPI_Cont; }
void FONSEModel::calculateLogLikelihoodRatioForHyperParameters(Genome &genome, unsigned iteration, std::vector <double> & logProbabilityRatio) { double lpr = 0.0; unsigned selectionCategory = getNumSynthesisRateCategories(); std::vector<double> currentStdDevSynthesisRate(selectionCategory, 0.0); std::vector<double> currentMphi(selectionCategory, 0.0); std::vector<double> proposedStdDevSynthesisRate(selectionCategory, 0.0); std::vector<double> proposedMphi(selectionCategory, 0.0); for (unsigned i = 0u; i < selectionCategory; i++) { currentStdDevSynthesisRate[i] = getStdDevSynthesisRate(i, false); currentMphi[i] = -((currentStdDevSynthesisRate[i] * currentStdDevSynthesisRate[i]) / 2); proposedStdDevSynthesisRate[i] = getStdDevSynthesisRate(i, true); proposedMphi[i] = -((proposedStdDevSynthesisRate[i] * proposedStdDevSynthesisRate[i]) / 2); // take the Jacobian into account for the non-linear transformation from logN to N distribution lpr -= (std::log(currentStdDevSynthesisRate[i]) - std::log(proposedStdDevSynthesisRate[i])); } logProbabilityRatio.resize(1); #ifdef _OPENMP //#ifndef __APPLE__ #pragma omp parallel for reduction(+:lpr) #endif for (unsigned i = 0u; i < genome.getGenomeSize(); i++) { unsigned mixture = getMixtureAssignment(i); mixture = getSynthesisRateCategory(mixture); double phi = getSynthesisRate(i, mixture, false); lpr += Parameter::densityLogNorm(phi, proposedMphi[mixture], proposedStdDevSynthesisRate[mixture], true) - Parameter::densityLogNorm(phi, currentMphi[mixture], currentStdDevSynthesisRate[mixture], true); } logProbabilityRatio[0] = lpr; }
// initializes a species with a leader genome and an ID number Species::Species(const Genome& a_Genome, int a_ID) { m_ID = a_ID; // copy the initializing genome locally. // it is now the representative of the species. m_Representative = a_Genome; m_BestGenome = a_Genome; // add the first and only one individual m_Individuals.push_back(a_Genome); m_Age = 0; m_GensNoImprovement = 0; m_OffspringRqd = 0; m_BestFitness = a_Genome.GetFitness(); m_BestSpecies = true; // Choose a random color RNG rng; rng.TimeSeed(); m_R = static_cast<int>(rng.RandFloat() * 255); m_G = static_cast<int>(rng.RandFloat() * 255); m_B = static_cast<int>(rng.RandFloat() * 255); }
void ReadContainer::addUpstreamRead ( const Genome& genome, const chr_num_t chr, const chr_pos_t pos ) { assume(pos <= 0, "3' ends need to be given as negative numbers!"); int ipos = pos - 1; // fix difference in one-based offsets auto upstr = genome.getReadAt(chr, ipos); // 3' ends are linked at negative indices if (upstr != nullptr) { // check if this is a multistrand splice junction if (genome.multistrand != nullptr && (upstr->chromosome != chromosome || (upstr->flags & MULTISTRAND) == MULTISTRAND)) { upstr->flags |= MULTISTRAND; flags |= MULTISTRAND; genome.multistrand->insert(shared_from_this()); genome.multistrand->insert(upstr); } int link = findLink(upstr, false); // search link upstr <= this int backLink = upstr->findLink(shared_from_this()); // search link upstr => this if (link == -1) { // upstr <= this unknown yet fivePrimeRead->push_back(upstr); } if (backLink >= 0) { // upstr => this known upstr->threePrimeRefs->at(backLink)++; } else { // upstr => this new upstr->threePrimeRead->push_back(shared_from_this()); upstr->threePrimeRefs->push_back(1); } } }
Ship(int vn, cpVect* vl, cpVect pos, Genome* ng = 0) { float mass = cpAreaForPoly(vn, vl, 0) * ship_density; float moi = cpMomentForPoly(mass, vn, vl, cpv(0, 0), 0); body = cpBodyNew(mass, moi); cpshape = cpPolyShapeNew(body, vn, vl, cpTransformIdentity, 0); cpShapeSetFriction(cpshape, 0.9); cpVect centroid = cpCentroidForPoly(vn, vl); shape.setPointCount(vn); for (int i = 0; i < vn; i++) { shape.setPoint(i, sf::Vector2f(vl[i].x, vl[i].y)); } cpBodySetCenterOfGravity(body, centroid); cpBodySetPosition(body, pos-centroid); cpBodySetVelocity(body, cpv(0, 0)); cpShapeSetCollisionType(cpshape, 1); cpShapeSetUserData(cpshape, this); last_fired = 0; nose_angle = PI/2; player = false; target = 0; score = 0; if (ng == 0) { Genome* braingenome = mutate(readgenome("shipmind.mind")); brain = braingenome->makenetwork(); delete braingenome; } else { brain = ng->makenetwork(); } score = 0; }