void mutationAddNeuron(float mutationChance, InnovationAssigner nIA, InnovationAssigner cIA) { IList <NeuronGene> ngs = new List <NeuronGene>(); IList <ConnectionGene> cgs = new List <ConnectionGene>(); foreach (var c in connectionGenes) { if (Random.Range(0f, 1f) <= mutationChance) { // New neuron NeuronGene ng = new NeuronGene(neuronGenes[c.Value.fromNeuronInnovation].layer + 1, (Neuron.Type)Random.Range(0, (int)Neuron.Type.amountOfTypes), nIA.getInnovation(), false, false); //Debug.Log("New neuron: " + ng.innovation + " layer " + ng.layer); // Create connection from new to old target neuron float weight = Random.Range(-1f, 1f); ConnectionGene cg = new ConnectionGene(cIA.getInnovation(), ng.innovation, c.Value.toNeuronInnovation, weight); //Debug.Log("New connection from " + cg.fromNeuronInnovation + " to " + cg.toNeuronInnovation); // Move connection to new neuron c.Value.setTarget(ng.innovation); ngs.Add(ng); cgs.Add(cg); } } foreach (var n in ngs) { neuronGenes.Add(n.innovation, n); } foreach (var c in cgs) { connectionGenes.Add(c.innovation, c); } }
public CPPN(Genome genome, InnovationAssigner nIA, InnovationAssigner cIA) { this.genome = genome; neuronIA = nIA; connectionIA = cIA; createFromGenome(); }
void mutationAddConnection(float mutationChance, InnovationAssigner cIA) { foreach (var n in neuronGenes) { if (!n.Value.isInput) { if (Random.Range(0f, 1f) <= mutationChance) { int[] candidates = getInputCandidates(n.Value.layer); int chosen = candidates[Random.Range(0, candidates.Length)]; float weight = Random.Range(-1f, 1f); ConnectionGene newConnection = new ConnectionGene(cIA.getInnovation(), chosen, n.Value.innovation, weight); connectionGenes.Add(newConnection.innovation, newConnection); //Debug.Log("New connection from " + newConnection.fromNeuronInnovation + " to " + newConnection.toNeuronInnovation); } } } }
public void mutate(InnovationAssigner nIA, InnovationAssigner cIA) { mutationModifyConnection(0.8f); mutationAddConnection(0.08f, cIA); mutationAddNeuron(0.05f, nIA, cIA); }
public CPPN(int numberOfInputs, int numberOfOutputs, InnovationAssigner nIA, InnovationAssigner cIA) { neuronIA = nIA; connectionIA = cIA; generateRandom(numberOfInputs, numberOfOutputs); }