protected boolean solveGaussNewtonPoint(DMatrixRMaj pointGN ) { if( !owner.hessian.initializeSolver() ) { return false; } // using direction instead of gradient "should" have better scaling if( !owner.hessian.solve(direction, pointGN) ) { return false; } CommonOps_DDRM.scale(owner.gradientNorm,pointGN); return true; }
protected boolean solveGaussNewtonPoint(DMatrixRMaj pointGN ) { if( !owner.hessian.initializeSolver() ) { return false; } // using direction instead of gradient "should" have better scaling if( !owner.hessian.solve(direction, pointGN) ) { return false; } CommonOps_DDRM.scale(owner.gradientNorm,pointGN); return true; }
/** * Adjusts the Hessian's diagonal elements value and computes the next step * * @param lambda (Input) tuning * @param gradient (Input) gradient * @param step (Output) step * @return true if solver could compute the next step */ protected boolean computeStep( double lambda, DMatrixRMaj gradient , DMatrixRMaj step ) { final double mixture = config.mixture; for (int i = 0; i < diagOrig.numRows; i++) { double v = min(config.diagonal_max, max(config.diagonal_min,diagOrig.data[i])); diagStep.data[i] = v + lambda*(mixture + (1.0-mixture)*v); } hessian.setDiagonals( diagStep ); if( !hessian.initializeSolver()) { return false; } // In the book formulation it solves something like (B + lambda*I)*p = -g // but we don't want to modify g, so we apply the negative to the step instead if( hessian.solve(gradient,step) ) { CommonOps_DDRM.scale(-1, step); return true; } else { return false; } }
/** * Adjusts the Hessian's diagonal elements value and computes the next step * * @param lambda (Input) tuning * @param gradient (Input) gradient * @param step (Output) step * @return true if solver could compute the next step */ protected boolean computeStep( double lambda, DMatrixRMaj gradient , DMatrixRMaj step ) { final double mixture = config.mixture; for (int i = 0; i < diagOrig.numRows; i++) { double v = min(config.diagonal_max, max(config.diagonal_min,diagOrig.data[i])); diagStep.data[i] = v + lambda*(mixture + (1.0-mixture)*v); } hessian.setDiagonals( diagStep ); if( !hessian.initializeSolver()) { return false; } // In the book formulation it solves something like (B + lambda*I)*p = -g // but we don't want to modify g, so we apply the negative to the step instead if( hessian.solve(gradient,step) ) { CommonOps_DDRM.scale(-1, step); return true; } else { return false; } }
@Test public void solve() { DMatrixRMaj M = RandomMatrices_DDRM.symmetricPosDef(10,rand); DMatrixRMaj v = RandomMatrices_DDRM.rectangle(10,1,rand); DMatrixRMaj origv = v.copy(); DMatrixRMaj expected = v.createLike(); CommonOps_DDRM.solve(M,v,expected); DMatrixRMaj found = v.createLike(); alg.init(M.numCols); setHessian(alg,M); assertTrue(alg.initializeSolver()); assertTrue(alg.solve(v,found)); // make sure it didn't modify the input assertTrue(MatrixFeatures_DDRM.isIdentical(origv,origv,UtilEjml.TEST_F64)); // check the solution assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); // run it again, if nothing was modified it should produce the same solution assertTrue(alg.initializeSolver()); assertTrue(alg.solve(v,found)); assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); }