Accord.Neuro.Learning.ParallelResilientBackpropagationLearning.UpdateNetwork C# (CSharp) Method

UpdateNetwork() private method

Update network weights.
private UpdateNetwork ( bool errIncrease = false ) : void
errIncrease bool
return void
        private void UpdateNetwork(bool errIncrease = false)
        {
            // For each layer of the network
            for (int i = 0; i < weightsUpdates.Length; i++)
            {
                ActivationLayer layer = this.network.Layers[i] as ActivationLayer;
                double[][] layerWeightsUpdates = weightsUpdates[i];
                double[] layerThresholdUpdates = thresholdsUpdates[i];

                double[][] layerWeightsDerivatives = weightsDerivatives[i];
                double[] layerThresholdDerivatives = thresholdsDerivatives[i];

                double[][] layerPreviousWeightsDerivatives = weightsPreviousDerivatives[i];
                double[] layerPreviousThresholdDerivatives = thresholdsPreviousDerivatives[i];

                // For each neuron in the current layer
                for (int j = 0; j < layerWeightsUpdates.Length; j++)
                {
                    ActivationNeuron neuron = layer.Neurons[j] as ActivationNeuron;

                    double[] neuronWeightUpdates = layerWeightsUpdates[j];
                    double[] neuronWeightDerivatives = layerWeightsDerivatives[j];
                    double[] neuronPreviousWeightDerivatives = layerPreviousWeightsDerivatives[j];

                    double S;

                    // For each weight in the current neuron
                    for (int k = 0; k < neuronPreviousWeightDerivatives.Length; k++)
                    {
                        S = neuronPreviousWeightDerivatives[k] * neuronWeightDerivatives[k];

                        if (S > 0.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.0)
                        {
                            var delta = Math.Max(neuronWeightUpdates[k] * etaMinus, deltaMin);
                            if (errIncrease)
                                neuron.Weights[k] -= neuronWeightUpdates[k]; // revert previous update
                            neuronWeightUpdates[k] = delta;
                            neuronPreviousWeightDerivatives[k] = 0.0;
                        }
                        else
                        {
                            neuron.Weights[k] -= Math.Sign(neuronWeightDerivatives[k]) * neuronWeightUpdates[k];
                            neuronPreviousWeightDerivatives[k] = neuronWeightDerivatives[k];
                        }
                    }

                    S = layerPreviousThresholdDerivatives[j] * layerThresholdDerivatives[j];

                    if (S > 0.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.0)
                    {
                        var delta = Math.Max(layerThresholdUpdates[j] * etaMinus, deltaMin);
                        if (errIncrease)
                            neuron.Threshold -= layerThresholdUpdates[j]; // revert previous update
                        layerThresholdUpdates[j] = delta;
                        layerPreviousThresholdDerivatives[j] = 0.0;
                    }
                    else
                    {
                        neuron.Threshold -= Math.Sign(layerThresholdDerivatives[j]) * layerThresholdUpdates[j];
                        layerPreviousThresholdDerivatives[j] = layerThresholdDerivatives[j];
                    }
                }
            }
        }