<p>In <a href="https://github.com/mlpack/mlpack/pull/686#discussion_r70633242">src/mlpack/methods/ne/neat.hpp</a>:</p>
<pre style='color:#555'>> + }
> + }
> + }
> +
> + // 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) {
</pre>
<p>Let us distinguish between disjoint and excess here. At the same time, we can decrease the runtime, by not looping over the genomes twice:</p>
<pre><code>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;
}
</code></pre>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/686/files/ff45785b8669f82beb38ef5392f48bcdf5c83f6a#r70633242">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe/AJ4bFDsXkWt5AX_-YJSu51YGNw_FMPEuks5qVPOQgaJpZM4IwJa6">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFEgKbwz_JV3jM4dQttzqv4tMPmjVks5qVPOQgaJpZM4IwJa6.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/mlpack/mlpack/pull/686/files/ff45785b8669f82beb38ef5392f48bcdf5c83f6a#r70633242"></link>
<meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>