Java Code Examples for org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer#optimize()

The following examples show how to use org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer#optimize() . 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: MultivariateFunctionMappingAdapterTest.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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 2e-7);
}
 
Example 2
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));
    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 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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             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 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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             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 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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             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 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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(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 7
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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             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 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));
    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 9
Source File: MultivariateFunctionMappingAdapterTest.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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 2e-7);
}
 
Example 10
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));
    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 11
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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             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 12
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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(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 13
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);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[] { 1.0, 0.5 });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(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 14
Source File: MultivariateFunctionMappingAdapterTest.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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 2e-7);
}
 
Example 15
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 2e-7);
}
 
Example 16
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-13, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 1e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 1e-7);
}
 
Example 17
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-13, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 1e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 1e-7);
}
 
Example 18
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 2e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 2e-7);
}
 
Example 19
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-13, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

    Assert.assertEquals(biQuadratic.getBoundedXOptimum(), bounded[0], 1e-7);
    Assert.assertEquals(biQuadratic.getBoundedYOptimum(), bounded[1], 1e-7);
}
 
Example 20
Source File: MultivariateFunctionMappingAdapterTest.java    From astor with GNU General Public License v2.0 5 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 MultivariateFunctionMappingAdapter wrapped
        = new MultivariateFunctionMappingAdapter(biQuadratic,
                                                 biQuadratic.getLower(),
                                                 biQuadratic.getUpper());

    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final AbstractSimplex simplex = new NelderMeadSimplex(new double[][] {
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.75 }),
            wrapped.boundedToUnbounded(new double[] { 1.5, 2.95 }),
            wrapped.boundedToUnbounded(new double[] { 1.7, 2.90 })
        });

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new ObjectiveFunction(wrapped),
                             simplex,
                             GoalType.MINIMIZE,
                             new InitialGuess(wrapped.boundedToUnbounded(new double[] { 1.5, 2.25 })));
    final double[] bounded = wrapped.unboundedToBounded(optimum.getPoint());

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