Exemplo n.º 1
0
        public double[] FeedForward(double[] input)
        {
            double[] output = new double[Weights[0].Length];
            for (int i = 0; i < Weights.Length; i++)
            {
                for (int k = 0; k < Weights[i].Length; k++)
                {
                    if (i == Weights.Length - 1)
                    {
                        output[k] += Weights[i][k];
                    }
                    else
                    {
                        output[k] += Weights[i][k] * input[i];
                    }
                }
            }

            for (int i = 0; i < output.Length; i++)
            {
                output[i] = NeuralMath.ReLU(output[i]);
            }

            return(output);
        }
Exemplo n.º 2
0
 public void Mutate(double probability, double amount)
 {
     for (int i = 0; i < Weights.Length; i++)
     {
         for (int k = 0; k < Weights[i].Length; k++)
         {
             if (NeuralMath.RandomDouble() < probability)
             {
                 Weights[i][k] = NeuralMath.RandomDouble() * (amount * 2) - amount;
             }
         }
     }
 }
Exemplo n.º 3
0
 public NeuralSection(UInt32 inputCount, UInt32 outputCount)
 {
     Weights = new double[inputCount + 1][];
     for (int i = 0; i < Weights.Length; i++)
     {
         Weights[i] = new double[outputCount];
     }
     for (int i = 0; i < Weights.Length; i++)
     {
         for (int k = 0; k < Weights[i].Length; k++)
         {
             Weights[i][k] = NeuralMath.RandomDouble() - 0.5f;
         }
     }
 }
Exemplo n.º 4
0
        public static NeuralNetwork Crossover(NeuralNetwork parent1, NeuralNetwork parent2, double uniformRate)
        {
            NeuralNetwork child = new NeuralNetwork(parent1);

            for (int i = 0; i < child.Sections.Length; i++)
            {
                double[][] weights = child.Sections[i].Weights;
                for (int k = 0; k < weights.Length; k++)
                {
                    for (int m = 0; m < weights[k].Length; m++)
                    {
                        if (NeuralMath.RandomDouble() > uniformRate)
                        {
                            weights[k][m] = parent2.Sections[i].Weights[k][m];
                        }
                    }
                }
            }
            return(child);
        }