Package org.apache.commons.math.optimization.general

Examples of org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer


    @Test
    public void testMath304()
        throws OptimizationException, FunctionEvaluationException {

        LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
        CurveFitter fitter = new CurveFitter(optimizer);
        fitter.addObservedPoint(2.805d, 0.6934785852953367d);
        fitter.addObservedPoint(2.74333333333333d, 0.6306772025518496d);
        fitter.addObservedPoint(1.655d, 0.9474675497289684);
        fitter.addObservedPoint(1.725d, 0.9013594835804194d);
View Full Code Here


    }

    @Test
    public void testMath372()
    throws OptimizationException, FunctionEvaluationException {
        LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
        CurveFitter curveFitter = new CurveFitter(optimizer);

        curveFitter.addObservedPoint( 154443);
        curveFitter.addObservedPoint( 318493);
        curveFitter.addObservedPoint( 62, 17586);
        curveFitter.addObservedPoint(125, 30582);
        curveFitter.addObservedPoint(250, 45087);
        curveFitter.addObservedPoint(500, 50683);

        ParametricRealFunction f = new ParametricRealFunction() {

            public double value(double x, double[] parameters) {

                double a = parameters[0];
                double b = parameters[1];
                double c = parameters[2];
                double d = parameters[3];

                return d + ((a - d) / (1 + FastMath.pow(x / c, b)));
            }

            public double[] gradient(double x, double[] parameters) {

                double a = parameters[0];
                double b = parameters[1];
                double c = parameters[2];
                double d = parameters[3];

                double[] gradients = new double[4];
                double den = 1 + FastMath.pow(x / c, b);

                // derivative with respect to a
                gradients[0] = 1 / den;

                // derivative with respect to b
                // in the reported (invalid) issue, there was a sign error here
                gradients[1] = -((a - d) * FastMath.pow(x / c, b) * FastMath.log(x / c)) / (den * den);

                // derivative with respect to c
                gradients[2] = (b * FastMath.pow(x / c, b - 1) * (x / (c * c)) * (a - d)) / (den * den);

                // derivative with respect to d
                gradients[3] = 1 - (1 / den);

                return gradients;

            }
        };

        double[] initialGuess = new double[] { 1500, 0.95, 65, 35000 };
        double[] estimatedParameters = curveFitter.fit(f, initialGuess);

        Assert.assertEquals( 2411.00, estimatedParameters[0], 500.00);
        Assert.assertEquals(    1.62, estimatedParameters[1],   0.04);
        Assert.assertEquals111.22, estimatedParameters[2],   0.30);
        Assert.assertEquals(55347.47, estimatedParameters[3], 300.00);
        Assert.assertTrue(optimizer.getRMS() < 600.0);

    }
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test
    public void testFit01()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(DATASET1, fitter);
        GaussianFunction fitFunction = fitter.fit();
        assertEquals(99200.86969833552, fitFunction.getA(), 1e-4);
        assertEquals(3410515.285208688, fitFunction.getB(), 1e-4);
        assertEquals(4.054928275302832, fitFunction.getC(), 1e-4);
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test(expected=IllegalArgumentException.class)
    public void testFit02()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        fitter.fit();
    }
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test(expected=IllegalArgumentException.class)
    public void testFit03()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(new double[][] {
            {4.0254623531026.0},
            {4.02804905, 664002.0}},
            fitter);
        fitter.fit();
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test
    public void testFit04()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(DATASET2, fitter);
        GaussianFunction fitFunction = fitter.fit();
        assertEquals(-256534.689445631, fitFunction.getA(), 1e-4);
        assertEquals(481328.2181530679, fitFunction.getB(), 1e-4);
        assertEquals(-10.5217226891099, fitFunction.getC(), 1e-4);
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test
    public void testFit05()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(DATASET3, fitter);
        GaussianFunction fitFunction = fitter.fit();
        assertEquals(491.6310079258938, fitFunction.getA(), 1e-4);
        assertEquals(283508.6800413632, fitFunction.getB(), 1e-4);
        assertEquals(-13.2966857238057, fitFunction.getC(), 1e-4);
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test
    public void testFit06()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(DATASET4, fitter);
        GaussianFunction fitFunction = fitter.fit();
        assertEquals(530.3649792355617, fitFunction.getA(), 1e-4);
        assertEquals(284517.0835567514, fitFunction.getB(), 1e-4);
        assertEquals(-13.5355534565105, fitFunction.getC(), 1e-4);
View Full Code Here

     * @throws FunctionEvaluationException in the event of a test case error
     */
    @Test
    public void testFit07()
    throws OptimizationException, FunctionEvaluationException {
        GaussianFitter fitter = new GaussianFitter(new LevenbergMarquardtOptimizer());
        addDatasetToGaussianFitter(DATASET5, fitter);
        GaussianFunction fitFunction = fitter.fit();
        assertEquals(176748.1400947575, fitFunction.getA(), 1e-4);
        assertEquals(3361537.018813906, fitFunction.getB(), 1e-4);
        assertEquals(4.054949992747176, fitFunction.getC(), 1e-4);
View Full Code Here

        Random randomizer = new Random(64925784252l);
        for (int degree = 1; degree < 10; ++degree) {
            PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

            PolynomialFitter fitter =
                new PolynomialFitter(degree, new LevenbergMarquardtOptimizer());
            for (int i = 0; i <= degree; ++i) {
                fitter.addObservedPoint(1.0, i, p.value(i));
            }

            PolynomialFunction fitted = fitter.fit();
View Full Code Here

TOP

Related Classes of org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.