If you assume you want to minimize mean squared error, the computation of output node gradients can be performed with code like this: double[] oGrads = new double[numOutput]; ...