Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        private static void MutateSynapseAddRandom(Ann ann)
        {
            if (ann.hiddenNeurons.Count == 0)
            {
                return;
            }

            int[] layers    = ann.GetAllLayers();
            int   fromLayer = layers.Length != 0 ? layers[Util.rand.Next(layers.Length)] : 0;

            int[]  fromNeuronPositions = ann.GetNeuronsForLayer(fromLayer).Select(x => x.NeuronPosition).ToArray();
            int    fromNeuron          = fromNeuronPositions[Util.rand.Next(fromNeuronPositions.Length)];
            Neuron synapseNeuron       = ann.GetAllNeurons()[Util.rand.Next(ann.GetAllNeurons().Count)];

            if (!HelperDoesSynapseExist(ann, fromLayer, fromNeuron))
            {
                synapseNeuron.synapses.Add(new Synapse(fromLayer, fromNeuron));
            }
        }