final double gradient = connection.getSource().getActivation()
* toNeuron.getTempTraining(0);
connection.addTempTraining(0, gradient);
// calculate the next layer delta
final FreeformNeuron fromNeuron = connection.getSource();
double sum = 0;
for (final FreeformConnection toConnection : fromNeuron
.getOutputs()) {
sum += toConnection.getTarget().getTempTraining(0)
* toConnection.getWeight();
}
final double neuronOutput = fromNeuron.getActivation();
final double neuronSum = fromNeuron.getSum();
double deriv = toNeuron.getInputSummation()
.getActivationFunction()
.derivativeFunction(neuronSum, neuronOutput);
if (this.fixFlatSopt
&& (toNeuron.getInputSummation()
.getActivationFunction() instanceof ActivationSigmoid)) {
deriv += FreeformPropagationTraining.FLAT_SPOT_CONST;
}
final double layerDelta = sum * deriv;
fromNeuron.setTempTraining(0, layerDelta);
}
// recurse to the next level
for (final FreeformConnection connection : toNeuron
.getInputSummation().list()) {
final FreeformNeuron fromNeuron = connection.getSource();
calculateNeuronGradient(fromNeuron);
}
}