Example #1
0
        public double GetGeneticalDistanceFrom(NeatChromosome other)
        {
            var totalWeightDifference = 0.0;
            var overlapingGenes       = 0;

            var smallerSize = System.Math.Min(GeneCount, other.GeneCount);

            for (var i = 0;
                 i < smallerSize && GetGeneAt(i)
                 .History == other.GetGeneAt(i)
                 .History;
                 ++i)
            {
                totalWeightDifference += System.Math.Abs(GetGeneAt(i)
                                                         .Weight - other.GetGeneAt(i)
                                                         .Weight);
                overlapingGenes++;
            }

            var disjointGenes = GeneCount + other.GeneCount - 2 * overlapingGenes;

            var disjointGenesInfluence  = (double)disjointGenes;
            var averageWeightDifference = totalWeightDifference / overlapingGenes;

            disjointGenesInfluence  *= _neat.Speciation.ImportanceOfDisjointGenes;
            averageWeightDifference *= _neat.Speciation.ImportanceOfAverageWeightDifference;

            return(disjointGenesInfluence + averageWeightDifference);
        }
Example #2
0
 public void AssignHistory(NeatChromosome chromosome)
 {
     for (var i = 0; i < chromosome.GeneCount; i++)
     {
         AssignHistory(chromosome.GetGeneAt(i));
     }
 }