Пример #1
0
        private static void MutateChangeNeuronsFunctions(Neuron[] neurons)
        {
            int neuronsSize = neurons.Length;
            int itersCount  = random.Next(neuronsSize);

            if (itersCount == 0)
            {
                itersCount = 1;
            }

            var used = new HashSet <int>();

            for (int iter = 0; iter < itersCount; iter++)
            {
                int i = random.Next(neuronsSize);
                if (neuronsSize > 1)
                {
                    while (used.Contains(i))
                    {
                        i = random.Next(neuronsSize);
                    }
                }

                var n = neurons[i];
                var f = ThresholdFunction.Random();
                n.SetFunctionAndParams(f, ThresholdFunction.GetDefaultParams(f));
                used.Add(i);
            }
        }
Пример #2
0
 public NeuralNetwork(int numberOfNeurons)
 {
     Neurons = new Neuron[numberOfNeurons];
     for (int i = 0; i < numberOfNeurons; i++)
     {
         Neurons[i] = new Neuron(ThresholdFunction.Function.Sign, ThresholdFunction.GetDefaultParams(ThresholdFunction.Function.Sign));
     }
 }