AForge.Neuro.Learning.PerceptronLearning.Run C# (CSharp) Method

Run() public method

Runs learning iteration.

Runs one learning iteration and updates neuron's weights in the case if neuron's output is not equal to the desired output.

public Run ( double input, double output ) : double
input double Input vector.
output double Desired output vector.
return double
        public double Run( double[] input, double[] output )
        {
            // compute output of network
            double[] networkOutput = network.Compute( input );

            // get the only layer of the network
            Layer layer = network.Layers[0];

            // summary network absolute error
            double error = 0.0;

            // check output of each neuron and update weights
            for ( int j = 0; j < layer.Neurons.Length; j++ )
            {
                double e = output[j] - networkOutput[j];

                if ( e != 0 )
                {
                    ActivationNeuron perceptron = layer.Neurons[j] as ActivationNeuron;

                    // update weights
                    for ( int i = 0; i < perceptron.Weights.Length; i++ )
                    {
                        perceptron.Weights[i] += learningRate * e * input[i];
                    }

                    // update threshold value
                    perceptron.Threshold += learningRate * e;

                    // make error to be absolute
                    error += Math.Abs( e );
                }
            }

            return error;
        }