private static void MutateSynapseFromNeuron(Ann ann) { if (HelperCountSynapses(ann) == 0) { return; } Neuron synapseNeuron = ann.GetAllNeurons()[Util.rand.Next(ann.GetAllNeurons().Count)]; if (synapseNeuron.synapses.Count == 0) { return; } Synapse synapse = synapseNeuron.synapses[Util.rand.Next(synapseNeuron.synapses.Count)]; int fromLayer = synapse.FromLayer; Neuron[] neuronsInLayer = ann.GetNeuronsForLayer(fromLayer); Neuron neuron = neuronsInLayer.Length != 0 ? neuronsInLayer[Util.rand.Next(neuronsInLayer.Length)] : null; int newNeuronPosition = neuron != null ? neuron.NeuronPosition : 0; if (!HelperDoesSynapseExist(ann, synapse.FromLayer, newNeuronPosition)) { synapse.FromNeuron = newNeuronPosition; } }
private static void MutateSynapseWeightIncreaseRandom(Ann ann) { if (HelperCountSynapses(ann) == 0) { return; } Neuron synapseNeuron = ann.GetAllNeurons()[Util.rand.Next(ann.GetAllNeurons().Count)]; if (synapseNeuron.synapses.Count == 0) { return; } Synapse synapse = synapseNeuron.synapses[Util.rand.Next(synapseNeuron.synapses.Count)]; synapse.Weight += Util.rand.NextDouble(); }
private static void MutateSynapseFromLayer(Ann ann) { if (HelperCountSynapses(ann) == 0) { return; } Neuron synapseNeuron = ann.GetAllNeurons()[Util.rand.Next(ann.GetAllNeurons().Count)]; if (synapseNeuron.synapses.Count == 0) { return; } Synapse synapse = synapseNeuron.synapses[Util.rand.Next(synapseNeuron.synapses.Count)]; int layer = ann.GetAllLayers()[Util.rand.Next(ann.GetAllLayers().Length)]; if (!HelperDoesSynapseExist(ann, layer, synapse.FromNeuron)) { synapse.FromLayer = layer; } }