Esempio n. 1
0
 public Phenotype(Neat neat, NeatChromosome chromosome, InnovationCacher currentGeneration)
 {
     _layerMap  = new Dictionary <int, IList <NeatNeuron> >();
     _neat      = neat;
     Chromosome = chromosome;
     MutateAndBuild(currentGeneration);
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public void AssignHistory(NeatChromosome chromosome)
 {
     for (var i = 0; i < chromosome.GeneCount; i++)
     {
         AssignHistory(chromosome.GetGeneAt(i));
     }
 }
Esempio n. 4
0
        public Phenotype(Neat neat, NeatChromosome chromosome)
        {
            _layerMap  = new Dictionary <int, IList <NeatNeuron> >();
            _neat      = neat;
            Chromosome = chromosome;

            BuildFromGenes();
        }
Esempio n. 5
0
 public void CreateInitialOrganisms(IList <IBody> bodies)
 {
     _species.Clear();
     for (var i = 0; i < bodies.Count; i++)
     {
         var body          = bodies[i];
         var standardGenes = new NeatChromosome(_neat, body.InputCount, body.OutputCount);
         _innovationCacher.AssignHistory(standardGenes);
         var phenotype = new Phenotype(_neat, standardGenes);
         var organism  = new Organism(_neat, body, phenotype);
         FillOrganismIntoSpecies(organism);
     }
 }
Esempio n. 6
0
        public bool IsCompatible(NeatChromosome chromosome)
        {
            var distance = _representative.Chromosome.GetGeneticalDistanceFrom(chromosome);

            return(!IsAboveCompatibilityThreshold(distance));
        }