Package org.apache.commons.math3.geometry.euclidean.twod

Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D


                                 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);
    }
View Full Code Here


        Assert.assertTrue(optimum.getEvaluations() < 10);

        double rms = optimum.getRMS();
        Assert.assertEquals(1.768262623567235, FastMath.sqrt(circle.getN()) * rms, TOl);

        Vector2D center = new Vector2D(optimum.getPoint().getEntry(0), optimum.getPoint().getEntry(1));
        Assert.assertEquals(69.96016176931406, circle.getRadius(center), 1e-6);
        Assert.assertEquals(96.07590211815305, center.getX(), 1e-6);
        Assert.assertEquals(48.13516790438953, center.getY(), 1e-6);

        double[][] cov = optimum.getCovariances(1e-14).getData();
        Assert.assertEquals(1.839, cov[0][0], 0.001);
        Assert.assertEquals(0.731, cov[0][1], 0.001);
        Assert.assertEquals(cov[0][1], cov[1][0], 1e-14);
        Assert.assertEquals(0.786, cov[1][1], 0.001);

        // add perfect measurements and check formal errors are reduced
        double r = circle.getRadius(center);
        for (double d = 0; d < 2 * FastMath.PI; d += 0.01) {
            circle.addPoint(center.getX() + r * FastMath.cos(d), center.getY() + r * FastMath.sin(d));
        }

        double[] weights = new double[circle.getN()];
        Arrays.fill(weights, 2);

View Full Code Here

            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);
    }
View Full Code Here

    private Vector2D create() {
        final double t = tP.sample();
        final double pX = cX.sample() + radius * FastMath.cos(t);
        final double pY = cY.sample() + radius * FastMath.sin(t);

        return new Vector2D(pX, pY);
    }
View Full Code Here

    public CircleVectorial() {
        points  = new ArrayList<Vector2D>();
    }

    public void addPoint(double px, double py) {
        points.add(new Vector2D(px, py));
    }
View Full Code Here

    }

    public ModelFunction getModelFunction() {
        return new ModelFunction(new MultivariateVectorFunction() {
                public double[] value(double[] params) {
                    Vector2D center = new Vector2D(params[0], params[1]);
                    double radius = getRadius(center);
                    double[] residuals = new double[points.size()];
                    for (int i = 0; i < residuals.length; i++) {
                        residuals[i] = points.get(i).distance(center) - radius;
                    }
View Full Code Here

    public ModelFunctionJacobian getModelFunctionJacobian() {
        return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
                public double[][] value(double[] params) {
                    final int n = points.size();
                    final Vector2D center = new Vector2D(params[0], params[1]);

                    double dRdX = 0;
                    double dRdY = 0;
                    for (Vector2D pk : points) {
                        double dk = pk.distance(center);
                        dRdX += (center.getX() - pk.getX()) / dk;
                        dRdY += (center.getY() - pk.getY()) / dk;
                    }
                    dRdX /= n;
                    dRdY /= n;

                    // Jacobian of the radius residuals.
                    double[][] jacobian = new double[n][2];
                    for (int i = 0; i < n; i++) {
                        final Vector2D pi = points.get(i);
                        final double di = pi.distance(center);
                        jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                        jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
                    }

                    return jacobian;
                }
        });
View Full Code Here

                                 new double[] { 98.680, 47.345 });
        Assert.assertTrue(optimizer.getEvaluations() < 10);
        Assert.assertTrue(optimizer.getJacobianEvaluations() < 10);
        double rms = optimizer.getRMS();
        Assert.assertEquals(1.768262623567235,  FastMath.sqrt(circle.getN()) * rms,  1.0e-10);
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.96016176931406, circle.getRadius(center), 1.0e-6);
        Assert.assertEquals(96.07590211815305, center.getX(),            1.0e-6);
        Assert.assertEquals(48.13516790438953, center.getY(),            1.0e-6);
        double[][] cov = optimizer.computeCovariances(optimum.getPoint(), 1e-14);
        Assert.assertEquals(1.839, cov[0][0], 0.001);
        Assert.assertEquals(0.731, cov[0][1], 0.001);
        Assert.assertEquals(cov[0][1], cov[1][0], 1.0e-14);
        Assert.assertEquals(0.786, cov[1][1], 0.001);

        // add perfect measurements and check errors are reduced
        double  r = circle.getRadius(center);
        for (double d= 0; d < 2 * FastMath.PI; d += 0.01) {
            circle.addPoint(center.getX() + r * FastMath.cos(d), center.getY() + r * FastMath.sin(d));
        }
        double[] target = new double[circle.getN()];
        Arrays.fill(target, 0.0);
        double[] weights = new double[circle.getN()];
        Arrays.fill(weights, 2.0);
View Full Code Here

            circle.addPoint(points[i][0], points[i][1]);
        }
        AbstractLeastSquaresOptimizer optimizer = createOptimizer();
        PointVectorValuePair optimum
            = optimizer.optimize(100, circle, target, weights, new double[] { -12, -12 });
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertTrue(optimizer.getEvaluations() < 25);
        Assert.assertTrue(optimizer.getJacobianEvaluations() < 20);
        Assert.assertEquals( 0.043, optimizer.getRMS(), 1.0e-3);
        Assert.assertEquals( 0.292235,  circle.getRadius(center), 1.0e-6);
        Assert.assertEquals(-0.151738,  center.getX(),            1.0e-6);
        Assert.assertEquals( 0.2075001, center.getY(),            1.0e-6);
    }
View Full Code Here

    public CircleVectorial() {
        points  = new ArrayList<Vector2D>();
    }

    public void addPoint(double px, double py) {
        points.add(new Vector2D(px, py));
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

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.