public Phenotype(Neat neat, NeatChromosome chromosome, InnovationCacher currentGeneration) { _layerMap = new Dictionary <int, IList <NeatNeuron> >(); _neat = neat; Chromosome = chromosome; MutateAndBuild(currentGeneration); }
private void MutateAndBuild(InnovationCacher currentGeneration) { if (ShouldAddConnection()) { BuildFromGenes(); AddRandomConnection(currentGeneration); } else { if (ShouldAddNeuron()) { AddRandomNeuron(currentGeneration); } else { ShuffleWeights(); } BuildFromGenes(); } }
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); }
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(); }
public SpeciesManager(Neat neat) { _neat = neat; _innovationCacher = new InnovationCacher(); _species = new List <Species>(); }