private void linkMutate(Genome genome, boolean forceBias) { int neuron1Index = randomNeuronIndex(genome.genes, false); int neuron2Index = randomNeuronIndex(genome.genes, true); Gene newLink = new Gene(); // if the index of the neuron is less than num inputs then it must be an input-neuron.. i should // change this architecture if (neuron1Index <= getGameDataManager().getNumInputs() && neuron2Index <= getGameDataManager().getNumInputs()) { // --Both input nodes return; } if (neuron2Index <= getGameDataManager().getNumInputs()) { // -- Swap output and input -- probably should copy ! int temp = neuron1Index; neuron1Index = neuron2Index; neuron2Index = temp; } newLink.setInto(neuron1Index); newLink.setOut(neuron2Index); if (forceBias) { newLink.setInto(getGameDataManager().getNumInputs()); } if (containsLink(genome.genes, newLink)) { return; } newLink.innovation = newInnovation(); newLink.setWeight(rand.nextFloat() * 4 - 2); genome.genes.add(newLink); }
private void nodeMutate(Genome genome) { if (genome.genes.size() == 0) return; genome.maxneuron = genome.maxneuron + 1; int randomIndex = rand.nextInt(genome.genes.size()); Gene gene = genome.genes.get(randomIndex); if (!gene.isEnabled()) return; gene.setEnabled(false); Gene gene1 = gene.copy(); gene1.setOut(genome.maxneuron); gene1.setWeight(1.0f); gene1.innovation = newInnovation(); gene1.setEnabled(true); genome.genes.add(gene1); Gene gene2 = gene.copy(); gene2.setInto(genome.maxneuron); gene2.innovation = newInnovation(); gene2.setEnabled(true); genome.genes.add(gene2); }