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

The following examples show how to use org.apache.commons.math3.optimization.SimpleValueChecker. 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
public void testOneSet() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1,  0, 0 },
            { -1,  1, 0 },
            {  0, -1, 1 }
    }, new double[] { 1, 1, 1});
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

}
 
Example #2
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInconsistentEquations() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 4.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
    Assert.assertTrue(optimum.getValue() > 0.1);

}
 
Example #3
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][] {
             { 1.0, 1.0,  0.0,  0.0, 0.0,  0.0 },
             { 0.0, 0.0,  1.0,  1.0, 1.0,  0.0 },
             { 0.0, 0.0,  0.0,  0.0, 1.0, -1.0 },
             { 0.0, 0.0, -1.0,  1.0, 0.0,  1.0 },
             { 0.0, 0.0,  0.0, -1.0, 1.0,  0.0 }
    }, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
 
Example #4
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testColumnsPermutation() {
    LinearProblem problem =
        new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
                          new double[] { 4.0, 6.0, 1.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0 });
    Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(0.0, optimum.getValue(), 1.0e-10);

}
 
Example #5
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRedundantEquations() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
    Assert.assertEquals(2.0, optimum.getPoint()[0], 1.0e-8);
    Assert.assertEquals(1.0, optimum.getPoint()[1], 1.0e-8);

}
 
Example #6
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNoDependency() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 2, 0, 0, 0, 0, 0 },
            { 0, 2, 0, 0, 0, 0 },
            { 0, 0, 2, 0, 0, 0 },
            { 0, 0, 0, 2, 0, 0 },
            { 0, 0, 0, 0, 2, 0 },
            { 0, 0, 0, 0, 0, 2 }
    }, new double[] { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 });
    for (int i = 0; i < problem.target.length; ++i) {
        Assert.assertEquals(0.55 * i, optimum.getPoint()[i], 1.0e-10);
    }
}
 
Example #7
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testColumnsPermutation() {
    LinearProblem problem =
        new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
                          new double[] { 4.0, 6.0, 1.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0 });
    Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(0.0, optimum.getValue(), 1.0e-10);

}
 
Example #8
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersSimple() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 3.0, 2.0,  0.0, 0.0 },
            { 0.0, 1.0, -1.0, 1.0 },
            { 2.0, 0.0,  1.0, 0.0 }
    }, new double[] { 7.0, 3.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 7, 6, 5, 4 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);

}
 
Example #9
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testOneSet() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1,  0, 0 },
            { -1,  1, 0 },
            {  0, -1, 1 }
    }, new double[] { 1, 1, 1});
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

}
 
Example #10
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersSimple() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 3.0, 2.0,  0.0, 0.0 },
            { 0.0, 1.0, -1.0, 1.0 },
            { 2.0, 0.0,  1.0, 0.0 }
    }, new double[] { 7.0, 3.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 7, 6, 5, 4 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);

}
 
Example #11
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInconsistentEquations() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 4.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
    Assert.assertTrue(optimum.getValue() > 0.1);

}
 
Example #12
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testOneSet() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1,  0, 0 },
            { -1,  1, 0 },
            {  0, -1, 1 }
    }, new double[] { 1, 1, 1});
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

}
 
Example #13
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testColumnsPermutation() {
    LinearProblem problem =
        new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
                          new double[] { 4.0, 6.0, 1.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0 });
    Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(0.0, optimum.getValue(), 1.0e-10);

}
 
Example #14
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][] {
             { 1.0, 1.0,  0.0,  0.0, 0.0,  0.0 },
             { 0.0, 0.0,  1.0,  1.0, 1.0,  0.0 },
             { 0.0, 0.0,  0.0,  0.0, 1.0, -1.0 },
             { 0.0, 0.0, -1.0,  1.0, 0.0,  1.0 },
             { 0.0, 0.0,  0.0, -1.0, 1.0,  0.0 }
    }, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
 
Example #15
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testOneSet() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1,  0, 0 },
            { -1,  1, 0 },
            {  0, -1, 1 }
    }, new double[] { 1, 1, 1});
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

}
 
Example #16
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersSimple() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 3.0, 2.0,  0.0, 0.0 },
            { 0.0, 1.0, -1.0, 1.0 },
            { 2.0, 0.0,  1.0, 0.0 }
    }, new double[] { 7.0, 3.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 7, 6, 5, 4 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);

}
 
Example #17
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInconsistentEquations() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 4.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
    Assert.assertTrue(optimum.getValue() > 0.1);

}
 
Example #18
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 #19
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 #20
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][] {
             { 1.0, 1.0,  0.0,  0.0, 0.0,  0.0 },
             { 0.0, 0.0,  1.0,  1.0, 1.0,  0.0 },
             { 0.0, 0.0,  0.0,  0.0, 1.0, -1.0 },
             { 0.0, 0.0, -1.0,  1.0, 0.0,  1.0 },
             { 0.0, 0.0,  0.0, -1.0, 1.0,  0.0 }
    }, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
 
Example #21
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersSimple() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 3.0, 2.0,  0.0, 0.0 },
            { 0.0, 1.0, -1.0, 1.0 },
            { 2.0, 0.0,  1.0, 0.0 }
    }, new double[] { 7.0, 3.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 7, 6, 5, 4 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);

}
 
Example #22
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRedundantEquations() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 1.0,  1.0 },
            { 1.0, -1.0 },
            { 1.0,  3.0 }
    }, new double[] { 3.0, 1.0, 5.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
    Assert.assertEquals(2.0, optimum.getPoint()[0], 1.0e-8);
    Assert.assertEquals(1.0, optimum.getPoint()[1], 1.0e-8);

}
 
Example #23
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testColumnsPermutation() {
    LinearProblem problem =
        new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
                          new double[] { 4.0, 6.0, 1.0 });

    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0 });
    Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(0.0, optimum.getValue(), 1.0e-10);

}
 
Example #24
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNoDependency() {
    LinearProblem problem = new LinearProblem(new double[][] {
            { 2, 0, 0, 0, 0, 0 },
            { 0, 2, 0, 0, 0, 0 },
            { 0, 0, 2, 0, 0, 0 },
            { 0, 0, 0, 2, 0, 0 },
            { 0, 0, 0, 0, 2, 0 },
            { 0, 0, 0, 0, 0, 2 }
    }, new double[] { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 });
    for (int i = 0; i < problem.target.length; ++i) {
        Assert.assertEquals(0.55 * i, optimum.getPoint()[i], 1.0e-10);
    }
}
 
Example #25
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 #26
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][] {
             { 1.0, 1.0,  0.0,  0.0, 0.0,  0.0 },
             { 0.0, 0.0,  1.0,  1.0, 1.0,  0.0 },
             { 0.0, 0.0,  0.0,  0.0, 1.0, -1.0 },
             { 0.0, 0.0, -1.0,  1.0, 0.0,  1.0 },
             { 0.0, 0.0,  0.0, -1.0, 1.0,  0.0 }
    }, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
    Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
 
Example #27
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testOneSet() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1,  0, 0 },
            { -1,  1, 0 },
            {  0, -1, 1 }
    }, new double[] { 1, 1, 1});
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
        optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
    Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
    Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);

}
 
Example #28
Source File: NonLinearConjugateGradientOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNonInversible() {
    LinearProblem problem = new LinearProblem(new double[][] {
            {  1, 2, -3 },
            {  2, 1,  3 },
            { -3, 0, -9 }
    }, new double[] { 1, 1, 1 });
    NonLinearConjugateGradientOptimizer optimizer =
        new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                new SimpleValueChecker(1e-6, 1e-6));
    PointValuePair optimum =
            optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
    Assert.assertTrue(optimum.getValue() > 0.5);
}
 
Example #29
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMaximize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-15, 1e-30));
    optimizer.setSimplex(new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(200, fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 2e-8);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXpYp, optimum.getValue(), 2e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 180);
    Assert.assertTrue(optimizer.getEvaluations() < 220);
}
 
Example #30
Source File: SimplexOptimizerMultiDirectionalTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMaximize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-15, 1e-30));
    optimizer.setSimplex(new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(200, fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 2e-8);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXpYp, optimum.getValue(), 2e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 180);
    Assert.assertTrue(optimizer.getEvaluations() < 220);
}