}
private void updateWeights() {
double previousNeuronValue, previousAdjustment, weightAdjustment, newWeight;
IWeight oldWeight;
IWeights weights = network.getWeights();
for (int layerIndex = network.getLayersCount() - 1; layerIndex > 0; layerIndex--) {
int currentNeuronsCount = network.getLayer(layerIndex).getNeuronsCount();
int previousNeuronsCount = network.getLayer(layerIndex - 1).getNeuronsCount() + 1;
for (int neuronIndex = 0; neuronIndex < currentNeuronsCount; neuronIndex++) {
double neuronDelta = weightErrors.get(layerIndex, neuronIndex);
for (int previousNeuronIndex = 0; previousNeuronIndex < previousNeuronsCount; previousNeuronIndex++) {
// weight adjustment
previousNeuronValue = previousNeuronIndex == 0 ? // bias
1 : networkValues.getNeuronValue(layerIndex - 1, previousNeuronIndex - 1);
previousAdjustment = previousAdjustments.get(layerIndex, neuronIndex, previousNeuronIndex);
weightAdjustment = learningRate * neuronDelta * previousNeuronValue + momentum * previousAdjustment;
// weights
oldWeight = weights.getConnectionWeight(layerIndex, neuronIndex, previousNeuronIndex);
newWeight = oldWeight.getWeight() + weightAdjustment;
// update helper structure and weights in network
previousAdjustments.set(layerIndex, neuronIndex, previousNeuronIndex, weightAdjustment);
weights.setConnectionWeight(layerIndex, neuronIndex, previousNeuronIndex, newWeight);
}
}
}
}