Пример #1
0
        private static void MutateNeuronAddRandom(Ann ann)
        {
            int[] layers = ann.GetHiddenLayers();
            int   layer  = layers.Length != 0 ? layers[Util.rand.Next(layers.Length)] : 0;

            int[] neuronPositions = ann.GetNeuronsForLayer(layer).Select(x => x.NeuronPosition).ToArray();
            int   neuronId        = 0;
            bool  keepSearching   = true;

            while (keepSearching)
            {
                if (neuronPositions.Contains(neuronId))
                {
                    neuronId++;
                }
                else
                {
                    keepSearching = false;
                }
            }

            if (!HelperDoesNeuronExist(ann, layer, neuronId))
            {
                ann.hiddenNeurons.Add(new Neuron(layer, neuronId));
            }
        }
Пример #2
0
        private static void MutateNeuronLayerRandomExisting(Ann ann)
        {
            if (ann.hiddenNeurons.Count == 0)
            {
                return;
            }

            int[]  layers      = ann.GetHiddenLayers();
            int    randomLayer = layers[Util.rand.Next(layers.Length)];
            Neuron neuron      = ann.hiddenNeurons[Util.rand.Next(ann.hiddenNeurons.Count)];

            if (!HelperDoesNeuronExist(ann, randomLayer, neuron.NeuronPosition))
            {
                neuron.Layer = randomLayer;
            }
        }