Exemple #1
0
        private static void MutateSynapseFromLayer(Ann ann)
        {
            if (ann.synapses.Count == 0)
            {
                return;
            }

            Synapse synapse = ann.synapses[Util.rand.Next(ann.synapses.Count)];
            int     layer   = ann.GetAllLayers()[Util.rand.Next(ann.GetAllLayers().Length)];

            if (synapse.ToLayer != layer && !HelperDoesSynapseExist(ann, layer, synapse.FromNeuron, synapse.ToLayer, synapse.ToNeuron))
            {
                synapse.FromLayer = layer;
            }
        }
Exemple #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)];
            int   toLayer             = layers.Length != 0 ? layers[Util.rand.Next(layers.Length)] : 0;

            int[] toNeuronPositions = ann.GetNeuronsForLayer(toLayer).Select(x => x.NeuronPosition).ToArray();
            int   toNeuron          = toNeuronPositions[Util.rand.Next(toNeuronPositions.Length)];

            if (toLayer != fromLayer && !HelperDoesSynapseExist(ann, fromLayer, fromNeuron, toLayer, toNeuron))
            {
                ann.synapses.Add(new Synapse(fromLayer, fromNeuron, toLayer, toNeuron));
            }
        }