public static void calculateGradients(DoubleMatrix[] thetas, DoubleMatrix[] thetaGradients, DoubleMatrix[] ax, DoubleMatrix[] deltaX, final int m, NetworkConfiguration conf) { // calculate the gradients of the weights for (int i = 0; i < thetaGradients.length; i++) { DoubleMatrix gradDXA = multiply(deltaX[i + 1], ax[i], true, false, conf); if (m != 1) { thetaGradients[i] = gradDXA.divide(m); } else { thetaGradients[i] = gradDXA; } if (conf.lambda != 0d) { thetaGradients[i] = thetaGradients[i].add((thetas[i] .multiply(conf.lambda / m))); // subtract the regularized bias DoubleVector regBias = thetas[i] .slice(0, thetas[i].getRowCount(), 0, 1).multiply(conf.lambda / m) .getColumnVector(0); thetaGradients[i].setColumnVector(0, regBias); } } }