private void UpdateNetwork( )
{
double[][] layerWeightsUpdates;
double[] layerThresholdUpdates;
double[] neuronWeightUpdates;
double[][] layerWeightsDerivatives;
double[] layerThresholdDerivatives;
double[] neuronWeightDerivatives;
double[][] layerPreviousWeightsDerivatives;
double[] layerPreviousThresholdDerivatives;
double[] neuronPreviousWeightDerivatives;
// for each layer of the network
for ( int i = 0; i < network.Layers.Length; i++ )
{
ActivationLayer layer = network.Layers[i] as ActivationLayer;
layerWeightsUpdates = weightsUpdates[i];
layerThresholdUpdates = thresholdsUpdates[i];
layerWeightsDerivatives = weightsDerivatives[i];
layerThresholdDerivatives = thresholdsDerivatives[i];
layerPreviousWeightsDerivatives = weightsPreviousDerivatives[i];
layerPreviousThresholdDerivatives = thresholdsPreviousDerivatives[i];
// for each neuron of the layer
for ( int j = 0; j < layer.Neurons.Length; j++ )
{
ActivationNeuron neuron = layer.Neurons[j] as ActivationNeuron;
neuronWeightUpdates = layerWeightsUpdates[j];
neuronWeightDerivatives = layerWeightsDerivatives[j];
neuronPreviousWeightDerivatives = layerPreviousWeightsDerivatives[j];
double S = 0;
// for each weight of the neuron
for ( int k = 0; k < neuron.InputsCount; k++ )
{
S = neuronPreviousWeightDerivatives[k] * neuronWeightDerivatives[k];
if ( S > 0 )
{
neuronWeightUpdates[k] = Math.Min( neuronWeightUpdates[k] * etaPlus, deltaMax );
neuron.Weights[k] -= Math.Sign( neuronWeightDerivatives[k] ) * neuronWeightUpdates[k];
neuronPreviousWeightDerivatives[k] = neuronWeightDerivatives[k];
}
else if ( S < 0 )
{
neuronWeightUpdates[k] = Math.Max( neuronWeightUpdates[k] * etaMinus, deltaMin );
neuronPreviousWeightDerivatives[k] = 0;
}
else
{
neuron.Weights[k] -= Math.Sign( neuronWeightDerivatives[k] ) * neuronWeightUpdates[k];
neuronPreviousWeightDerivatives[k] = neuronWeightDerivatives[k];
}
}
// update treshold
S = layerPreviousThresholdDerivatives[j] * layerThresholdDerivatives[j];
if ( S > 0 )
{
layerThresholdUpdates[j] = Math.Min( layerThresholdUpdates[j] * etaPlus, deltaMax );
neuron.Threshold -= Math.Sign( layerThresholdDerivatives[j] ) * layerThresholdUpdates[j];
layerPreviousThresholdDerivatives[j] = layerThresholdDerivatives[j];
}
else if ( S < 0 )
{
layerThresholdUpdates[j] = Math.Max( layerThresholdUpdates[j] * etaMinus, deltaMin );
layerThresholdDerivatives[j] = 0;
}
else
{
neuron.Threshold -= Math.Sign( layerThresholdDerivatives[j] ) * layerThresholdUpdates[j];
layerPreviousThresholdDerivatives[j] = layerThresholdDerivatives[j];
}
}
}
}