Пример #1
0
        private void AddRandomNeuron(InnovationCacher currentGeneration)
        {
            var randGene = GetRandomEnabledGene();
            var index    = Chromosome.NeuronCount;

            var g1 = new NeatGene(_neat, randGene.From, index);

            g1.Weight    = 1.0;
            g1.Recursive = randGene.Recursive;
            currentGeneration.AssignHistory(g1);

            var g2 = new NeatGene(_neat, index, randGene.To);

            g2.Weight    = randGene.Weight;
            g2.Recursive = randGene.Recursive;
            currentGeneration.AssignHistory(g2);

            randGene.Enabled = false;

            Chromosome.AppendGene(g1);
            Chromosome.AppendGene(g2);
        }
Пример #2
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);
     }
 }
Пример #3
0
        private void AddRandomConnection(InnovationCacher currentGeneration)
        {
            var neuronPair = GetTwoUnconnectedNeurons();
            var fromNeuron = neuronPair[0];
            var toNeuron   = neuronPair[1];

            var newConnectionGene = new NeatGene(_neat, _neurons.IndexOf(fromNeuron), _neurons.IndexOf(toNeuron));

            if (fromNeuron.Layer > toNeuron.Layer)
            {
                if (!_neat.Structure.AllowRecurrentConnections)
                {
                    throw new Exception("Illegal recurrent connection");
                }

                newConnectionGene.Recursive = true;
            }

            currentGeneration.AssignHistory(newConnectionGene);

            var inConnection = new NeatNeuron.Connection();

            inConnection.Recursive = newConnectionGene.Recursive;
            inConnection.Neuron    = fromNeuron;
            inConnection.Weight    = newConnectionGene.Weight;
            toNeuron.Connections.Add(inConnection);

            var outConnection = new NeatNeuron.Connection();

            outConnection.Recursive = newConnectionGene.Recursive;
            outConnection.Neuron    = toNeuron;
            outConnection.Weight    = newConnectionGene.Weight;
            outConnection.OutGoing  = true;
            fromNeuron.Connections.Add(outConnection);

            Chromosome.AppendGene(newConnectionGene);
            CategorizeNeuronsIntoLayers();
        }