/** * Iterate until the line search converges or the maximum number of iterations has been exceeded. * * The maximum number of steps is specified. A step is defined as the number of times the * optimization parameters are changed. * * @param search Search algorithm * @param maxSteps Maximum number of steps. * @return Value returned by {@link IterativeOptimization#iterate} */ public static boolean process( IterativeOptimization search , int maxSteps ) { for( int i = 0; i < maxSteps; i++ ) { boolean converged = step(search); if( converged ) { return search.isConverged(); } } return true; }
if( !UtilOptimize.process(optimizer,converge.maxIterations) ) return false;
UtilOptimize.process(optimizer,500);
UtilOptimize.process(optimizer,500);
/** * Iterate until the line search converges or the maximum number of iterations has been exceeded. * * The maximum number of steps is specified. A step is defined as the number of times the * optimization parameters are changed. * * @param search Search algorithm * @param maxSteps Maximum number of steps. * @return Value returned by {@link IterativeOptimization#iterate} */ public static boolean process( IterativeOptimization search , int maxSteps ) { for( int i = 0; i < maxSteps; i++ ) { boolean converged = step(search); if( converged ) { return search.isConverged(); } } return true; }
/** * Minimize the algebraic error using LM. The two epipoles are the parameters being optimized. */ private void minimizeWithGeometricConstraints() { extractEpipoles.process(solutionN, e2, e3); // encode the parameters being optimized param[0] = e2.x; param[1] = e2.y; param[2] = e2.z; param[3] = e3.x; param[4] = e3.y; param[5] = e3.z; // adjust the error function for the current inputs errorFunction.init(); // set up the optimization algorithm optimizer.setFunction(errorFunction,null); optimizer.initialize(param,gtol,ftol); // optimize until convergence or the maximum number of iterations UtilOptimize.process(optimizer, maxIterations); // get the results and compute the trifocal tensor double found[] = optimizer.getParameters(); paramToEpipoles(found,e2,e3); enforce.process(e2,e3,A); enforce.extractSolution(solutionN); }
public static void main(String[] args) { UnconstrainedMinimization optimizer = FactoryOptimization.quasiNewtonBfgs(null); // Send to standard out progress information optimizer.setVerbose(System.out,0); // Provide an analytical gradient to the Rosenbrock function. optimizer.setFunction(new Rosenbrock(),new Gradient(),0); // [-1.2, 1] is the recommended starting point for testing optimizer.initialize(new double[]{-1.2,1},1e-12,1e-12); // iterate 500 times or until it converges. // Manually iteration is possible too if more control over is required UtilOptimize.process(optimizer,500); double found[] = optimizer.getParameters(); // see how accurately it found the solution System.out.println("Final Error = "+optimizer.getFunctionValue()); // Compare the actual parameters to the found parameters System.out.printf("x[0]: expected=1.00 found=%5.2f\n",found[0]); System.out.printf("x[1]: expected=1.00 found=%5.2f\n",found[1]); }
/** * Minimize the algebraic error using LM. The two epipoles are the parameters being optimized. */ private void minimizeWithGeometricConstraints() { extractEpipoles.setTensor(solutionN); extractEpipoles.extractEpipoles(e2,e3); // encode the parameters being optimized param[0] = e2.x; param[1] = e2.y; param[2] = e2.z; param[3] = e3.x; param[4] = e3.y; param[5] = e3.z; // adjust the error function for the current inputs errorFunction.init(); // set up the optimization algorithm optimizer.setFunction(errorFunction,null); optimizer.initialize(param,gtol,ftol); // optimize until convergence or the maximum number of iterations UtilOptimize.process(optimizer, maxIterations); // get the results and compute the trifocal tensor double found[] = optimizer.getParameters(); paramToEpipoles(found,e2,e3); enforce.process(e2,e3,A); enforce.extractSolution(solutionN); }
/** * Give it a very simple function and see if it finds the minimum approximately. More * robustness and correctness tests are found in benchmark directory. */ @Test public void checkBasic() { double expected = 10; FunctionStoS f = new TrivialQuadraticStoS(expected); FunctionStoS d = new TrivialQuadraticDerivStoS(expected); // the initial value should pass all the tests with this setting LineSearch alg = new LineSearchMore94().setConvergence(0.0001,0.1,0.001); alg.setFunction(new Individual_to_CoupledDerivative(f,d),0); double valueZero = f.process(0); double derivZero = d.process(0); double initValue = f.process(1); alg.init(valueZero,derivZero,initValue,1,0,100); assertTrue(UtilOptimize.process(alg, 50)); double foundLoose = alg.getStep(); // now try it with tighter bounds alg = new LineSearchMore94().setConvergence(0.00001,0.000001,0.001); alg.setFunction(new Individual_to_CoupledDerivative(f,d),0); alg.init(valueZero,derivZero,initValue,1,0,100); assertTrue(UtilOptimize.process(alg, 50)); assertTrue(alg.isConverged()); double foundTight = alg.getStep(); // see if the tighter bounds is more accurate assertTrue(Math.abs(foundTight - expected) < Math.abs(foundLoose - expected)); // since it is a quadratic function it should find a perfect solution too assertEquals(expected, foundTight, 1e-5); }