/** * Propagates the errors back through the network. */ private void backpropagate() { for (int l = net.length; --l > 0;) { backpropagate(net[l], net[l - 1]); } }
/** * Update the neural network with given instance and associated target value. * Note that this method is NOT multi-thread safe. * @param x the training instance. * @param y the target value. * @param weight a positive weight value associated with the training instance. * @return the weighted training error before back-propagation. */ public double learn(double[] x, double[] y, double weight) { setInput(x); propagate(); double err = weight * computeOutputError(y); if (weight != 1.0) { for (int i = 0; i < outputLayer.units; i++) { outputLayer.error[i] *= weight; } } backpropagate(); adjustWeights(); return err; }