org.apache.commons.math3.optim.SimplePointChecker Java Examples
The following examples show how to use
org.apache.commons.math3.optim.SimplePointChecker.
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: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOptimumOutsideRange() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0, 1.0, 3.0, 2.0, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-11, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(600), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #2
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHalfBounded() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0, 1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(400), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #3
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOptimumOutsideRange() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0, 1.0, 3.0, 2.0, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-11, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(600), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #4
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHalfBounded() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0, 1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(400), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #5
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOptimumOutsideRange() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0, 1.0, 3.0, 2.0, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-11, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(600), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #6
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHalfBounded() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0, 1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(400), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #7
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOptimumOutsideRange() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0, 1.0, 3.0, 2.0, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-11, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(600), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #8
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHalfBounded() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0, 1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(400), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #9
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOptimumOutsideRange() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0, 1.0, 3.0, 2.0, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-11, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(600), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #10
Source File: MultivariateFunctionPenaltyAdapterTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testHalfBounded() { final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0, 1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 3.0); final MultivariateFunctionPenaltyAdapter wrapped = new MultivariateFunctionPenaltyAdapter(biQuadratic, biQuadratic.getLower(), biQuadratic.getUpper(), 1000.0, new double[] { 100.0, 100.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20)); final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 }); final PointValuePair optimum = optimizer.optimize(new MaxEval(400), new ObjectiveFunction(wrapped), simplex, GoalType.MINIMIZE, new InitialGuess(new double[] { -1.5, 4.0 })); Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7); Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7); }
Example #11
Source File: OptimizerFactoryCMAES.java From finmath-lib with Apache License 2.0 | 4 votes |
@Override public Optimizer getOptimizer(final ObjectiveFunction objectiveFunction, final double[] initialParameters, final double[] lowerBound,final double[] upperBound, final double[] parameterStep, final double[] targetValues) { final double[] values = new double[targetValues.length]; final double[] effectiveParameterLowerBound = parameterLowerBound != null ? parameterLowerBound : lowerBound; final double[] effectiveParameterUpperBound = parameterUppderBound != null ? parameterUppderBound : upperBound; final double[] effectiveParameterStandardDeviation = parameterStandardDeviation != null ? parameterStandardDeviation : parameterStep; // Throw exception if std dev is non null, but lower bound / upper bound are null. return new Optimizer() { private org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer optimizer; private org.apache.commons.math3.optim.PointValuePair result; @Override public double[] getBestFitParameters() { return result.getPoint(); } @Override public double getRootMeanSquaredError() { return result.getValue(); } @Override public int getIterations() { return optimizer != null ? optimizer.getIterations() : 0; } @Override public void run() { optimizer = new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer(maxIterations, accuracy, true, 0, 0, new MersenneTwister(3141), false, new SimplePointChecker<org.apache.commons.math3.optim.PointValuePair>(0, 0)) { @Override public double computeObjectiveValue(final double[] parameters) { try { objectiveFunction.setValues(parameters, values); } catch (final SolverException e) { return Double.NaN; } double rms = 0; for(final double value : values) { rms += value*value; } return Math.sqrt(rms); } @Override public org.apache.commons.math3.optim.nonlinear.scalar.GoalType getGoalType() { return org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE; } @Override public double[] getStartPoint() { return initialParameters; } @Override public double[] getLowerBound() { return effectiveParameterLowerBound; } @Override public double[] getUpperBound() { return effectiveParameterUpperBound; } }; try { result = optimizer.optimize( new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.PopulationSize((int) (4 + 3 * Math.log(initialParameters.length))), new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.Sigma(effectiveParameterStandardDeviation) ); } catch(final org.apache.commons.math3.exception.MathIllegalStateException e) { new SolverException(e); } } }; }
Example #12
Source File: OptimizerFactoryCMAES.java From finmath-lib with Apache License 2.0 | 4 votes |
@Override public Optimizer getOptimizer(final ObjectiveFunction objectiveFunction, final double[] initialParameters, final double[] lowerBound,final double[] upperBound, final double[] parameterStep, final double[] targetValues) { final double[] values = new double[targetValues.length]; final double[] effectiveParameterLowerBound = parameterLowerBound != null ? parameterLowerBound : lowerBound; final double[] effectiveParameterUpperBound = parameterUppderBound != null ? parameterUppderBound : upperBound; final double[] effectiveParameterStandardDeviation = parameterStandardDeviation != null ? parameterStandardDeviation : parameterStep; // Throw exception if std dev is non null, but lower bound / upper bound are null. return new Optimizer() { private org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer optimizer; private org.apache.commons.math3.optim.PointValuePair result; @Override public double[] getBestFitParameters() { return result.getPoint(); } @Override public double getRootMeanSquaredError() { return result.getValue(); } @Override public int getIterations() { return optimizer != null ? optimizer.getIterations() : 0; } @Override public void run() { optimizer = new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer(maxIterations, accuracy, true, 0, 0, new MersenneTwister(3141), false, new SimplePointChecker<org.apache.commons.math3.optim.PointValuePair>(0, 0)) { @Override public double computeObjectiveValue(final double[] parameters) { try { objectiveFunction.setValues(parameters, values); } catch (final SolverException e) { return Double.NaN; } double rms = 0; for(final double value : values) { rms += value*value; } return Math.sqrt(rms); } @Override public org.apache.commons.math3.optim.nonlinear.scalar.GoalType getGoalType() { return org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE; } @Override public double[] getStartPoint() { return initialParameters; } @Override public double[] getLowerBound() { return effectiveParameterLowerBound; } @Override public double[] getUpperBound() { return effectiveParameterUpperBound; } }; try { result = optimizer.optimize( new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.PopulationSize((int) (4 + 3 * Math.log(initialParameters.length))), new org.apache.commons.math3.optim.nonlinear.scalar.noderiv.CMAESOptimizer.Sigma(effectiveParameterStandardDeviation) ); } catch(final org.apache.commons.math3.exception.MathIllegalStateException e) { new SolverException(e); } } }; }