Java Code Examples for org.apache.commons.math3.optim.PointValuePair#getValue()
The following examples show how to use
org.apache.commons.math3.optim.PointValuePair#getValue() .
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: MultiStartMultivariateOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return a comparator for sorting the optima. */ private Comparator<PointValuePair> getPairComparator() { return new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (optimizer.getGoalType() == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; }
Example 2
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14); final Gaussian2D function = new Gaussian2D(0, 0, 1); PointValuePair estimate = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(function), GoalType.MAXIMIZE, new InitialGuess(function.getMaximumPosition()), new MultiDirectionalSimplex(2)); final double EPSILON = 1e-5; final double expectedMaximum = function.getMaximum(); final double actualMaximum = estimate.getValue(); Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON); final double[] expectedPosition = function.getMaximumPosition(); final double[] actualPosition = estimate.getPoint(); Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON ); Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON ); }
Example 3
Source File: MultiStartMultivariateOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return a comparator for sorting the optima. */ private Comparator<PointValuePair> getPairComparator() { return new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (optimizer.getGoalType() == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; }
Example 4
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14); final Gaussian2D function = new Gaussian2D(0, 0, 1); PointValuePair estimate = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(function), GoalType.MAXIMIZE, new InitialGuess(function.getMaximumPosition()), new MultiDirectionalSimplex(2)); final double EPSILON = 1e-5; final double expectedMaximum = function.getMaximum(); final double actualMaximum = estimate.getValue(); Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON); final double[] expectedPosition = function.getMaximumPosition(); final double[] actualPosition = estimate.getPoint(); Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON ); Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON ); }
Example 5
Source File: MultiStartMultivariateOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return a comparator for sorting the optima. */ private Comparator<PointValuePair> getPairComparator() { return new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (optimizer.getGoalType() == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; }
Example 6
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14); final Gaussian2D function = new Gaussian2D(0, 0, 1); PointValuePair estimate = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(function), GoalType.MAXIMIZE, new InitialGuess(function.getMaximumPosition()), new MultiDirectionalSimplex(2)); final double EPSILON = 1e-5; final double expectedMaximum = function.getMaximum(); final double actualMaximum = estimate.getValue(); Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON); final double[] expectedPosition = function.getMaximumPosition(); final double[] actualPosition = estimate.getPoint(); Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON ); Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON ); }
Example 7
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14); final Gaussian2D function = new Gaussian2D(0, 0, 1); PointValuePair estimate = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(function), GoalType.MAXIMIZE, new InitialGuess(function.getMaximumPosition()), new MultiDirectionalSimplex(2)); final double EPSILON = 1e-5; final double expectedMaximum = function.getMaximum(); final double actualMaximum = estimate.getValue(); Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON); final double[] expectedPosition = function.getMaximumPosition(); final double[] actualPosition = estimate.getPoint(); Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON ); Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON ); }
Example 8
Source File: MultiStartMultivariateOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return a comparator for sorting the optima. */ private Comparator<PointValuePair> getPairComparator() { return new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (optimizer.getGoalType() == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; }
Example 9
Source File: SimplexOptimizerMultiDirectionalTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMath283() { // fails because MultiDirectional.iterateSimplex is looping forever // the while(true) should be replaced with a convergence check SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14); final Gaussian2D function = new Gaussian2D(0, 0, 1); PointValuePair estimate = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(function), GoalType.MAXIMIZE, new InitialGuess(function.getMaximumPosition()), new MultiDirectionalSimplex(2)); final double EPSILON = 1e-5; final double expectedMaximum = function.getMaximum(); final double actualMaximum = estimate.getValue(); Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON); final double[] expectedPosition = function.getMaximumPosition(); final double[] actualPosition = estimate.getPoint(); Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON ); Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON ); }
Example 10
Source File: MultiStartMultivariateOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return a comparator for sorting the optima. */ private Comparator<PointValuePair> getPairComparator() { return new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { if (o1 == null) { return (o2 == null) ? 0 : 1; } else if (o2 == null) { return -1; } final double v1 = o1.getValue(); final double v2 = o2.getValue(); return (optimizer.getGoalType() == GoalType.MINIMIZE) ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; }
Example 11
Source File: LPChecks.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
public static boolean canAddConstr(LinearConstraint newConstr, ArrayList<LinearConstraint> oldConstr){ //oldConstr define a non-empty polytope; can we add newConstr without making it empty? SimplexSolver ss = new SimplexSolver(); LinearObjectiveFunction of = constrAsFunction(newConstr); PointValuePair ans = ss.optimize(of, new LinearConstraintSet(oldConstr), GoalType.MINIMIZE); return ans.getValue()<-1e-8;//making sure there is numerically significant intersection }
Example 12
Source File: SimplexOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 13
Source File: Math_6_SimplexOptimizer_t.java From coming with MIT License | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 14
Source File: SimplexOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 15
Source File: SimplexOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 16
Source File: SimplexOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 17
Source File: SimplexOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (getIterations() > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); incrementIterationCount(); } }
Example 18
Source File: Math_6_SimplexOptimizer_s.java From coming with MIT License | 4 votes |
/** {@inheritDoc} */ @Override protected PointValuePair doOptimize() { checkParameters(); // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. final MultivariateFunction evalFunc = new MultivariateFunction() { public double value(double[] point) { return computeObjectiveValue(point); } }; final boolean isMinim = getGoalType() == GoalType.MINIMIZE; final Comparator<PointValuePair> comparator = new Comparator<PointValuePair>() { public int compare(final PointValuePair o1, final PointValuePair o2) { final double v1 = o1.getValue(); final double v2 = o2.getValue(); return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); } }; // Initialize search. simplex.build(getStartPoint()); simplex.evaluate(evalFunc, comparator); PointValuePair[] previous = null; int iteration = 0; final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker(); while (true) { if (iteration > 0) { boolean converged = true; for (int i = 0; i < simplex.getSize(); i++) { PointValuePair prev = previous[i]; converged = converged && checker.converged(iteration, prev, simplex.getPoint(i)); } if (converged) { // We have found an optimum. return simplex.getPoint(0); } } // We still need to search. previous = simplex.getPoints(); simplex.iterate(evalFunc, comparator); ++iteration; } }