Exemplo n.º 1
0
        public void Mutate(Genotype genotype, MutationResults results)
        {
            // We require a synapse to split
            if (genotype.SynapseCount == 0)
            {
                return;
            }

            // Pick a synapse at random
            var synapseIndex = Random.Range(0, genotype.SynapseCount);
            var synapseGene  = genotype.SynapseGenes.ElementAt(synapseIndex);

            // Generate an innovation id for the operation
            var innovationId = innovations.GetNeuronInnovationId(
                synapseGene.fromNeuronId,
                synapseGene.toNeuronId,
                synapseGene.InnovationId
                );

            // If the genotype already contains the innovation id, bail
            if (genotype.Contains(innovationId))
            {
                return;
            }

            var neuronGene = NeuronGene.Random(innovationId);

            var neuronGenes = new GeneList <NeuronGene>(genotype.NeuronGenes);

            neuronGenes.Add(neuronGene);
            genotype.NeuronGenes = neuronGenes;

            var synapseGenes = new GeneList <SynapseGene>(genotype.SynapseGenes);

            var synapseGene1 = new SynapseGene(innovationId + 0,
                                               synapseGene.fromNeuronId,
                                               neuronGene.InnovationId,
                                               true, 0.5f);

            synapseGenes.Add(synapseGene1);

            var synapseGene2 = new SynapseGene(innovationId + 1,
                                               neuronGene.InnovationId,
                                               synapseGene.toNeuronId,
                                               true, 0.5f);

            synapseGenes.Add(synapseGene2);

            genotype.SynapseGenes = synapseGenes;

            results.addedNeurons  += 1;
            results.addedSynapses += 2;
        }
Exemplo n.º 2
0
        public void Mutate(Genotype genotype, MutationResults results)
        {
            var innovationIds = genotype.NeuronGenes.InnovationIds;

            for (int i = 0; i < innovationIds.Count; i++)
            {
                if (Random.value < p)
                {
                    var innovationId = innovationIds[i];
                    genotype.NeuronGenes[innovationId] = NeuronGene.Random(innovationId);
                    results.replacedNeurons++;
                }
            }
        }
Exemplo n.º 3
0
 public static NeuronGene FromPrototype(NeuronGene other)
 {
     return(NeuronGene.Random(other.InnovationId));
 }