public double Run( double[] input )
{
double error = 0.0;
// compute the network
network.Compute( input );
int winner = network.GetWinner( );
// get layer of the network
Layer layer = network.Layers[0];
// check learning radius
if ( learningRadius == 0 )
{
Neuron neuron = layer.Neurons[winner];
// update weight of the winner only
for ( int i = 0; i < neuron.Weights.Length; i++ )
{
// calculate the error
double e = input[i] - neuron.Weights[i];
error += Math.Abs( e );
// update weights
neuron.Weights[i] += e * learningRate;
}
}
else
{
// winner's X and Y
int wx = winner % width;
int wy = winner / width;
// walk through all neurons of the layer
for ( int j = 0; j < layer.Neurons.Length; j++ )
{
Neuron neuron = layer.Neurons[j];
int dx = ( j % width ) - wx;
int dy = ( j / width ) - wy;
// update factor ( Gaussian based )
double factor = Math.Exp( -(double) ( dx * dx + dy * dy ) / squaredRadius2 );
// update weight of the neuron
for ( int i = 0; i < neuron.Weights.Length; i++ )
{
// calculate the error
double e = ( input[i] - neuron.Weights[i] ) * factor;
error += Math.Abs( e );
// update weight
neuron.Weights[i] += e * learningRate;
}
}
}
return error;
}