[mlpack-git] [mlpack/mlpack] NeuralEvolution - implemented gene, genome (#686)
Marcus Edel
notifications at github.com
Wed Jul 13 10:17:52 EDT 2016
> + }
> + }
> + }
> +
> + // Crossover two genome to get one genome.
> + void Crossover(Genome& genome1, Genome& genome2, Genome& childGenome) {
> + if (CompareGenome(genome1, genome2)) { // genome1 is better
> + CrossoverLinkAndNeuron(genome1, genome2, childGenome);
> + } else {
> + CrossoverLinkAndNeuron(genome2, genome1, childGenome);
> + }
> + }
> +
> + // Measure two genomes' disjoint (including exceed).
> + // NOTICE: we can separate into disjoint and exceed. But currently maybe it is enough.
> + double Disjoint(Genome& genome1, Genome& genome2) {
Let us distinguish between disjoint and excess here. At the same time, we can decrease the runtime, by not looping over the genomes twice:
```
size_t disjoint = 0;
size_t excess = 0;
if (genome1.NumLink() >= genome2.NumLink())
{
DisjointExcess(genome1, genome2, disjoint, excess);
}
else
{
DisjointExcess(genome2, genome1, disjoint, excess);
}
void DisjointExcess(Genome& genome1, Genome& genome2, size_t& disjoint, size_t& excess, size_t& matching)
{
size_t maxInovation = genome2.GetMaxInnovation();
for (size_t i = 0; i < genome1.NumLink(); ++i)
{
size_t innovationNumber = genome1.aLinkGenes[i].InnovationId();
if (!genome2.ContainLink(innovId))
{
if (innovationNumber > maxInovation)
{
excess += 1;
}
else
{
disjoint += 1;
}
}
else
{
matching += 1;
}
}
disjoint += genome2.NumLink() - matching;
}
```
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/686/files/ff45785b8669f82beb38ef5392f48bcdf5c83f6a#r70633242
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160713/f67b3275/attachment.html>
More information about the mlpack-git
mailing list