Java Code Examples for org.apache.commons.math.random.JDKRandomGenerator#setSeed()
The following examples show how to use
org.apache.commons.math.random.JDKRandomGenerator#setSeed() .
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: MultiStartUnivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testQuinticMin() { // The quintic function has zeros at 0, +-0.5 and +-1. // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643, UnivariateRealFunction f = new QuinticFunction(); UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(4312000053L); MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer = new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g); UnivariateRealPointValuePair optimum = optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2); Assert.assertEquals(-0.2719561293, optimum.getPoint(), 1e-9); Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9); UnivariateRealPointValuePair[] optima = optimizer.getOptima(); for (int i = 0; i < optima.length; ++i) { Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1e-9); } Assert.assertTrue(optimizer.getEvaluations() >= 50); Assert.assertTrue(optimizer.getEvaluations() <= 100); }
Example 2
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected = OptimizationException.class) public void testNoOptimum() throws FunctionEvaluationException, OptimizationException { DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(12373523445l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); optimizer.optimize(new DifferentiableMultivariateVectorialFunction() { public MultivariateMatrixFunction jacobian() { return null; } public double[] value(double[] point) throws FunctionEvaluationException { throw new FunctionEvaluationException(point[0]); } }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 }); }
Example 3
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected = OptimizationException.class) public void testNoOptimum() throws FunctionEvaluationException, OptimizationException { DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(12373523445l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); optimizer.optimize(new DifferentiableMultivariateVectorialFunction() { public MultivariateMatrixFunction jacobian() { return null; } public double[] value(double[] point) throws FunctionEvaluationException { throw new FunctionEvaluationException(point[0]); } }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 }); }
Example 4
Source File: MultiStartMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testRosenbrock() throws FunctionEvaluationException, ConvergenceException { Rosenbrock rosenbrock = new Rosenbrock(); NelderMead underlying = new NelderMead(); underlying.setStartConfiguration(new double[][] { { -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 } }); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateRealOptimizer optimizer = new MultiStartMultivariateRealOptimizer(underlying, 10, generator); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3)); optimizer.setMaxIterations(100); RealPointValuePair optimum = optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 }); assertEquals(rosenbrock.getCount(), optimizer.getEvaluations()); assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 250); assertTrue(optimum.getValue() < 8.0e-4); }
Example 5
Source File: MultiStartUnivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSinMin() throws MathException { UnivariateRealFunction f = new SinFunction(); UnivariateRealOptimizer underlying = new BrentOptimizer(); underlying.setConvergenceChecker(new BrentOptimizer.BrentConvergenceChecker(1e-10, 1e-14)); underlying.setMaxEvaluations(300); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(44428400075l); MultiStartUnivariateRealOptimizer optimizer = new MultiStartUnivariateRealOptimizer(underlying, 10, g); optimizer.optimize(f, GoalType.MINIMIZE, -100.0, 100.0); UnivariateRealPointValuePair[] optima = optimizer.getOptima(); for (int i = 1; i < optima.length; ++i) { double d = (optima[i].getPoint() - optima[i-1].getPoint()) / (2 * FastMath.PI); assertTrue (FastMath.abs(d - FastMath.rint(d)) < 1.0e-8); assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10); assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10); } assertTrue(optimizer.getEvaluations() > 150); assertTrue(optimizer.getEvaluations() < 250); }
Example 6
Source File: MultiStartMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testRosenbrock() throws FunctionEvaluationException, ConvergenceException { Rosenbrock rosenbrock = new Rosenbrock(); NelderMead underlying = new NelderMead(); underlying.setStartConfiguration(new double[][] { { -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 } }); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateRealOptimizer optimizer = new MultiStartMultivariateRealOptimizer(underlying, 10, generator); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3)); optimizer.setMaxIterations(100); RealPointValuePair optimum = optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 }); assertEquals(rosenbrock.getCount(), optimizer.getEvaluations()); assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 250); assertTrue(optimum.getValue() < 8.0e-4); }
Example 7
Source File: MultiStartUnivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testQuinticMin() { // The quintic function has zeros at 0, +-0.5 and +-1. // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643, UnivariateRealFunction f = new QuinticFunction(); UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(4312000053L); MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer = new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g); UnivariateRealPointValuePair optimum = optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2); Assert.assertEquals(-0.2719561293, optimum.getPoint(), 1e-9); Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9); UnivariateRealPointValuePair[] optima = optimizer.getOptima(); for (int i = 0; i < optima.length; ++i) { Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1e-9); } Assert.assertTrue(optimizer.getEvaluations() >= 50); Assert.assertTrue(optimizer.getEvaluations() <= 100); }
Example 8
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected = MathUserException.class) public void testNoOptimum() { DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(12373523445l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); optimizer.optimize(100, new DifferentiableMultivariateVectorialFunction() { public MultivariateMatrixFunction jacobian() { return null; } public double[] value(double[] point) { throw new MathUserException(); } }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 }); }
Example 9
Source File: MultiStartUnivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSinMin() throws MathException { UnivariateRealFunction f = new SinFunction(); UnivariateRealOptimizer underlying = new BrentOptimizer(); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(44428400075l); MultiStartUnivariateRealOptimizer minimizer = new MultiStartUnivariateRealOptimizer(underlying, 10, g); minimizer.optimize(f, GoalType.MINIMIZE, -100.0, 100.0); double[] optima = minimizer.getOptima(); double[] optimaValues = minimizer.getOptimaValues(); for (int i = 1; i < optima.length; ++i) { double d = (optima[i] - optima[i-1]) / (2 * Math.PI); assertTrue (Math.abs(d - Math.rint(d)) < 1.0e-8); assertEquals(-1.0, f.value(optima[i]), 1.0e-10); assertEquals(f.value(optima[i]), optimaValues[i], 1.0e-10); } assertTrue(minimizer.getEvaluations() > 2900); assertTrue(minimizer.getEvaluations() < 3100); }
Example 10
Source File: MultiStartUnivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSinMin() throws MathException { UnivariateRealFunction f = new SinFunction(); UnivariateRealOptimizer underlying = new BrentOptimizer(); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(44428400075l); MultiStartUnivariateRealOptimizer minimizer = new MultiStartUnivariateRealOptimizer(underlying, 10, g); minimizer.optimize(f, GoalType.MINIMIZE, -100.0, 100.0); double[] optima = minimizer.getOptima(); double[] optimaValues = minimizer.getOptimaValues(); for (int i = 1; i < optima.length; ++i) { double d = (optima[i] - optima[i-1]) / (2 * Math.PI); assertTrue (Math.abs(d - Math.rint(d)) < 1.0e-8); assertEquals(-1.0, f.value(optima[i]), 1.0e-10); assertEquals(f.value(optima[i]), optimaValues[i], 1.0e-10); } assertTrue(minimizer.getEvaluations() > 2900); assertTrue(minimizer.getEvaluations() < 3100); }
Example 11
Source File: MultiStartDifferentiableMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCircleFitting() { Circle circle = new Circle(); 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 underlying = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(753289573253l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 }, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateRealOptimizer optimizer = new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10)); RealPointValuePair optimum = optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); Assert.assertEquals(200, optimizer.getMaxEvaluations()); RealPointValuePair[] optima = optimizer.getOptima(); for (RealPointValuePair o : optima) { Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.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); } Assert.assertTrue(optimizer.getEvaluations() > 70); Assert.assertTrue(optimizer.getEvaluations() < 90); Assert.assertEquals(3.1267527, optimum.getValue(), 1.0e-8); }
Example 12
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testTrivial() { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); Assert.fail("an exception should have been thrown"); } catch (MathIllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 }); Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); Assert.assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); Assert.assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { Assert.assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); Assert.assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } Assert.assertTrue(optimizer.getEvaluations() > 20); Assert.assertTrue(optimizer.getEvaluations() < 50); Assert.assertEquals(100, optimizer.getMaxEvaluations()); }
Example 13
Source File: MultiStartDifferentiableMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testCircleFitting() throws FunctionEvaluationException, OptimizationException { Circle circle = new Circle(); 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 underlying = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(753289573253l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 }, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateRealOptimizer optimizer = new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator); optimizer.setMaxIterations(100); assertEquals(100, optimizer.getMaxIterations()); optimizer.setMaxEvaluations(100); assertEquals(100, optimizer.getMaxEvaluations()); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10)); BrentSolver solver = new BrentSolver(); solver.setAbsoluteAccuracy(1.0e-13); solver.setRelativeAccuracy(1.0e-15); RealPointValuePair optimum = optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); RealPointValuePair[] optima = optimizer.getOptima(); for (RealPointValuePair o : optima) { Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]); assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); assertEquals(96.075902096, center.x, 1.0e-8); assertEquals(48.135167894, center.y, 1.0e-8); } assertTrue(optimizer.getGradientEvaluations() > 650); assertTrue(optimizer.getGradientEvaluations() < 700); assertTrue(optimizer.getEvaluations() > 70); assertTrue(optimizer.getEvaluations() < 90); assertTrue(optimizer.getIterations() > 70); assertTrue(optimizer.getIterations() < 90); assertEquals(3.1267527, optimum.getValue(), 1.0e-8); }
Example 14
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTrivial() throws FunctionEvaluationException, OptimizationException { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); fail("an exception should have been thrown"); } catch (IllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 50); assertTrue(optimizer.getIterations() > 20); assertTrue(optimizer.getIterations() < 50); assertTrue(optimizer.getJacobianEvaluations() > 20); assertTrue(optimizer.getJacobianEvaluations() < 50); assertEquals(100, optimizer.getMaxIterations()); }
Example 15
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTrivial() throws FunctionEvaluationException, OptimizationException { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); fail("an exception should have been thrown"); } catch (IllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 50); assertTrue(optimizer.getIterations() > 20); assertTrue(optimizer.getIterations() < 50); assertTrue(optimizer.getJacobianEvaluations() > 20); assertTrue(optimizer.getJacobianEvaluations() < 50); assertEquals(100, optimizer.getMaxIterations()); }
Example 16
Source File: MultiStartDifferentiableMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testCircleFitting() throws FunctionEvaluationException, OptimizationException { Circle circle = new Circle(); 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 underlying = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(753289573253l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 }, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateRealOptimizer optimizer = new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator); optimizer.setMaxIterations(100); assertEquals(100, optimizer.getMaxIterations()); optimizer.setMaxEvaluations(100); assertEquals(100, optimizer.getMaxEvaluations()); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10)); BrentSolver solver = new BrentSolver(); solver.setAbsoluteAccuracy(1.0e-13); solver.setRelativeAccuracy(1.0e-15); RealPointValuePair optimum = optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); RealPointValuePair[] optima = optimizer.getOptima(); for (RealPointValuePair o : optima) { Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]); assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); assertEquals(96.075902096, center.x, 1.0e-8); assertEquals(48.135167894, center.y, 1.0e-8); } assertTrue(optimizer.getGradientEvaluations() > 650); assertTrue(optimizer.getGradientEvaluations() < 700); assertTrue(optimizer.getEvaluations() > 70); assertTrue(optimizer.getEvaluations() < 90); assertTrue(optimizer.getIterations() > 70); assertTrue(optimizer.getIterations() < 90); assertEquals(3.1267527, optimum.getValue(), 1.0e-8); }
Example 17
Source File: MultiStartDifferentiableMultivariateRealOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testCircleFitting() throws FunctionEvaluationException, OptimizationException { Circle circle = new Circle(); 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 underlying = new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(753289573253l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 }, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateRealOptimizer optimizer = new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator); optimizer.setMaxIterations(100); assertEquals(100, optimizer.getMaxIterations()); optimizer.setMaxEvaluations(100); assertEquals(100, optimizer.getMaxEvaluations()); optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10)); BrentSolver solver = new BrentSolver(); solver.setAbsoluteAccuracy(1.0e-13); solver.setRelativeAccuracy(1.0e-15); RealPointValuePair optimum = optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 }); RealPointValuePair[] optima = optimizer.getOptima(); for (RealPointValuePair o : optima) { Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]); assertEquals(69.960161753, circle.getRadius(center), 1.0e-8); assertEquals(96.075902096, center.x, 1.0e-8); assertEquals(48.135167894, center.y, 1.0e-8); } assertTrue(optimizer.getGradientEvaluations() > 650); assertTrue(optimizer.getGradientEvaluations() < 700); assertTrue(optimizer.getEvaluations() > 70); assertTrue(optimizer.getEvaluations() < 90); assertTrue(optimizer.getIterations() > 70); assertTrue(optimizer.getIterations() < 90); assertEquals(3.1267527, optimum.getValue(), 1.0e-8); }
Example 18
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTrivial() throws FunctionEvaluationException, OptimizationException { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); fail("an exception should have been thrown"); } catch (IllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 50); assertTrue(optimizer.getIterations() > 20); assertTrue(optimizer.getIterations() < 50); assertTrue(optimizer.getJacobianEvaluations() > 20); assertTrue(optimizer.getJacobianEvaluations() < 50); assertEquals(100, optimizer.getMaxIterations()); }
Example 19
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTrivial() throws FunctionEvaluationException, OptimizationException { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); fail("an exception should have been thrown"); } catch (IllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 50); assertTrue(optimizer.getIterations() > 20); assertTrue(optimizer.getIterations() < 50); assertTrue(optimizer.getJacobianEvaluations() > 20); assertTrue(optimizer.getJacobianEvaluations() < 50); assertEquals(100, optimizer.getMaxIterations()); }
Example 20
Source File: MultiStartDifferentiableMultivariateVectorialOptimizerTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testTrivial() throws FunctionEvaluationException, OptimizationException { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); DifferentiableMultivariateVectorialOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartDifferentiableMultivariateVectorialOptimizer optimizer = new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer, 10, generator); optimizer.setMaxIterations(100); optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6)); // no optima before first optimization attempt try { optimizer.getOptima(); fail("an exception should have been thrown"); } catch (IllegalStateException ise) { // expected } VectorialPointValuePair optimum = optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(3.0, optimum.getValue()[0], 1.0e-10); VectorialPointValuePair[] optima = optimizer.getOptima(); assertEquals(10, optima.length); for (int i = 0; i < optima.length; ++i) { assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10); assertEquals(3.0, optima[i].getValue()[0], 1.0e-10); } assertTrue(optimizer.getEvaluations() > 20); assertTrue(optimizer.getEvaluations() < 50); assertTrue(optimizer.getIterations() > 20); assertTrue(optimizer.getIterations() < 50); assertTrue(optimizer.getJacobianEvaluations() > 20); assertTrue(optimizer.getJacobianEvaluations() < 50); assertEquals(100, optimizer.getMaxIterations()); }