int layersCount = matrixMlp.getLayersCount();
for ( int layerIdx = layersCount -2 ; layerIdx > 0 ; layerIdx--) {
MatrixMlpLayer currentLayer = (MatrixMlpLayer)matrixLayers[layerIdx];
TransferFunction transferFunction = currentLayer.getTransferFunction();
int neuronsCount = currentLayer.getNeuronsCount();
double[] neuronErrors = currentLayer.getErrors();
double[] netInputs = currentLayer.getNetInput();
MatrixMlpLayer nextLayer = (MatrixMlpLayer)currentLayer.getNextLayer();
double[] nextLayerErrors = nextLayer.getErrors();
double[][] nextLayerWeights = nextLayer.getWeights();
// calculate error for each neuron in current layer
for(int neuronIdx = 0; neuronIdx < neuronsCount; neuronIdx++) {
// calculate weighted sum of errors of all neuron it is attached to - calculate how much this neuron is contributing to errors in next layer
double weightedErrorsSum = 0;
for(int nextLayerNeuronIdx = 0; nextLayerNeuronIdx < nextLayer.getNeuronsCount(); nextLayerNeuronIdx++) {
weightedErrorsSum += nextLayerErrors[nextLayerNeuronIdx] * nextLayerWeights[nextLayerNeuronIdx][neuronIdx];
}
// calculate the error for this neuron
neuronErrors[neuronIdx] = transferFunction.getDerivative(netInputs[neuronIdx]) * weightedErrorsSum;
} // neuron iterator
this.updateLayerWeights(currentLayer, neuronErrors);
} // layer iterator