@Override protected void functionGradientHessian(DMatrixRMaj x, boolean sameStateAsCost, DMatrixRMaj gradient, HessianBFGS hessian) { functionGradient.process(x.data, gradient.data); if( !firstIteration ) { // compute the change in Gradient CommonOps_DDRM.subtract(gradient, gradientPrevious, y); CommonOps_DDRM.subtract(x, xPrevious, s); // Only update when the Wolfe condition is true of the Hessian gets corrected very quickly if( wolfeCondition(s,y,gradientPrevious)) { // Apply DFP equation and update H // Note: there is some duplication in math between Wolfe, update(), and inverseUpdate() hessian.update(s,y); gradientPrevious.set(gradient); xPrevious.set(x); f_prev = fx; } } else { firstIteration = false; gradientPrevious.set(gradient); xPrevious.set(x); f_prev = fx; } }
@Override protected void functionGradientHessian(DMatrixRMaj x, boolean sameStateAsCost, DMatrixRMaj gradient, HessianBFGS hessian) { functionGradient.process(x.data, gradient.data); if( !firstIteration ) { // compute the change in Gradient CommonOps_DDRM.subtract(gradient, gradientPrevious, y); CommonOps_DDRM.subtract(x, xPrevious, s); // Only update when the Wolfe condition is true of the Hessian gets corrected very quickly if( wolfeCondition(s,y,gradientPrevious)) { // Apply DFP equation and update H // Note: there is some duplication in math between Wolfe, update(), and inverseUpdate() hessian.update(s,y); gradientPrevious.set(gradient); xPrevious.set(x); f_prev = fx; } } else { firstIteration = false; gradientPrevious.set(gradient); xPrevious.set(x); f_prev = fx; } }