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

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


    }

    public double[] target() {
        final double[] t = new double[points.size() * 2];
        for (int i = 0; i < points.size(); i++) {
            final Vector2D p = points.get(i);
            final int index = i * 2;
            t[index]     = p.getX();
            t[index + 1] = p.getY();
        }

        return t;
    }
View Full Code Here


        final double r = params[2];

        final double[] model = new double[points.size() * 2];

        for (int i = 0; i < points.size(); i++) {
            final Vector2D p = points.get(i);

            // Find the circle point closest to the observed point
            // (observed points are points add through the addPoint method above)
            final double dX = cx - p.getX();
            final double dY = cy - p.getY();
            final double scaling = r / FastMath.hypot(dX, dY);
            final int index  = i * 2;
            model[index]     = cx - scaling * dX;
            model[index + 1] = cy - scaling * dY;

 
View Full Code Here

        final DerivativeStructure r = params[2];

        final DerivativeStructure[] model = new DerivativeStructure[points.size() * 2];

        for (int i = 0; i < points.size(); i++) {
            final Vector2D p = points.get(i);

            // Find the circle point closest to the observed point
            // (observed points are points add through the addPoint method above)
            final DerivativeStructure dX = cx.subtract(p.getX());
            final DerivativeStructure dY = cy.subtract(p.getY());
            final DerivativeStructure scaling = r.divide(dX.multiply(dX).add(dY.multiply(dY)).sqrt());
            final int index  = i * 2;
            model[index]     = cx.subtract(scaling.multiply(dX));
            model[index + 1] = cy.subtract(scaling.multiply(dY));

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 CircleScalar() {
        points  = new ArrayList<Vector2D>();
    }

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

        }
        return r.divide(points.size());
    }

    public double value(double[] variables)  {
        Vector2D center = new Vector2D(variables[0], variables[1]);
        double radius = getRadius(center);

        double sum = 0;
        for (Vector2D point : points) {
            double di = point.distance(center) - radius;
View Full Code Here

            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                    new SimpleValueChecker(1e-30, 1e-30),
                                                    new BrentSolver(1e-15, 1e-13));
        PointValuePair optimum =
            optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
        Assert.assertEquals(96.075902096, center.getX(), 1.0e-8);
        Assert.assertEquals(48.135167894, center.getY(), 1.0e-8);
    }
View Full Code Here

            = optimizer.optimize(new MaxEval(100),
                                 problem.getObjectiveFunction(),
                                 problem.getObjectiveFunctionGradient(),
                                 GoalType.MINIMIZE,
                                 new InitialGuess(new double[] { 98.680, 47.345 }));
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8);
        Assert.assertEquals(96.075902096, center.getX(), 1.0e-7);
        Assert.assertEquals(48.135167894, center.getY(), 1.0e-6);
    }
View Full Code Here

        PointValuePair optimum =
            optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Assert.assertEquals(200, optimizer.getMaxEvaluations());
        PointValuePair[] optima = optimizer.getOptima();
        for (PointValuePair o : optima) {
            Vector2D center = new Vector2D(o.getPointRef()[0], o.getPointRef()[1]);
            Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
            Assert.assertEquals(96.075902096, center.getX(), 1.0e-8);
            Assert.assertEquals(48.135167894, center.getY(), 1.0e-8);
        }
        Assert.assertTrue(optimizer.getEvaluations() > 70);
        Assert.assertTrue(optimizer.getEvaluations() < 90);
        Assert.assertEquals(3.1267527, optimum.getValue(), 1.0e-8);
    }
View Full Code Here

                                 new Weight(new double[] { 1, 1, 1, 1, 1 }),
                                 new InitialGuess(new double[] { 98.680, 47.345 }));
        Assert.assertTrue(optimizer.getEvaluations() < 10);
        double rms = optimizer.getRMS();
        Assert.assertEquals(1.768262623567235,  FastMath.sqrt(circle.getN()) * rms,  1e-10);
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[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 = 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], 1e-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);
        double[] weights = new double[circle.getN()];
        Arrays.fill(weights, 2);
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.