org.apache.commons.math3.optim.nonlinear.vector.Weight Java Examples
The following examples show how to use
org.apache.commons.math3.optim.nonlinear.vector.Weight.
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: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=DimensionMismatchException.class) public void testInconsistentSizes1() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 0 }, { 0, 1 } }, new double[] { -1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(-1, optimum.getPoint()[0], 1e-10); Assert.assertEquals(1, optimum.getPoint()[1], 1e-10); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0, 0 })); }
Example #2
Source File: AbstractLeastSquaresOptimizerTestValidation.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return the normalized chi-square. */ private double getChi2N(AbstractLeastSquaresOptimizer optim, StraightLineProblem problem, double[] params) { final double[] t = problem.target(); final double[] w = problem.weight(); optim.optimize(new MaxEval(Integer.MAX_VALUE), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(t), new Weight(w), new InitialGuess(params)); return optim.getChiSquare() / (t.length - params.length); }
Example #3
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=DimensionMismatchException.class) public void testInconsistentSizes1() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 0 }, { 0, 1 } }, new double[] { -1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(-1, optimum.getPoint()[0], 1e-10); Assert.assertEquals(1, optimum.getPoint()[1], 1e-10); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0, 0 })); }
Example #4
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void doTestStRD(final StatisticalReferenceDataset dataset, final double errParams, final double errParamsSd) { final AbstractLeastSquaresOptimizer optimizer = createOptimizer(); final double[] w = new double[dataset.getNumObservations()]; Arrays.fill(w, 1); final double[][] data = dataset.getData(); final double[] initial = dataset.getStartingPoint(0); final StatisticalReferenceDataset.LeastSquaresProblem problem = dataset.getLeastSquaresProblem(); final PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(data[1]), new Weight(w), new InitialGuess(initial)); final double[] actual = optimum.getPoint(); for (int i = 0; i < actual.length; i++) { double expected = dataset.getParameter(i); double delta = FastMath.abs(errParams * expected); Assert.assertEquals(dataset.getName() + ", param #" + i, expected, actual[i], delta); } }
Example #5
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testQRColumnsPermutation() { LinearProblem problem = new LinearProblem(new double[][] { { 1, -1 }, { 0, 2 }, { 1, -2 } }, new double[] { 4, 6, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(7, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3, optimum.getPoint()[1], 1e-10); Assert.assertEquals(4, optimum.getValue()[0], 1e-10); Assert.assertEquals(6, optimum.getValue()[1], 1e-10); Assert.assertEquals(1, optimum.getValue()[2], 1e-10); }
Example #6
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFittingBadInit() { CircleVectorial circle = new CircleVectorial(); double[][] points = circlePoints; double[] target = new double[points.length]; Arrays.fill(target, 0); double[] weights = new double[points.length]; Arrays.fill(weights, 2); for (int i = 0; i < points.length; ++i) { circle.addPoint(points[i][0], points[i][1]); } AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(target), new Weight(weights), new InitialGuess(new double[] { -12, -12 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertTrue(optimizer.getEvaluations() < 25); Assert.assertEquals( 0.043, optimizer.getRMS(), 1e-3); Assert.assertEquals( 0.292235, circle.getRadius(center), 1e-6); Assert.assertEquals(-0.151738, center.getX(), 1e-6); Assert.assertEquals( 0.2075001, center.getY(), 1e-6); }
Example #7
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 6 votes |
private void minpackTest(MinpackFunction function, boolean exceptionExpected) { LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(FastMath.sqrt(2.22044604926e-16), FastMath.sqrt(2.22044604926e-16), 2.22044604926e-16); try { PointVectorValuePair optimum = optimizer.optimize(new MaxEval(400 * (function.getN() + 1)), function.getModelFunction(), function.getModelFunctionJacobian(), new Target(function.getTarget()), new Weight(function.getWeight()), new InitialGuess(function.getStartPoint())); Assert.assertFalse(exceptionExpected); function.checkTheoreticalMinCost(optimizer.getRMS()); function.checkTheoreticalMinParams(optimum); } catch (TooManyEvaluationsException e) { Assert.assertTrue(exceptionExpected); } }
Example #8
Source File: GaussNewtonOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=TooManyEvaluationsException.class) public void testMaxEvaluations() throws Exception { CircleVectorial circle = new CircleVectorial(); 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); GaussNewtonOptimizer optimizer = new GaussNewtonOptimizer(new SimpleVectorValueChecker(1e-30, 1e-30)); optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(new double[] { 0, 0, 0, 0, 0 }), new Weight(new double[] { 1, 1, 1, 1, 1 }), new InitialGuess(new double[] { 98.680, 47.345 })); }
Example #9
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFittingBadInit() { CircleVectorial circle = new CircleVectorial(); double[][] points = circlePoints; double[] target = new double[points.length]; Arrays.fill(target, 0); double[] weights = new double[points.length]; Arrays.fill(weights, 2); for (int i = 0; i < points.length; ++i) { circle.addPoint(points[i][0], points[i][1]); } AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(target), new Weight(weights), new InitialGuess(new double[] { -12, -12 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertTrue(optimizer.getEvaluations() < 25); Assert.assertEquals( 0.043, optimizer.getRMS(), 1e-3); Assert.assertEquals( 0.292235, circle.getRadius(center), 1e-6); Assert.assertEquals(-0.151738, center.getX(), 1e-6); Assert.assertEquals( 0.2075001, center.getY(), 1e-6); }
Example #10
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testTrivial() { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(1.5, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10); }
Example #11
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testQRColumnsPermutation() { LinearProblem problem = new LinearProblem(new double[][] { { 1, -1 }, { 0, 2 }, { 1, -2 } }, new double[] { 4, 6, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(7, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3, optimum.getPoint()[1], 1e-10); Assert.assertEquals(4, optimum.getValue()[0], 1e-10); Assert.assertEquals(6, optimum.getValue()[1], 1e-10); Assert.assertEquals(1, optimum.getValue()[2], 1e-10); }
Example #12
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFittingBadInit() { CircleVectorial circle = new CircleVectorial(); double[][] points = circlePoints; double[] target = new double[points.length]; Arrays.fill(target, 0); double[] weights = new double[points.length]; Arrays.fill(weights, 2); for (int i = 0; i < points.length; ++i) { circle.addPoint(points[i][0], points[i][1]); } AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(target), new Weight(weights), new InitialGuess(new double[] { -12, -12 })); Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]); Assert.assertTrue(optimizer.getEvaluations() < 25); Assert.assertEquals( 0.043, optimizer.getRMS(), 1e-3); Assert.assertEquals( 0.292235, circle.getRadius(center), 1e-6); Assert.assertEquals(-0.151738, center.getX(), 1e-6); Assert.assertEquals( 0.2075001, center.getY(), 1e-6); }
Example #13
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOneSet() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 0, 0 }, { -1, 1, 0 }, { 0, -1, 1 } }, new double[] { 1, 1, 1}); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(1, optimum.getPoint()[0], 1e-10); Assert.assertEquals(2, optimum.getPoint()[1], 1e-10); Assert.assertEquals(3, optimum.getPoint()[2], 1e-10); }
Example #14
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=ConvergenceException.class) public void testNonInvertible() throws Exception { LinearProblem problem = new LinearProblem(new double[][] { { 1, 2, -3 }, { 2, 1, 3 }, { -3, 0, -9 } }, new double[] { 1, 1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0 })); }
Example #15
Source File: AbstractLeastSquaresOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testGetChiSquare() throws IOException { final StatisticalReferenceDataset dataset = StatisticalReferenceDatasetFactory.createKirby2(); final AbstractLeastSquaresOptimizer optimizer = createOptimizer(); final double[] a = dataset.getParameters(); final double[] y = dataset.getData()[1]; final double[] w = new double[y.length]; Arrays.fill(w, 1.0); StatisticalReferenceDataset.LeastSquaresProblem problem = dataset.getLeastSquaresProblem(); optimizer.optimize(new MaxEval(1), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(y), new Weight(w), new InitialGuess(a)); final double expected = dataset.getResidualSumOfSquares(); final double actual = optimizer.getChiSquare(); Assert.assertEquals(dataset.getName(), expected, actual, 1E-11 * expected); }
Example #16
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=DimensionMismatchException.class) public void testInconsistentSizes2() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 0 }, { 0, 1 } }, new double[] { -1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(-1, optimum.getPoint()[0], 1e-10); Assert.assertEquals(1, optimum.getPoint()[1], 1e-10); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(new double[] { 1 }), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0, 0 })); }
Example #17
Source File: MinpackTest.java From astor with GNU General Public License v2.0 | 6 votes |
private void minpackTest(MinpackFunction function, boolean exceptionExpected) { LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(FastMath.sqrt(2.22044604926e-16), FastMath.sqrt(2.22044604926e-16), 2.22044604926e-16); try { PointVectorValuePair optimum = optimizer.optimize(new MaxEval(400 * (function.getN() + 1)), function.getModelFunction(), function.getModelFunctionJacobian(), new Target(function.getTarget()), new Weight(function.getWeight()), new InitialGuess(function.getStartPoint())); Assert.assertFalse(exceptionExpected); function.checkTheoreticalMinCost(optimizer.getRMS()); function.checkTheoreticalMinParams(optimum); } catch (TooManyEvaluationsException e) { Assert.assertTrue(exceptionExpected); } }
Example #18
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=ConvergenceException.class) public void testNonInvertible() throws Exception { LinearProblem problem = new LinearProblem(new double[][] { { 1, 2, -3 }, { 2, 1, 3 }, { -3, 0, -9 } }, new double[] { 1, 1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0 })); }
Example #19
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMoreEstimatedParametersSimple() { LinearProblem problem = new LinearProblem(new double[][] { { 3, 2, 0, 0 }, { 0, 1, -1, 1 }, { 2, 0, 1, 0 } }, new double[] { 7, 3, 5 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 7, 6, 5, 4 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); }
Example #20
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMoreEstimatedParametersSimple() { LinearProblem problem = new LinearProblem(new double[][] { { 3, 2, 0, 0 }, { 0, 1, -1, 1 }, { 2, 0, 1, 0 } }, new double[] { 7, 3, 5 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 7, 6, 5, 4 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); }
Example #21
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=ConvergenceException.class) public void testNonInvertible() throws Exception { LinearProblem problem = new LinearProblem(new double[][] { { 1, 2, -3 }, { 2, 1, 3 }, { -3, 0, -9 } }, new double[] { 1, 1, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0 })); }
Example #22
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testInconsistentEquations() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 1 }, { 1, -1 }, { 1, 3 } }, new double[] { 3, 1, 4 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 1, 1 })); Assert.assertTrue(optimizer.getRMS() > 0.1); }
Example #23
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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, 1.1, 2.2, 3.3, 4.4, 5.5 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1, 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0, 0, 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); for (int i = 0; i < problem.target.length; ++i) { Assert.assertEquals(0.55 * i, optimum.getPoint()[i], 1e-10); } }
Example #24
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testQRColumnsPermutation() { LinearProblem problem = new LinearProblem(new double[][] { { 1, -1 }, { 0, 2 }, { 1, -2 } }, new double[] { 4, 6, 1 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(7, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3, optimum.getPoint()[1], 1e-10); Assert.assertEquals(4, optimum.getValue()[0], 1e-10); Assert.assertEquals(6, optimum.getValue()[1], 1e-10); Assert.assertEquals(1, optimum.getValue()[2], 1e-10); }
Example #25
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testTrivial() { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(1.5, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10); }
Example #26
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testOneSet() { LinearProblem problem = new LinearProblem(new double[][] { { 1, 0, 0 }, { -1, 1, 0 }, { 0, -1, 1 } }, new double[] { 1, 1, 1}); AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1, 1, 1 }), new InitialGuess(new double[] { 0, 0, 0 })); Assert.assertEquals(0, optimizer.getRMS(), 1e-10); Assert.assertEquals(1, optimum.getPoint()[0], 1e-10); Assert.assertEquals(2, optimum.getPoint()[1], 1e-10); Assert.assertEquals(3, optimum.getPoint()[2], 1e-10); }
Example #27
Source File: GaussNewtonOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=TooManyEvaluationsException.class) public void testMaxEvaluations() throws Exception { CircleVectorial circle = new CircleVectorial(); 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); GaussNewtonOptimizer optimizer = new GaussNewtonOptimizer(new SimpleVectorValueChecker(1e-30, 1e-30)); optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(new double[] { 0, 0, 0, 0, 0 }), new Weight(new double[] { 1, 1, 1, 1, 1 }), new InitialGuess(new double[] { 98.680, 47.345 })); }
Example #28
Source File: AbstractLeastSquaresOptimizerAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testCircleFittingGoodInit() { CircleVectorial circle = new CircleVectorial(); double[][] points = circlePoints; double[] target = new double[points.length]; Arrays.fill(target, 0); double[] weights = new double[points.length]; Arrays.fill(weights, 2); for (int i = 0; i < points.length; ++i) { circle.addPoint(points[i][0], points[i][1]); } AbstractLeastSquaresOptimizer optimizer = createOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), circle.getModelFunction(), circle.getModelFunctionJacobian(), new Target(target), new Weight(weights), new InitialGuess(new double[] { 0, 0 })); Assert.assertEquals(-0.1517383071957963, optimum.getPointRef()[0], 1e-6); Assert.assertEquals(0.2074999736353867, optimum.getPointRef()[1], 1e-6); Assert.assertEquals(0.04268731682389561, optimizer.getRMS(), 1e-8); }
Example #29
Source File: AbstractLeastSquaresOptimizerTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testGetChiSquare() throws IOException { final StatisticalReferenceDataset dataset = StatisticalReferenceDatasetFactory.createKirby2(); final AbstractLeastSquaresOptimizer optimizer = createOptimizer(); final double[] a = dataset.getParameters(); final double[] y = dataset.getData()[1]; final double[] w = new double[y.length]; Arrays.fill(w, 1.0); StatisticalReferenceDataset.LeastSquaresProblem problem = dataset.getLeastSquaresProblem(); optimizer.optimize(new MaxEval(1), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(y), new Weight(w), new InitialGuess(a)); final double expected = dataset.getResidualSumOfSquares(); final double actual = optimizer.getChiSquare(); Assert.assertEquals(dataset.getName(), expected, actual, 1E-11 * expected); }
Example #30
Source File: AbstractLeastSquaresOptimizerTestValidation.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @return the normalized chi-square. */ private double getChi2N(AbstractLeastSquaresOptimizer optim, StraightLineProblem problem, double[] params) { final double[] t = problem.target(); final double[] w = problem.weight(); optim.optimize(new MaxEval(Integer.MAX_VALUE), problem.getModelFunction(), problem.getModelFunctionJacobian(), new Target(t), new Weight(w), new InitialGuess(params)); return optim.getChiSquare() / (t.length - params.length); }