// get layer related information
DoubleFunction squashingFunction = this.squashingFunctionList
.get(curLayerIdx);
DoubleVector curLayerOutput = outputCache.get(curLayerIdx);
DoubleMatrix weightMatrix = this.weightMatrixList.get(curLayerIdx);
DoubleMatrix prevWeightMatrix = this.prevWeightUpdatesList.get(curLayerIdx);
// next layer is not output layer, remove the delta of bias neuron
if (curLayerIdx != this.layerSizeList.size() - 2) {
nextLayerDelta = nextLayerDelta.slice(1,
nextLayerDelta.getDimension() - 1);
}
DoubleVector delta = weightMatrix.transpose()
.multiplyVector(nextLayerDelta);
for (int i = 0; i < delta.getDimension(); ++i) {
delta.set(
i,
delta.get(i)
* squashingFunction.applyDerivative(curLayerOutput.get(i)));
}
// update weights
for (int i = 0; i < weightUpdateMatrix.getRowCount(); ++i) {
for (int j = 0; j < weightUpdateMatrix.getColumnCount(); ++j) {
weightUpdateMatrix.set(i, j,
-learningRate * nextLayerDelta.get(i) * curLayerOutput.get(j)
+ this.momentumWeight * prevWeightMatrix.get(i, j));
}
}
return delta;
}