org.apache.commons.math3.analysis.solvers.BrentSolver Java Examples
The following examples show how to use
org.apache.commons.math3.analysis.solvers.BrentSolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RobustBrentSolver.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected double doSolve() throws TooManyEvaluationsException, NoBracketingException { final double min = getMin(); final double max = getMax(); final double[] xSearchGrid = createHybridSearchGrid(min, max, numBisections, depth); final double[] fSearchGrid = Arrays.stream(xSearchGrid).map(this::computeObjectiveValue).toArray(); /* find bracketing intervals on the search grid */ final List<Bracket> bracketsList = detectBrackets(xSearchGrid, fSearchGrid); if (bracketsList.isEmpty()) { throw new NoBracketingException(min, max, fSearchGrid[0], fSearchGrid[fSearchGrid.length-1]); } final BrentSolver solver = new BrentSolver(getRelativeAccuracy(), getAbsoluteAccuracy(), getFunctionValueAccuracy()); final List<Double> roots = bracketsList.stream() .map(b -> solver.solve(getMaxEvaluations(), this::computeObjectiveValue, b.min, b.max, 0.5 * (b.min + b.max))) .collect(Collectors.toList()); if (roots.size() == 1 || meritFunc == null) { return roots.get(0); } final double[] merits = roots.stream().mapToDouble(meritFunc::value).toArray(); final int bestRootIndex = IntStream.range(0, roots.size()) .boxed() .max((i, j) -> (int) (merits[i] - merits[j])) .get(); return roots.get(bestRootIndex); }
Example #2
Source File: RobustBrentSolverUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test on a 4th degree polynomial with 4 real roots at x = 0, 1, 2, 3. This objective function is positive for * large enough positive and negative values of its arguments. Therefore, the simple Brent solver complains that * the search interval does not bracket a root. The robust Brent solver, however, subdivides the given search * interval and finds a bracketing sub-interval. * * The "best" root according to the given merit function (set to the anti-derivative of the objective function) * is in fact the one at x = 0. We require the robust solver to output x = 0, and the simple solver to fail. */ @Test public void simpleTest() { final UnivariateFunction objFunc = x -> 30 * x * (x - 1) * (x - 2) * (x - 3); final UnivariateFunction meritFunc = x -> 6 * FastMath.pow(x, 5) - 45 * FastMath.pow(x, 4) + 110 * FastMath.pow(x, 3) - 90 * FastMath.pow(x, 2); final RobustBrentSolver solverRobust = new RobustBrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC, meritFunc, 4, 1); final BrentSolver solverSimple = new BrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC); final double xRobust = solverRobust.solve(100, objFunc, -1, 4); Assert.assertEquals(xRobust, 0, DEF_ABS_ACC); boolean simpleSolverFails = false; try { /* this will fail */ solverSimple.solve(100, objFunc, -1, 4); } catch (final NoBracketingException ex) { simpleSolverFails = true; } Assert.assertTrue(simpleSolverFails); }
Example #3
Source File: RobustBrentSolver.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected double doSolve() throws TooManyEvaluationsException, NoBracketingException { final double min = getMin(); final double max = getMax(); final double[] xSearchGrid = createHybridSearchGrid(min, max, numBisections, depth); final double[] fSearchGrid = Arrays.stream(xSearchGrid).map(this::computeObjectiveValue).toArray(); /* find bracketing intervals on the search grid */ final List<Bracket> bracketsList = detectBrackets(xSearchGrid, fSearchGrid); if (bracketsList.isEmpty()) { throw new NoBracketingException(min, max, fSearchGrid[0], fSearchGrid[fSearchGrid.length-1]); } final BrentSolver solver = new BrentSolver(getRelativeAccuracy(), getAbsoluteAccuracy(), getFunctionValueAccuracy()); final List<Double> roots = bracketsList.stream() .map(b -> solver.solve(getMaxEvaluations(), this::computeObjectiveValue, b.min, b.max, 0.5 * (b.min + b.max))) .collect(Collectors.toList()); if (roots.size() == 1 || meritFunc == null) { return roots.get(0); } final double[] merits = roots.stream().mapToDouble(meritFunc::value).toArray(); final int bestRootIndex = IntStream.range(0, roots.size()) .boxed() .max((i, j) -> (int) (merits[i] - merits[j])) .get(); return roots.get(bestRootIndex); }
Example #4
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #5
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar problem = new CircleScalar(); problem.addPoint( 30.0, 68.0); problem.addPoint( 50.0, -6.0); problem.addPoint(110.0, -20.0); problem.addPoint( 35.0, 15.0); problem.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getObjectiveFunction(), problem.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 98.680, 47.345 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #6
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #7
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar problem = new CircleScalar(); problem.addPoint( 30.0, 68.0); problem.addPoint( 50.0, -6.0); problem.addPoint(110.0, -20.0); problem.addPoint( 35.0, 15.0); problem.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getObjectiveFunction(), problem.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 98.680, 47.345 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #8
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #9
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.x, 1.0e-8); Assert.assertEquals(48.135167894, center.y, 1.0e-8); }
Example #10
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar problem = new CircleScalar(); problem.addPoint( 30.0, 68.0); problem.addPoint( 50.0, -6.0); problem.addPoint(110.0, -20.0); problem.addPoint( 35.0, 15.0); problem.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getObjectiveFunction(), problem.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 98.680, 47.345 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #11
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #12
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.x, 1.0e-8); Assert.assertEquals(48.135167894, center.y, 1.0e-8); }
Example #13
Source File: InversePowerLawLearningCurve.java From AILibs with GNU Affero General Public License v3.0 | 6 votes |
@Override public double getConvergenceValue() { UnivariateSolver solver = new BrentSolver(0, 1.0d); double convergencePoint = -1; int upperIntervalBound = 10000; int retriesLeft = 8; while (retriesLeft > 0 && convergencePoint == -1) { try { convergencePoint = solver.solve(1000, x -> this.getDerivativeCurveValue(x) - 0.0000001, 1, upperIntervalBound); } catch (NoBracketingException e) { this.logger.warn(String.format("No solution could be found in interval [1,%d]", upperIntervalBound)); retriesLeft--; upperIntervalBound *= 2; } } if (convergencePoint == -1) { throw new IllegalStateException(String.format("No solution could be found in interval [1,%d]", upperIntervalBound)); } return this.getCurveValue(convergencePoint); }
Example #14
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #15
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-30, 1e-30), new BrentSolver(1e-15, 1e-13)); PointValuePair optimum = optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); Assert.assertEquals(96.075902096, center.getX(), 1.0e-8); Assert.assertEquals(48.135167894, center.getY(), 1.0e-8); }
Example #16
Source File: RobustBrentSolverUnitTest.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test on a 4th degree polynomial with 4 real roots at x = 0, 1, 2, 3. This objective function is positive for * large enough positive and negative values of its arguments. Therefore, the simple Brent solver complains that * the search interval does not bracket a root. The robust Brent solver, however, subdivides the given search * interval and finds a bracketing sub-interval. * * The "best" root according to the given merit function (set to the anti-derivative of the objective function) * is in fact the one at x = 0. We require the robust solver to output x = 0, and the simple solver to fail. */ @Test public void simpleTest() { final UnivariateFunction objFunc = x -> 30 * x * (x - 1) * (x - 2) * (x - 3); final UnivariateFunction meritFunc = x -> 6 * FastMath.pow(x, 5) - 45 * FastMath.pow(x, 4) + 110 * FastMath.pow(x, 3) - 90 * FastMath.pow(x, 2); final RobustBrentSolver solverRobust = new RobustBrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC, meritFunc, 4, 1); final BrentSolver solverSimple = new BrentSolver(DEF_REL_ACC, DEF_REL_ACC, DEF_F_ACC); final double xRobust = solverRobust.solve(100, objFunc, -1, 4); Assert.assertEquals(xRobust, 0, DEF_ABS_ACC); boolean simpleSolverFails = false; try { /* this will fail */ solverSimple.solve(100, objFunc, -1, 4); } catch (final NoBracketingException ex) { simpleSolverFails = true; } Assert.assertTrue(simpleSolverFails); }
Example #17
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #18
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #19
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #20
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #21
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #22
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #23
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #24
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(200, problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(200, problem2, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 }); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #25
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTwoSets() { final double epsilon = 1.0e-7; LinearProblem problem = new LinearProblem(new double[][] { { 2, 1, 0, 4, 0, 0 }, { -4, -2, 3, -7, 0, 0 }, { 4, 1, -2, 8, 0, 0 }, { 0, -3, -12, -1, 0, 0 }, { 0, 0, 0, 0, epsilon, 1 }, { 0, 0, 0, 0, 1, 1 } }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner = new Preconditioner() { public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; d[1] /= 30.0; d[2] /= 314.0; d[3] /= 260.0; d[4] /= 2 * (1 + epsilon * epsilon); d[5] /= 4.0; return d; } }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(), preconditioner); PointValuePair optimum = optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 }); Assert.assertEquals( 3.0, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals( 4.0, optimum.getPoint()[1], 1.0e-10); Assert.assertEquals(-1.0, optimum.getPoint()[2], 1.0e-10); Assert.assertEquals(-2.0, optimum.getPoint()[3], 1.0e-10); Assert.assertEquals( 1.0 + epsilon, optimum.getPoint()[4], 1.0e-10); Assert.assertEquals( 1.0 - epsilon, optimum.getPoint()[5], 1.0e-10); }
Example #26
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTwoSets() { final double epsilon = 1.0e-7; LinearProblem problem = new LinearProblem(new double[][] { { 2, 1, 0, 4, 0, 0 }, { -4, -2, 3, -7, 0, 0 }, { 4, 1, -2, 8, 0, 0 }, { 0, -3, -12, -1, 0, 0 }, { 0, 0, 0, 0, epsilon, 1 }, { 0, 0, 0, 0, 1, 1 } }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner = new Preconditioner() { public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; d[1] /= 30.0; d[2] /= 314.0; d[3] /= 260.0; d[4] /= 2 * (1 + epsilon * epsilon); d[5] /= 4.0; return d; } }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(), preconditioner); PointValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getObjectiveFunction(), problem.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 0, 0, 0, 0, 0, 0 })); Assert.assertEquals( 3.0, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals( 4.0, optimum.getPoint()[1], 1.0e-10); Assert.assertEquals(-1.0, optimum.getPoint()[2], 1.0e-10); Assert.assertEquals(-2.0, optimum.getPoint()[3], 1.0e-10); Assert.assertEquals( 1.0 + epsilon, optimum.getPoint()[4], 1.0e-10); Assert.assertEquals( 1.0 - epsilon, optimum.getPoint()[5], 1.0e-10); }
Example #27
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testIllConditioned() { LinearProblem problem1 = new LinearProblem(new double[][] { { 10.0, 7.0, 8.0, 7.0 }, { 7.0, 5.0, 6.0, 5.0 }, { 8.0, 6.0, 10.0, 9.0 }, { 7.0, 5.0, 9.0, 10.0 } }, new double[] { 32, 23, 33, 31 }); NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(1e-15, 1e-15)); PointValuePair optimum1 = optimizer.optimize(new MaxEval(200), problem1.getObjectiveFunction(), problem1.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 0, 1, 2, 3 })); Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4); Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4); LinearProblem problem2 = new LinearProblem(new double[][] { { 10.00, 7.00, 8.10, 7.20 }, { 7.08, 5.04, 6.00, 5.00 }, { 8.00, 5.98, 9.89, 9.00 }, { 6.99, 4.99, 9.00, 9.98 } }, new double[] { 32, 23, 33, 31 }); PointValuePair optimum2 = optimizer.optimize(new MaxEval(200), problem2.getObjectiveFunction(), problem2.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 0, 1, 2, 3 })); Assert.assertEquals(-81.0, optimum2.getPoint()[0], 1.0e-1); Assert.assertEquals(137.0, optimum2.getPoint()[1], 1.0e-1); Assert.assertEquals(-34.0, optimum2.getPoint()[2], 1.0e-1); Assert.assertEquals( 22.0, optimum2.getPoint()[3], 1.0e-1); }
Example #28
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTwoSets() { final double epsilon = 1.0e-7; LinearProblem problem = new LinearProblem(new double[][] { { 2, 1, 0, 4, 0, 0 }, { -4, -2, 3, -7, 0, 0 }, { 4, 1, -2, 8, 0, 0 }, { 0, -3, -12, -1, 0, 0 }, { 0, 0, 0, 0, epsilon, 1 }, { 0, 0, 0, 0, 1, 1 } }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner = new Preconditioner() { public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; d[1] /= 30.0; d[2] /= 314.0; d[3] /= 260.0; d[4] /= 2 * (1 + epsilon * epsilon); d[5] /= 4.0; return d; } }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(), preconditioner); PointValuePair optimum = optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 }); Assert.assertEquals( 3.0, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals( 4.0, optimum.getPoint()[1], 1.0e-10); Assert.assertEquals(-1.0, optimum.getPoint()[2], 1.0e-10); Assert.assertEquals(-2.0, optimum.getPoint()[3], 1.0e-10); Assert.assertEquals( 1.0 + epsilon, optimum.getPoint()[4], 1.0e-10); Assert.assertEquals( 1.0 - epsilon, optimum.getPoint()[5], 1.0e-10); }
Example #29
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTwoSets() { final double epsilon = 1.0e-7; LinearProblem problem = new LinearProblem(new double[][] { { 2, 1, 0, 4, 0, 0 }, { -4, -2, 3, -7, 0, 0 }, { 4, 1, -2, 8, 0, 0 }, { 0, -3, -12, -1, 0, 0 }, { 0, 0, 0, 0, epsilon, 1 }, { 0, 0, 0, 0, 1, 1 } }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner = new Preconditioner() { public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; d[1] /= 30.0; d[2] /= 314.0; d[3] /= 260.0; d[4] /= 2 * (1 + epsilon * epsilon); d[5] /= 4.0; return d; } }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(), preconditioner); PointValuePair optimum = optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 }); Assert.assertEquals( 3.0, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals( 4.0, optimum.getPoint()[1], 1.0e-10); Assert.assertEquals(-1.0, optimum.getPoint()[2], 1.0e-10); Assert.assertEquals(-2.0, optimum.getPoint()[3], 1.0e-10); Assert.assertEquals( 1.0 + epsilon, optimum.getPoint()[4], 1.0e-10); Assert.assertEquals( 1.0 - epsilon, optimum.getPoint()[5], 1.0e-10); }
Example #30
Source File: NonLinearConjugateGradientOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTwoSets() { final double epsilon = 1.0e-7; LinearProblem problem = new LinearProblem(new double[][] { { 2, 1, 0, 4, 0, 0 }, { -4, -2, 3, -7, 0, 0 }, { 4, 1, -2, 8, 0, 0 }, { 0, -3, -12, -1, 0, 0 }, { 0, 0, 0, 0, epsilon, 1 }, { 0, 0, 0, 0, 1, 1 } }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner = new Preconditioner() { public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; d[1] /= 30.0; d[2] /= 314.0; d[3] /= 260.0; d[4] /= 2 * (1 + epsilon * epsilon); d[5] /= 4.0; return d; } }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-13, 1e-13), new BrentSolver(), preconditioner); PointValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getObjectiveFunction(), problem.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 0, 0, 0, 0, 0, 0 })); Assert.assertEquals( 3.0, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals( 4.0, optimum.getPoint()[1], 1.0e-10); Assert.assertEquals(-1.0, optimum.getPoint()[2], 1.0e-10); Assert.assertEquals(-2.0, optimum.getPoint()[3], 1.0e-10); Assert.assertEquals( 1.0 + epsilon, optimum.getPoint()[4], 1.0e-10); Assert.assertEquals( 1.0 - epsilon, optimum.getPoint()[5], 1.0e-10); }