org.apache.commons.math3.optimization.PointValuePair Java Examples

The following examples show how to use org.apache.commons.math3.optimization.PointValuePair. 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: Arja_0055_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #2
Source File: Arja_00177_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #3
Source File: MultivariateFunctionPenaltyAdapterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testStartSimplexOutsideRange() {

    final BiQuadratic biQuadratic = new BiQuadratic(2.0, 2.5, 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(1e-10, 1e-30);
    optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));

    final PointValuePair optimum
        = optimizer.optimize(300, wrapped, GoalType.MINIMIZE, 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 vote down vote up
@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));
    optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));

    final PointValuePair optimum
        = optimizer.optimize(600, wrapped, GoalType.MINIMIZE, 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: JGenProg2017_0021_s.java    From coming with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           restrictToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }
    return tableau.getSolution();
}
 
Example #6
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLeastSquares1() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2.0, -3.0 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
 
Example #7
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testPowell() {
    MultivariateFunction powell =
        new MultivariateFunction() {
            public double value(double[] x) {
                ++count;
                double a = x[0] + 10 * x[1];
                double b = x[2] - x[3];
                double c = x[1] - 2 * x[2];
                double d = x[0] - x[3];
                return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d;
            }
        };

    count = 0;
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
    optimizer.setSimplex(new MultiDirectionalSimplex(4));
    PointValuePair optimum =
        optimizer.optimize(1000, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
    Assert.assertEquals(count, optimizer.getEvaluations());
    Assert.assertTrue(optimizer.getEvaluations() > 800);
    Assert.assertTrue(optimizer.getEvaluations() < 900);
    Assert.assertTrue(optimum.getValue() > 1e-2);
}
 
Example #8
Source File: BOBYQAOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param func Function to optimize.
 * @param startPoint Starting point.
 * @param boundaries Upper / lower point limit.
 * @param goal Minimization or maximization.
 * @param fTol Tolerance relative error on the objective function.
 * @param pointTol Tolerance for checking that the optimum is correct.
 * @param maxEvaluations Maximum number of evaluations.
 * @param expected Expected point / value.
 */
private void doTest(MultivariateFunction func,
                    double[] startPoint,
                    double[][] boundaries,
                    GoalType goal,
                    double fTol,
                    double pointTol,
                    int maxEvaluations,
                    PointValuePair expected) {
    doTest(func,
           startPoint,
           boundaries,
           goal,
           fTol,
           pointTol,
           maxEvaluations,
           0,
           expected,
           "");
}
 
Example #9
Source File: MultivariateFunctionPenaltyAdapterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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));
    optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));

    final PointValuePair optimum
        = optimizer.optimize(400, wrapped, GoalType.MINIMIZE, 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: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 #11
Source File: JGenProg2017_0020_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #12
Source File: Arja_00140_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #13
Source File: PowellOptimizer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This constructor allows to specify a user-defined convergence checker,
 * in addition to the parameters that control the default convergence
 * checking procedure and the line search tolerances.
 *
 * @param rel Relative threshold for this optimizer.
 * @param abs Absolute threshold for this optimizer.
 * @param lineRel Relative threshold for the internal line search optimizer.
 * @param lineAbs Absolute threshold for the internal line search optimizer.
 * @param checker Convergence checker.
 * @throws NotStrictlyPositiveException if {@code abs <= 0}.
 * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
 */
public PowellOptimizer(double rel,
                       double abs,
                       double lineRel,
                       double lineAbs,
                       ConvergenceChecker<PointValuePair> checker) {
    super(checker);

    if (rel < MIN_RELATIVE_TOLERANCE) {
        throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
    }
    if (abs <= 0) {
        throw new NotStrictlyPositiveException(abs);
    }
    relativeThreshold = rel;
    absoluteThreshold = abs;

    // Create the line search optimizer.
    line = new LineSearch(lineRel,
                          lineAbs);
}
 
Example #14
Source File: Arja_00166_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #15
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLeastSquares1() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2.0, -3.0 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
 
Example #16
Source File: JGenProg2017_0021_t.java    From coming with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           restrictToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }
    return tableau.getSolution();
}
 
Example #17
Source File: SimplexSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMath828Cycle() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(
            new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 0.0);
    
    ArrayList <LinearConstraint>constraints = new ArrayList<LinearConstraint>();

    constraints.add(new LinearConstraint(new double[] {0.0, 16.0, 14.0, 69.0, 1.0, 85.0, 52.0, 43.0, 64.0, 97.0, 14.0, 74.0, 89.0, 28.0, 94.0, 58.0, 13.0, 22.0, 21.0, 17.0, 30.0, 25.0, 1.0, 59.0, 91.0, 78.0, 12.0, 74.0, 56.0, 3.0, 88.0,}, Relationship.GEQ, 91.0));
    constraints.add(new LinearConstraint(new double[] {0.0, 60.0, 40.0, 81.0, 71.0, 72.0, 46.0, 45.0, 38.0, 48.0, 40.0, 17.0, 33.0, 85.0, 64.0, 32.0, 84.0, 3.0, 54.0, 44.0, 71.0, 67.0, 90.0, 95.0, 54.0, 99.0, 99.0, 29.0, 52.0, 98.0, 9.0,}, Relationship.GEQ, 54.0));
    constraints.add(new LinearConstraint(new double[] {0.0, 41.0, 12.0, 86.0, 90.0, 61.0, 31.0, 41.0, 23.0, 89.0, 17.0, 74.0, 44.0, 27.0, 16.0, 47.0, 80.0, 32.0, 11.0, 56.0, 68.0, 82.0, 11.0, 62.0, 62.0, 53.0, 39.0, 16.0, 48.0, 1.0, 63.0,}, Relationship.GEQ, 62.0));
    constraints.add(new LinearConstraint(new double[] {83.0, -76.0, -94.0, -19.0, -15.0, -70.0, -72.0, -57.0, -63.0, -65.0, -22.0, -94.0, -22.0, -88.0, -86.0, -89.0, -72.0, -16.0, -80.0, -49.0, -70.0, -93.0, -95.0, -17.0, -83.0, -97.0, -31.0, -47.0, -31.0, -13.0, -23.0,}, Relationship.GEQ, 0.0));
    constraints.add(new LinearConstraint(new double[] {41.0, -96.0, -41.0, -48.0, -70.0, -43.0, -43.0, -43.0, -97.0, -37.0, -85.0, -70.0, -45.0, -67.0, -87.0, -69.0, -94.0, -54.0, -54.0, -92.0, -79.0, -10.0, -35.0, -20.0, -41.0, -41.0, -65.0, -25.0, -12.0, -8.0, -46.0,}, Relationship.GEQ, 0.0));
    constraints.add(new LinearConstraint(new double[] {27.0, -42.0, -65.0, -49.0, -53.0, -42.0, -17.0, -2.0, -61.0, -31.0, -76.0, -47.0, -8.0, -93.0, -86.0, -62.0, -65.0, -63.0, -22.0, -43.0, -27.0, -23.0, -32.0, -74.0, -27.0, -63.0, -47.0, -78.0, -29.0, -95.0, -73.0,}, Relationship.GEQ, 0.0));
    constraints.add(new LinearConstraint(new double[] {15.0, -46.0, -41.0, -83.0, -98.0, -99.0, -21.0, -35.0, -7.0, -14.0, -80.0, -63.0, -18.0, -42.0, -5.0, -34.0, -56.0, -70.0, -16.0, -18.0, -74.0, -61.0, -47.0, -41.0, -15.0, -79.0, -18.0, -47.0, -88.0, -68.0, -55.0,}, Relationship.GEQ, 0.0));
    
    double epsilon = 1e-6;
    PointValuePair solution = new SimplexSolver().optimize(f, constraints, GoalType.MINIMIZE, true);
    Assert.assertEquals(1.0d, solution.getValue(), epsilon);
    Assert.assertTrue(validSolution(solution, constraints, epsilon));        
}
 
Example #18
Source File: BOBYQAOptimizer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
    final double[] lowerBound = getLowerBound();
    final double[] upperBound = getUpperBound();

    // Validity checks.
    setup(lowerBound, upperBound);

    isMinimize = (getGoalType() == GoalType.MINIMIZE);
    currentBest = new ArrayRealVector(getStartPoint());

    final double value = bobyqa(lowerBound, upperBound);

    return new PointValuePair(currentBest.getDataRef(),
                                  isMinimize ? value : -value);
}
 
Example #19
Source File: Cardumen_00258_s.java    From coming with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           restrictToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }
    return tableau.getSolution();
}
 
Example #20
Source File: MultivariateFunctionPenaltyAdapterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testUnbounded() {

    final BiQuadratic biQuadratic = new BiQuadratic(4.0, 0.0,
                                                    Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
                                                    Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    final MultivariateFunctionPenaltyAdapter wrapped =
            new MultivariateFunctionPenaltyAdapter(biQuadratic,
                                                       biQuadratic.getLower(),
                                                       biQuadratic.getUpper(),
                                                       1000.0, new double[] { 100.0, 100.0 });

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));

    final PointValuePair optimum
        = optimizer.optimize(300, wrapped, GoalType.MINIMIZE, 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 #21
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           restrictToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }
    return tableau.getSolution();
}
 
Example #22
Source File: SimplexSolverTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMath272() {
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 2, 2, 1 }, 0);
    Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
    constraints.add(new LinearConstraint(new double[] { 1, 1, 0 }, Relationship.GEQ,  1));
    constraints.add(new LinearConstraint(new double[] { 1, 0, 1 }, Relationship.GEQ,  1));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0 }, Relationship.GEQ,  1));

    SimplexSolver solver = new SimplexSolver();
    PointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);

    Assert.assertEquals(0.0, solution.getPoint()[0], .0000001);
    Assert.assertEquals(1.0, solution.getPoint()[1], .0000001);
    Assert.assertEquals(1.0, solution.getPoint()[2], .0000001);
    Assert.assertEquals(3.0, solution.getValue(), .0000001);
}
 
Example #23
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLeastSquares1() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2.0, -3.0 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
 
Example #24
Source File: jKali_0024_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #25
Source File: MultivariateFunctionPenaltyAdapterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testStartSimplexInsideRange() {

    final BiQuadratic biQuadratic = new BiQuadratic(2.0, 2.5, 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(1e-10, 1e-30);
    optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));

    final PointValuePair optimum
        = optimizer.optimize(300, wrapped, GoalType.MINIMIZE, new double[] { 1.5, 2.25 });

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7);

}
 
Example #26
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 #27
Source File: Cardumen_0037_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #28
Source File: jMutRepair_0025_s.java    From coming with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           restrictToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }
    return tableau.getSolution();
}
 
Example #29
Source File: Cardumen_00163_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * @param lambda Population size.
 * @param inputSigma Initial search volume; sigma of offspring objective variables.
 * @param maxIterations Maximal number of iterations.
 * @param stopFitness Whether to stop if objective function value is smaller than
 * {@code stopFitness}.
 * @param isActiveCMA Chooses the covariance matrix update method.
 * @param diagonalOnly Number of initial iterations, where the covariance matrix
 * remains diagonal.
 * @param checkFeasableCount Determines how often new random objective variables are
 * generated in case they are out of bounds.
 * @param random Random generator.
 * @param generateStatistics Whether statistic data is collected.
 * @param checker Convergence checker.
 */
public CMAESOptimizer(int lambda, double[] inputSigma,
                      int maxIterations, double stopFitness,
                      boolean isActiveCMA, int diagonalOnly, int checkFeasableCount,
                      RandomGenerator random, boolean generateStatistics,
                      ConvergenceChecker<PointValuePair> checker) {
    super(checker);
    this.lambda = lambda;
    this.inputSigma = inputSigma == null ? null : (double[]) inputSigma.clone();
    this.maxIterations = maxIterations;
    this.stopFitness = stopFitness;
    this.isActiveCMA = isActiveCMA;
    this.diagonalOnly = diagonalOnly;
    this.checkFeasableCount = checkFeasableCount;
    this.random = random;
    this.generateStatistics = generateStatistics;
}
 
Example #30
Source File: PowellOptimizer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This constructor allows to specify a user-defined convergence checker,
 * in addition to the parameters that control the default convergence
 * checking procedure and the line search tolerances.
 *
 * @param rel Relative threshold for this optimizer.
 * @param abs Absolute threshold for this optimizer.
 * @param lineRel Relative threshold for the internal line search optimizer.
 * @param lineAbs Absolute threshold for the internal line search optimizer.
 * @param checker Convergence checker.
 * @throws NotStrictlyPositiveException if {@code abs <= 0}.
 * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
 */
public PowellOptimizer(double rel,
                       double abs,
                       double lineRel,
                       double lineAbs,
                       ConvergenceChecker<PointValuePair> checker) {
    super(checker);

    if (rel < MIN_RELATIVE_TOLERANCE) {
        throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
    }
    if (abs <= 0) {
        throw new NotStrictlyPositiveException(abs);
    }
    relativeThreshold = rel;
    absoluteThreshold = abs;

    // Create the line search optimizer.
    line = new LineSearch(lineRel,
                          lineAbs);
}