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


Java Optimum类代码示例

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


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


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