/** * Sets scaling to the sqrt() of the diagonal elements in the Hessian matrix */ protected void computeHessianScaling() { hessian.extractDiagonals(hessianScaling); computeHessianScaling(hessianScaling); }
/** * Sets scaling to the sqrt() of the diagonal elements in the Hessian matrix */ protected void computeHessianScaling() { hessian.extractDiagonals(hessianScaling); computeHessianScaling(hessianScaling); }
/** * Computes derived * @return true if it has converged or false if it has not */ protected boolean updateDerivates() { functionGradientHessian(x,true, gradient, hessian); if( config.hessianScaling) { computeHessianScaling(); applyHessianScaling(); } hessian.extractDiagonals(diagOrig); if( checkConvergenceGTest(gradient) ) { if( verbose != null ) { verbose.println("Converged g-test"); } return true; } mode = Mode.DETERMINE_STEP; return false; }
/** * Computes derived * @return true if it has converged or false if it has not */ protected boolean updateDerivates() { functionGradientHessian(x,true, gradient, hessian); if( config.hessianScaling) { computeHessianScaling(); applyHessianScaling(); } hessian.extractDiagonals(diagOrig); if( checkConvergenceGTest(gradient) ) { if( verbose != null ) { verbose.println("Converged g-test"); } return true; } mode = Mode.DETERMINE_STEP; return false; }
@Test public void extractDiagonals() { DMatrixRMaj M = RandomMatrices_DDRM.rectangle(6,6,rand); setHessian(alg,M); DMatrixRMaj v = RandomMatrices_DDRM.rectangle(6,1,rand); alg.extractDiagonals(v); for (int i = 0; i < M.numRows; i++) { assertEquals(M.get(i,i),v.get(i,0), UtilEjml.TEST_F64); } }
@Test public void setDiagonals() { DMatrixRMaj M = RandomMatrices_DDRM.rectangle(6,6,rand); setHessian(alg,M); DMatrixRMaj v = RandomMatrices_DDRM.rectangle(6,1,rand); alg.setDiagonals(v); DMatrixRMaj found = RandomMatrices_DDRM.rectangle(6,1,rand); alg.extractDiagonals(found); for (int i = 0; i < M.numRows; i++) { assertEquals(found.get(i),v.get(i), UtilEjml.TEST_F64); } }
@Test public void updateHessian() { DMatrixRMaj J = RandomMatrices_DDRM.rectangle(30,6,rand); DMatrixRMaj H = new DMatrixRMaj(1,1); CommonOps_DDRM.multTransA(J,J,H); ((HessianLeastSquares)alg).updateHessian(convert(J)); DMatrixRMaj expected = new DMatrixRMaj(6,1); DMatrixRMaj found = expected.createLike(); alg.extractDiagonals(found); CommonOps_DDRM.extractDiag(H,expected); assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); } }
@Test public void divideRowsCols() { DMatrixRMaj M = RandomMatrices_DDRM.symmetricPosDef(10,rand); DMatrixRMaj scale = RandomMatrices_DDRM.rectangle(10,1,0,1,rand); DMatrixRMaj expected = M.copy(); CommonOps_DDRM.divideRows(scale.data,expected); CommonOps_DDRM.divideCols(expected,scale.data); setHessian(alg,M); alg.divideRowsCols(scale); // Not a great unit test since it doesn't check the off diagonal elements DMatrixRMaj found = RandomMatrices_DDRM.rectangle(10,1,rand); alg.extractDiagonals(found); for (int i = 0; i < M.numRows; i++) { assertEquals(expected.get(i,i),found.get(i), UtilEjml.TEST_F64); } }