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];
// get activation function of the layer
IActivationFunction activationFunction = ( layer.Neurons[0] as ActivationNeuron ).ActivationFunction;
// summary network absolute error
double error = 0.0;
// update weights of each neuron
for ( int j = 0; j < layer.Neurons.Length; j++ )
{
// get neuron of the layer
ActivationNeuron neuron = layer.Neurons[j] as ActivationNeuron;
// calculate neuron's error
double e = output[j] - networkOutput[j];
// get activation function's derivative
double functionDerivative = activationFunction.Derivative2( networkOutput[j] );
// update weights
for ( int i = 0; i < neuron.Weights.Length; i++ )
{
neuron.Weights[i] += learningRate * e * functionDerivative * input[i];
}
// update threshold value
neuron.Threshold += learningRate * e * functionDerivative;
// sum error
error += ( e * e );
}
return error / 2;
}