• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Optimum类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Optimum类属于org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer包,在下文中一共展示了Optimum类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testEvaluationCount

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testEvaluationCount() {
    //setup
    LeastSquaresProblem lsp = new LinearProblem(new double[][] {{1}}, new double[] {1})
            .getBuilder()
            .checker(new ConvergenceChecker<Evaluation>() {
                public boolean converged(int iteration, Evaluation previous, Evaluation current) {
                    return true;
                }
            })
            .build();

    //action
    Optimum optimum = optimizer.optimize(lsp);

    //verify
    //check iterations and evaluations are not switched.
    Assert.assertThat(optimum.getIterations(), is(1));
    Assert.assertThat(optimum.getEvaluations(), is(2));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:LevenbergMarquardtOptimizerTest.java


示例2: testNoDependency

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@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});

    Optimum optimum = optimizer.optimize(problem.getBuilder().build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    for (int i = 0; i < problem.target.length; ++i) {
        Assert.assertEquals(0.55 * i, optimum.getPoint().getEntry(i), TOl);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例3: testTwoSets

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testTwoSets() {
    double epsilon = 1e-7;
    LinearProblem problem = new LinearProblem(new double[][]{
            {2, 1, 0, 4, 0, 0},
            {-4, -2, 3, -7, 0, 0},
            {4, 1, -2, 8, 0, 0},
            {0, -3, -12, -1, 0, 0},
            {0, 0, 0, 0, epsilon, 1},
            {0, 0, 0, 0, 1, 1}
    }, new double[]{2, -9, 2, 2, 1 + epsilon * epsilon, 2});

    Optimum optimum = optimizer.optimize(problem.getBuilder().build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(TOl, optimum.getPoint(), 3, 4, -1, -2, 1 + epsilon, 1 - epsilon);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例4: 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


示例5: testInconsistentSizes1

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

        //TODO why is this part here? hasn't it been tested already?
        Optimum optimum = optimizer.optimize(problem.getBuilder().build());

        Assert.assertEquals(0, optimum.getRMS(), TOl);
        assertEquals(TOl, optimum.getPoint(), -1, 1);

        //TODO move to builder test
        optimizer.optimize(
                problem.getBuilder().weight(new DiagonalMatrix(new double[]{1})).build());

        fail(optimizer);
    } catch (DimensionMismatchException e) {
        //expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例6: testInconsistentSizes2

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

        Optimum optimum = optimizer.optimize(problem.getBuilder().build());

        Assert.assertEquals(0, optimum.getRMS(), TOl);
        assertEquals(TOl, optimum.getPoint(), -1, 1);

        //TODO move to builder test
        optimizer.optimize(
                problem.getBuilder()
                        .target(new double[]{1})
                        .weight(new DiagonalMatrix(new double[]{1}))
                        .build()
        );

        fail(optimizer);
    } catch (DimensionMismatchException e) {
        //expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例7: testCircleFittingBadInit

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testCircleFittingBadInit() {
    CircleVectorial circle = new CircleVectorial();
    double[][] points = circlePoints;
    double[] weights = new double[points.length];
    final double[] start = {-12, -12};
    Arrays.fill(weights, 2);
    for (int i = 0; i < points.length; ++i) {
        circle.addPoint(points[i][0], points[i][1]);
    }

    Optimum optimum = optimizer.optimize(builder(circle).weight(new DiagonalMatrix(weights)).start(start).build());

    Vector2D center = new Vector2D(optimum.getPoint().getEntry(0), optimum.getPoint().getEntry(1));
    Assert.assertTrue(optimum.getEvaluations() < 25);
    Assert.assertEquals(0.043, optimum.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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例8: testCircleFittingGoodInit

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testCircleFittingGoodInit() {
    CircleVectorial circle = new CircleVectorial();
    double[][] points = circlePoints;
    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]);
    }
    final double[] start = {0, 0};

    Optimum optimum = optimizer.optimize(
            builder(circle).weight(new DiagonalMatrix(weights)).start(start).build());

    assertEquals(1e-6, optimum.getPoint(), -0.1517383071957963, 0.2074999736353867);
    Assert.assertEquals(0.04268731682389561, optimum.getRMS(), 1e-8);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例9: testNonInvertible

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
@Override
public void testNonInvertible() throws Exception {
    /*  SVD can compute a solution to singular problems.
     *  In this case the target vector, b, is not in the
     *  span of the jacobian matrix, A. The closes point
     *  to b on the plane spanned by A is computed.
     */
    LinearProblem problem = new LinearProblem(new double[][]{
            {1, 2, -3},
            {2, 1, 3},
            {-3, 0, -9}
    }, new double[]{1, 1, 1});

    Optimum optimum = optimizer.optimize(problem.getBuilder().build());

    Plane span = new Plane(Vector3D.ZERO, new Vector3D(1, 2, -3), new Vector3D(2, 1, 0), TOl);
    double expected = FastMath.abs(span.getOffset(new Vector3D(1, 1, 1)));
    double actual = optimum.getResiduals().getNorm();

    //verify
    Assert.assertEquals(expected, actual, TOl);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:GaussNewtonOptimizerWithSVDTest.java


示例10: refine

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
/**
 * Perform Levenburg-Marquardt non-linear optimisation to get better
 * estimates of the parameters
 */
private void refine()
{
	final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer();
	final RealVector start = buildInitialVector();
	final RealVector observed = buildObservedVector();
	final int maxEvaluations = 1000;
	final int maxIterations = 1000;

	final MultivariateVectorFunction value = new Value();
	final MultivariateMatrixFunction jacobian = new Jacobian();
	final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian);

	final Optimum result = lm.optimize(LeastSquaresFactory.create(model,
			observed, start, null, maxEvaluations, maxIterations));

	updateEstimates(result.getPoint());
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:CameraCalibrationZhang.java


示例11: saveResult

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
private void saveResult(Optimum optimum)
{
	createResultWindow();
	StringBuilder sb = new StringBuilder();
	Rounder rounder = RounderFactory.create(4);
	sb.append(fitZ.length * 2);
	sb.append('\t').append(pluginSettings.getWeightedFit());
	sb.append('\t').append(Utils.rounded(optimum.getRMS(), 6));
	sb.append('\t').append(optimum.getIterations());
	sb.append('\t').append(optimum.getEvaluations());
	sb.append('\t').append(rounder.round(parameters[P_GAMMA]));
	sb.append('\t').append(rounder.round(parameters[P_D]));
	sb.append('\t').append(rounder.round(parameters[P_S0X]));
	sb.append('\t').append(rounder.round(parameters[P_AX]));
	sb.append('\t').append(rounder.round(parameters[P_BX]));
	sb.append('\t').append(rounder.round(parameters[P_S0Y]));
	sb.append('\t').append(rounder.round(parameters[P_AY]));
	sb.append('\t').append(rounder.round(parameters[P_BY]));
	sb.append('\t').append(rounder.round(parameters[P_Z0]));
	resultsWindow.append(sb.toString());
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:22,代码来源:AstigmatismModelManager.java


示例12: solve

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
public Optimum solve(double[] target, double[] weights, double[] initialPoint, boolean debugInfo) {
	if (debugInfo) {
		System.out.println("Max Number of Iterations : " + MAXNUMBEROFITERATIONS);
	}

	LeastSquaresProblem leastSquaresProblem = LeastSquaresFactory.create(
			// function to be optimized
			function,
			// target values at optimal point in least square equation
			// (x0+xi)^2 + (y0+yi)^2 + ri^2 = target[i]
			new ArrayRealVector(target, false), new ArrayRealVector(initialPoint, false), new DiagonalMatrix(weights), null, MAXNUMBEROFITERATIONS, MAXNUMBEROFITERATIONS);

	return leastSquaresOptimizer.optimize(leastSquaresProblem);
}
 
开发者ID:berger89,项目名称:beacon-finder,代码行数:15,代码来源:NonLinearLeastSquaresSolver.java


示例13: testNonInvertible

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Override
@Test
public void testNonInvertible() {
    try{
        /*
         * Overrides the method from parent class, since the default singularity
         * threshold (1e-14) does not trigger the expected exception.
         */
        LinearProblem problem = new LinearProblem(new double[][] {
                {  1, 2, -3 },
                {  2, 1,  3 },
                { -3, 0, -9 }
        }, new double[] { 1, 1, 1 });

        final Optimum optimum = optimizer.optimize(
                problem.getBuilder().maxIterations(20).build());

        //TODO check that it is a bad fit? Why the extra conditions?
        Assert.assertTrue(FastMath.sqrt(problem.getTarget().length) * optimum.getRMS() > 0.6);

        optimum.getCovariances(1.5e-14);

        fail(optimizer);
    }catch (SingularMatrixException e){
        //expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:28,代码来源:LevenbergMarquardtOptimizerTest.java


示例14: testCircleFitting2

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testCircleFitting2() {
    final double xCenter = 123.456;
    final double yCenter = 654.321;
    final double xSigma = 10;
    final double ySigma = 15;
    final double radius = 111.111;
    // The test is extremely sensitive to the seed.
    final long seed = 59421061L;
    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 double[] paramFound = optimum.getPoint().toArray();

    // Retrieve errors estimation.
    final double[] asymptoticStandardErrorFound = optimum.getSigma(1e-14).toArray();

    // Check that the parameters are found within the assumed error bars.
    Assert.assertEquals(xCenter, paramFound[0], asymptoticStandardErrorFound[0]);
    Assert.assertEquals(yCenter, paramFound[1], asymptoticStandardErrorFound[1]);
    Assert.assertEquals(radius, paramFound[2], asymptoticStandardErrorFound[2]);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:37,代码来源:LevenbergMarquardtOptimizerTest.java


示例15: testGetIterations

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testGetIterations() {
    LeastSquaresProblem lsp = base()
            .target(new double[]{1})
            .weight(new DiagonalMatrix(new double[]{1}))
            .start(new double[]{3})
            .model(new MultivariateJacobianFunction() {
                public Pair<RealVector, RealMatrix> value(final RealVector point) {
                    return new Pair<RealVector, RealMatrix>(
                            new ArrayRealVector(
                                    new double[]{
                                            FastMath.pow(point.getEntry(0), 4)
                                    },
                                    false),
                            new Array2DRowRealMatrix(
                                    new double[][]{
                                            {0.25 * FastMath.pow(point.getEntry(0), 3)}
                                    },
                                    false)
                    );
                }
            })
            .build();

    Optimum optimum = optimizer.optimize(lsp);

    //TODO more specific test? could pass with 'return 1;'
    Assert.assertTrue(optimum.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:30,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例16: testTrivial

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testTrivial() {
    LinearProblem problem
            = new LinearProblem(new double[][]{{2}},
            new double[]{3});
    LeastSquaresProblem ls = problem.getBuilder().build();

    Optimum optimum = optimizer.optimize(ls);

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(TOl, optimum.getPoint(), 1.5);
    Assert.assertEquals(0.0, optimum.getResiduals().getEntry(0), TOl);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:14,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例17: testQRColumnsPermutation

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testQRColumnsPermutation() {
    LinearProblem problem
            = new LinearProblem(new double[][]{{1, -1}, {0, 2}, {1, -2}},
            new double[]{4, 6, 1});

    Optimum optimum = optimizer.optimize(problem.getBuilder().build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(TOl, optimum.getPoint(), 7, 3);
    assertEquals(TOl, optimum.getResiduals(), 0, 0, 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:13,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例18: testOneSet

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

    Optimum optimum = optimizer.optimize(problem.getBuilder().build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(TOl, optimum.getPoint(), 1, 2, 3);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:14,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例19: testIllConditioned

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@Test
public void testIllConditioned() {
    LinearProblem problem1 = new LinearProblem(new double[][]{
            {10, 7, 8, 7},
            {7, 5, 6, 5},
            {8, 6, 10, 9},
            {7, 5, 9, 10}
    }, new double[]{32, 23, 33, 31});
    final double[] start = {0, 1, 2, 3};

    Optimum optimum = optimizer
            .optimize(problem1.getBuilder().start(start).build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(TOl, optimum.getPoint(), 1, 1, 1, 1);

    LinearProblem problem2 = new LinearProblem(new double[][]{
            {10.00, 7.00, 8.10, 7.20},
            {7.08, 5.04, 6.00, 5.00},
            {8.00, 5.98, 9.89, 9.00},
            {6.99, 4.99, 9.00, 9.98}
    }, new double[]{32, 23, 33, 31});

    optimum = optimizer.optimize(problem2.getBuilder().start(start).build());

    Assert.assertEquals(0, optimum.getRMS(), TOl);
    assertEquals(1e-8, optimum.getPoint(), -81, 137, -34, 22);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:29,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java


示例20: testMoreEstimatedParametersSimple

import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum; //导入依赖的package包/类
@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});

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

    Assert.assertEquals(0, optimum.getRMS(), TOl);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:14,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NotifyCallback类代码示例发布时间:2022-05-22
下一篇:
Java GetTaskAttemptReportResponsePBImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap