当前位置: 首页>>代码示例>>Java>>正文


Java Optimum.getPoint方法代码示例

本文整理汇总了Java中org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum.getPoint方法的典型用法代码示例。如果您正苦于以下问题:Java Optimum.getPoint方法的具体用法?Java Optimum.getPoint怎么用?Java Optimum.getPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum的用法示例。


在下文中一共展示了Optimum.getPoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMoreEstimatedParametersUnsorted

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入方法依赖的package包/类
@Test
public void testMoreEstimatedParametersUnsorted() {
    LinearProblem problem = new LinearProblem(new double[][]{
            {1, 1, 0, 0, 0, 0},
            {0, 0, 1, 1, 1, 0},
            {0, 0, 0, 0, 1, -1},
            {0, 0, -1, 1, 0, 1},
            {0, 0, 0, -1, 1, 0}
    }, new double[]{3, 12, -1, 7, 1});

    Optimum optimum = optimizer.optimize(
            problem.getBuilder().start(new double[]{2, 2, 2, 2, 2, 2}).build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    RealVector point = optimum.getPoint();
    //the first two elements are under constrained
    //check first two elements obey the constraint: sum to 3
    Assert.assertEquals(3, point.getEntry(0) + point.getEntry(1), TOl);
    //#constrains = #states fro the last 4 elements
    assertEquals(TOl, point.getSubVector(2, 4), 3, 4, 5, 6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java

示例2: doTestStRD

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入方法依赖的package包/类
public void doTestStRD(final StatisticalReferenceDataset dataset,
                       final LeastSquaresOptimizer optimizer,
                       final double errParams,
                       final double errParamsSd) {

    final Optimum optimum = optimizer.optimize(builder(dataset).build());

    final RealVector actual = optimum.getPoint();
    for (int i = 0; i < actual.getDimension(); i++) {
        double expected = dataset.getParameter(i);
        double delta = FastMath.abs(errParams * expected);
        Assert.assertEquals(dataset.getName() + ", param #" + i,
                expected, actual.getEntry(i), delta);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:16,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java

示例3: testBevington

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入方法依赖的package包/类
/**
 * Non-linear test case: fitting of decay curve (from Chapter 8 of
 * Bevington's textbook, "Data reduction and analysis for the physical sciences").
 * XXX The expected ("reference") values may not be accurate and the tolerance too
 * relaxed for this test to be currently really useful (the issue is under
 * investigation).
 */
@Test
public void testBevington() {
    final double[][] dataPoints = {
        // column 1 = times
        { 15, 30, 45, 60, 75, 90, 105, 120, 135, 150,
          165, 180, 195, 210, 225, 240, 255, 270, 285, 300,
          315, 330, 345, 360, 375, 390, 405, 420, 435, 450,
          465, 480, 495, 510, 525, 540, 555, 570, 585, 600,
          615, 630, 645, 660, 675, 690, 705, 720, 735, 750,
          765, 780, 795, 810, 825, 840, 855, 870, 885, },
        // column 2 = measured counts
        { 775, 479, 380, 302, 185, 157, 137, 119, 110, 89,
          74, 61, 66, 68, 48, 54, 51, 46, 55, 29,
          28, 37, 49, 26, 35, 29, 31, 24, 25, 35,
          24, 30, 26, 28, 21, 18, 20, 27, 17, 17,
          14, 17, 24, 11, 22, 17, 12, 10, 13, 16,
          9, 9, 14, 21, 17, 13, 12, 18, 10, },
    };
    final double[] start = {10, 900, 80, 27, 225};

    final BevingtonProblem problem = new BevingtonProblem();

    final int len = dataPoints[0].length;
    final double[] weights = new double[len];
    for (int i = 0; i < len; i++) {
        problem.addPoint(dataPoints[0][i],
                         dataPoints[1][i]);

        weights[i] = 1 / dataPoints[1][i];
    }

    final Optimum optimum = optimizer.optimize(
            builder(problem)
                    .target(dataPoints[1])
                    .weight(new DiagonalMatrix(weights))
                    .start(start)
                    .maxIterations(20)
                    .build()
    );

    final RealVector solution = optimum.getPoint();
    final double[] expectedSolution = { 10.4, 958.3, 131.4, 33.9, 205.0 };

    final RealMatrix covarMatrix = optimum.getCovariances(1e-14);
    final double[][] expectedCovarMatrix = {
        { 3.38, -3.69, 27.98, -2.34, -49.24 },
        { -3.69, 2492.26, 81.89, -69.21, -8.9 },
        { 27.98, 81.89, 468.99, -44.22, -615.44 },
        { -2.34, -69.21, -44.22, 6.39, 53.80 },
        { -49.24, -8.9, -615.44, 53.8, 929.45 }
    };

    final int numParams = expectedSolution.length;

    // Check that the computed solution is within the reference error range.
    for (int i = 0; i < numParams; i++) {
        final double error = FastMath.sqrt(expectedCovarMatrix[i][i]);
        Assert.assertEquals("Parameter " + i, expectedSolution[i], solution.getEntry(i), error);
    }

    // Check that each entry of the computed covariance matrix is within 10%
    // of the reference matrix entry.
    for (int i = 0; i < numParams; i++) {
        for (int j = 0; j < numParams; j++) {
            Assert.assertEquals("Covariance matrix [" + i + "][" + j + "]",
                                expectedCovarMatrix[i][j],
                                covarMatrix.getEntry(i, j),
                                FastMath.abs(0.1 * expectedCovarMatrix[i][j]));
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:79,代码来源:LevenbergMarquardtOptimizerTest.java

示例4: testParameterValidator

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入方法依赖的package包/类
@Test
public void testParameterValidator() {
    // Setup.
    final double xCenter = 123.456;
    final double yCenter = 654.321;
    final double xSigma = 10;
    final double ySigma = 15;
    final double radius = 111.111;
    final long seed = 3456789L;
    final RandomCirclePointGenerator factory
        = new RandomCirclePointGenerator(xCenter, yCenter, radius,
                                         xSigma, ySigma,
                                         seed);
    final CircleProblem circle = new CircleProblem(xSigma, ySigma);

    final int numPoints = 10;
    for (Vector2D p : factory.generate(numPoints)) {
        circle.addPoint(p.getX(), p.getY());
    }

    // First guess for the center's coordinates and radius.
    final double[] init = { 90, 659, 115 };
    final Optimum optimum
        = optimizer.optimize(builder(circle).maxIterations(50).start(init).build());
    final int numEval = optimum.getEvaluations();
    Assert.assertTrue(numEval > 1);

    // Build a new problem with a validator that amounts to cheating.
    final ParameterValidator cheatValidator
        = new ParameterValidator() {
                public RealVector validate(RealVector params) {
                    // Cheat: return the optimum found previously.
                    return optimum.getPoint();
                }
            };

    final Optimum cheatOptimum
        = optimizer.optimize(builder(circle).maxIterations(50).start(init).parameterValidator(cheatValidator).build());
    final int cheatNumEval = cheatOptimum.getEvaluations();
    Assert.assertTrue(cheatNumEval < numEval);
    // System.out.println("n=" + numEval + " nc=" + cheatNumEval);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:43,代码来源:LevenbergMarquardtOptimizerTest.java


注:本文中的org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum.getPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。