double[] derivative = new double[weightCount];
// Loop over every training element
for (final MLDataPair pair : this.training) {
EngineArray.fill(derivative, 0);
final MLData networkOutput = this.network.compute(pair.getInput());
e = pair.getIdeal().getData(outputNeuron) - networkOutput.getData(outputNeuron);
error.updateError(networkOutput.getData(outputNeuron), pair.getIdeal().getData(outputNeuron));
int currentWeight = 0;
// loop over the output weights
int outputFeedCount = network.getLayerTotalNeuronCount(network.getLayerCount()-2);
for(int i=0;i<this.network.getOutputCount();i++) {
for(int j=0;j<outputFeedCount;j++) {
double jc;
if (i == outputNeuron) {
jc = computeDerivative(pair.getInput(), outputNeuron,
currentWeight, this.dStep,
networkOutput.getData(outputNeuron), row);
} else {
jc = 0;
}
this.gradients[currentWeight] += jc *e;
derivative[currentWeight] = jc;
currentWeight++;
}
}
// Loop over every weight in the neural network
while( currentWeight<this.network.getFlat().getWeights().length) {
double jc = computeDerivative(
pair.getInput(), outputNeuron, currentWeight,
this.dStep,
networkOutput.getData(outputNeuron), row);
derivative[currentWeight] = jc;
this.gradients[currentWeight] += jc *e;
currentWeight++;
}