Example #1
0
 public static Genoma Mutate(Random r, Genoma gen,
                             float mutationRate, float maxPerturbation)
 {
     for (int layer = 0; layer < gen.W.Length; layer++)
     {
         float[,] m = gen.W[layer];
         FloatMatrix.MatrixLoop((i, j) =>
         {
             if ((float)r.NextDouble() < mutationRate)
             {
                 m[i, j] += ((float)r.NextDouble() * 2f - 1f) * maxPerturbation;
             }
         }, gen.W[layer].x, gen.W[layer].y);
         gen.W[layer] = m;
     }
     return(gen);
 }
Example #2
0
        public static Genoma Cross(Random r, Genoma parent1, Genoma parent2)
        {
            FloatMatrix[] SonW = new FloatMatrix[parent1.W.Length];

            for (int layer = 0; layer < parent1.W.Length; layer++)
            {
                float[,] w = new float[parent1.W[layer].x, parent1.W[layer].y];
                FloatMatrix.MatrixLoop((i, j) =>
                {
                    if ((float)r.NextDouble() > 0.5)
                    {
                        w[i, j] = parent1.W[layer].GetValue(i, j);
                    }
                    else
                    {
                        w[i, j] = parent2.W[layer].GetValue(i, j);
                    }
                }, parent1.W[layer].x, parent1.W[layer].y);
                SonW[layer] = w;
            }

            return(new Genoma(SonW));
        }
Example #3
0
 public Perceptron(Genoma genoma,
                   ActivationFunction activationFunction)
 {
     this.activationFunction = activationFunction;
     W = genoma.W;
 }