org.apache.commons.math3.optim.SimpleBounds Java Examples

The following examples show how to use org.apache.commons.math3.optim.SimpleBounds. 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: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    LinearProblem problem
        = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    NonLinearConjugateGradientOptimizer optimizer
        = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                  new SimpleValueChecker(1e-6, 1e-6),
                                                  1e-3, 1e-3, 1);
    optimizer.optimize(new MaxEval(100),
                       problem.getObjectiveFunction(),
                       problem.getObjectiveFunctionGradient(),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1 },
                                        new double[] { 1 }));
}
 
Example #2
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    LinearProblem problem
        = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    NonLinearConjugateGradientOptimizer optimizer
        = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                  new SimpleValueChecker(1e-6, 1e-6),
                                                  1e-3, 1e-3, 1);
    optimizer.optimize(new MaxEval(100),
                       problem.getObjectiveFunction(),
                       problem.getObjectiveFunctionGradient(),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1 },
                                        new double[] { 1 }));
}
 
Example #3
Source File: CMAESOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMath864() {
    final CMAESOptimizer optimizer
        = new CMAESOptimizer(30000, 0, true, 10,
                             0, new MersenneTwister(), false, null);
    final MultivariateFunction fitnessFunction = new MultivariateFunction() {
            public double value(double[] parameters) {
                final double target = 1;
                final double error = target - parameters[0];
                return error * error;
            }
        };

    final double[] start = { 0 };
    final double[] lower = { -1e6 };
    final double[] upper = { 1.5 };
    final double[] sigma = { 1e-1 };
    final double[] result = optimizer.optimize(new MaxEval(10000),
                                               new ObjectiveFunction(fitnessFunction),
                                               GoalType.MINIMIZE,
                                               new CMAESOptimizer.PopulationSize(5),
                                               new CMAESOptimizer.Sigma(sigma),
                                               new InitialGuess(start),
                                               new SimpleBounds(lower, upper)).getPoint();
    Assert.assertTrue("Out of bounds (" + result[0] + " > " + upper[0] + ")",
                      result[0] <= upper[0]);
}
 
Example #4
Source File: GaussNewtonOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #5
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #6
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    LinearProblem problem
        = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    NonLinearConjugateGradientOptimizer optimizer
        = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                  new SimpleValueChecker(1e-6, 1e-6));
    optimizer.optimize(new MaxEval(100),
                       problem.getObjectiveFunction(),
                       problem.getObjectiveFunctionGradient(),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1 },
                                        new double[] { 1 }));
}
 
Example #7
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #8
Source File: PowellOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    final MultivariateFunction func = new SumSincFunction(-1);
    final PowellOptimizer optim = new PowellOptimizer(1e-8, 1e-5,
                                                      1e-4, 1e-4);

    optim.optimize(new MaxEval(100),
                   new ObjectiveFunction(func),
                   GoalType.MINIMIZE,
                   new InitialGuess(new double[] { -3, 0 }),
                   new SimpleBounds(new double[] { -5, -1 },
                                    new double[] { 5, 1 }));
}
 
Example #9
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #10
Source File: MultiStartMultivariateVectorOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIssue914() {
    LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    JacobianMultivariateVectorOptimizer underlyingOptimizer =
            new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)) {
        @Override
        public PointVectorValuePair optimize(OptimizationData... optData) {
            // filter out simple bounds, as they are not supported
            // by the underlying optimizer, and we don't really care for this test
            OptimizationData[] filtered = optData.clone();
            for (int i = 0; i < filtered.length; ++i) {
                if (filtered[i] instanceof SimpleBounds) {
                    filtered[i] = null;
                }
            }
            return super.optimize(filtered);
        }
    };
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator =
            new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer =
            new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    optimizer.optimize(new MaxEval(100),
                       problem.getModelFunction(),
                       problem.getModelFunctionJacobian(),
                       problem.getTarget(),
                       new Weight(new double[] { 1 }),
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1.0e-10 }, new double[] {  1.0e-10 }));
    PointVectorValuePair[] optima = optimizer.getOptima();
    // only the first start should have succeeded
    Assert.assertEquals(1, optima.length);

}
 
Example #11
Source File: GaussNewtonOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #12
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #13
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    LinearProblem problem
        = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    NonLinearConjugateGradientOptimizer optimizer
        = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                  new SimpleValueChecker(1e-6, 1e-6));
    optimizer.optimize(new MaxEval(100),
                       problem.getObjectiveFunction(),
                       problem.getObjectiveFunctionGradient(),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1 },
                                        new double[] { 1 }));
}
 
Example #14
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #15
Source File: CMAESOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMath864() {
    final CMAESOptimizer optimizer
        = new CMAESOptimizer(30000, 0, true, 10,
                             0, new MersenneTwister(), false, null);
    final MultivariateFunction fitnessFunction = new MultivariateFunction() {
            public double value(double[] parameters) {
                final double target = 1;
                final double error = target - parameters[0];
                return error * error;
            }
        };

    final double[] start = { 0 };
    final double[] lower = { -1e6 };
    final double[] upper = { 1.5 };
    final double[] sigma = { 1e-1 };
    final double[] result = optimizer.optimize(new MaxEval(10000),
                                               new ObjectiveFunction(fitnessFunction),
                                               GoalType.MINIMIZE,
                                               new CMAESOptimizer.PopulationSize(5),
                                               new CMAESOptimizer.Sigma(sigma),
                                               new InitialGuess(start),
                                               new SimpleBounds(lower, upper)).getPoint();
    Assert.assertTrue("Out of bounds (" + result[0] + " > " + upper[0] + ")",
                      result[0] <= upper[0]);
}
 
Example #16
Source File: PowellOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    final MultivariateFunction func = new SumSincFunction(-1);
    final PowellOptimizer optim = new PowellOptimizer(1e-8, 1e-5,
                                                      1e-4, 1e-4);

    optim.optimize(new MaxEval(100),
                   new ObjectiveFunction(func),
                   GoalType.MINIMIZE,
                   new InitialGuess(new double[] { -3, 0 }),
                   new SimpleBounds(new double[] { -5, -1 },
                                    new double[] { 5, 1 }));
}
 
Example #17
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #18
Source File: MultiStartMultivariateVectorOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIssue914() {
    LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    JacobianMultivariateVectorOptimizer underlyingOptimizer =
            new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)) {
        @Override
        public PointVectorValuePair optimize(OptimizationData... optData) {
            // filter out simple bounds, as they are not supported
            // by the underlying optimizer, and we don't really care for this test
            OptimizationData[] filtered = optData.clone();
            for (int i = 0; i < filtered.length; ++i) {
                if (filtered[i] instanceof SimpleBounds) {
                    filtered[i] = null;
                }
            }
            return super.optimize(filtered);
        }
    };
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator =
            new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer =
            new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    optimizer.optimize(new MaxEval(100),
                       problem.getModelFunction(),
                       problem.getModelFunctionJacobian(),
                       problem.getTarget(),
                       new Weight(new double[] { 1 }),
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1.0e-10 }, new double[] {  1.0e-10 }));
    PointVectorValuePair[] optima = optimizer.getOptima();
    // only the first start should have succeeded
    Assert.assertEquals(1, optima.length);

}
 
Example #19
Source File: GaussNewtonOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #20
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #21
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #22
Source File: CMAESOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMath864() {
    final CMAESOptimizer optimizer
        = new CMAESOptimizer(30000, 0, true, 10,
                             0, new MersenneTwister(), false, null);
    final MultivariateFunction fitnessFunction = new MultivariateFunction() {
            public double value(double[] parameters) {
                final double target = 1;
                final double error = target - parameters[0];
                return error * error;
            }
        };

    final double[] start = { 0 };
    final double[] lower = { -1e6 };
    final double[] upper = { 1.5 };
    final double[] sigma = { 1e-1 };
    final double[] result = optimizer.optimize(new MaxEval(10000),
                                               new ObjectiveFunction(fitnessFunction),
                                               GoalType.MINIMIZE,
                                               new CMAESOptimizer.PopulationSize(5),
                                               new CMAESOptimizer.Sigma(sigma),
                                               new InitialGuess(start),
                                               new SimpleBounds(lower, upper)).getPoint();
    Assert.assertTrue("Out of bounds (" + result[0] + " > " + upper[0] + ")",
                      result[0] <= upper[0]);
}
 
Example #23
Source File: PowellOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    final MultivariateFunction func = new SumSincFunction(-1);
    final PowellOptimizer optim = new PowellOptimizer(1e-8, 1e-5,
                                                      1e-4, 1e-4);

    optim.optimize(new MaxEval(100),
                   new ObjectiveFunction(func),
                   GoalType.MINIMIZE,
                   new InitialGuess(new double[] { -3, 0 }),
                   new SimpleBounds(new double[] { -5, -1 },
                                    new double[] { 5, 1 }));
}
 
Example #24
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #25
Source File: SimplexOptimizerNelderMeadTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #26
Source File: MultiStartMultivariateVectorOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIssue914() {
    LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    JacobianMultivariateVectorOptimizer underlyingOptimizer =
            new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)) {
        @Override
        public PointVectorValuePair optimize(OptimizationData... optData) {
            // filter out simple bounds, as they are not supported
            // by the underlying optimizer, and we don't really care for this test
            OptimizationData[] filtered = optData.clone();
            for (int i = 0; i < filtered.length; ++i) {
                if (filtered[i] instanceof SimpleBounds) {
                    filtered[i] = null;
                }
            }
            return super.optimize(filtered);
        }
    };
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator =
            new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer =
            new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    optimizer.optimize(new MaxEval(100),
                       problem.getModelFunction(),
                       problem.getModelFunctionJacobian(),
                       problem.getTarget(),
                       new Weight(new double[] { 1 }),
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1.0e-10 }, new double[] {  1.0e-10 }));
    PointVectorValuePair[] optima = optimizer.getOptima();
    // only the first start should have succeeded
    Assert.assertEquals(1, optima.length);

}
 
Example #27
Source File: GaussNewtonOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #28
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testConstraintsUnsupported() {
    createOptimizer().optimize(new MaxEval(100),
                               new Target(new double[] { 2 }),
                               new Weight(new double[] { 1 }),
                               new InitialGuess(new double[] { 1, 2 }),
                               new SimpleBounds(new double[] { -10, 0 },
                                                new double[] { 20, 30 }));
}
 
Example #29
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=MathUnsupportedOperationException.class)
public void testBoundsUnsupported() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    optimizer.optimize(new MaxEval(100),
                       new ObjectiveFunction(fourExtrema),
                       GoalType.MINIMIZE,
                       new InitialGuess(new double[] { -3, 0 }),
                       new NelderMeadSimplex(new double[] { 0.2, 0.2 }),
                       new SimpleBounds(new double[] { -5, -1 },
                                        new double[] { 5, 1 }));
}
 
Example #30
Source File: CMAESOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMath864() {
    final CMAESOptimizer optimizer
        = new CMAESOptimizer(30000, 0, true, 10,
                             0, new MersenneTwister(), false, null);
    final MultivariateFunction fitnessFunction = new MultivariateFunction() {
            public double value(double[] parameters) {
                final double target = 1;
                final double error = target - parameters[0];
                return error * error;
            }
        };

    final double[] start = { 0 };
    final double[] lower = { -1e6 };
    final double[] upper = { 1.5 };
    final double[] sigma = { 1e-1 };
    final double[] result = optimizer.optimize(new MaxEval(10000),
                                               new ObjectiveFunction(fitnessFunction),
                                               GoalType.MINIMIZE,
                                               new CMAESOptimizer.PopulationSize(5),
                                               new CMAESOptimizer.Sigma(sigma),
                                               new InitialGuess(start),
                                               new SimpleBounds(lower, upper)).getPoint();
    Assert.assertTrue("Out of bounds (" + result[0] + " > " + upper[0] + ")",
                      result[0] <= upper[0]);
}