Example usage for org.apache.commons.math3.linear RealMatrix setEntry

List of usage examples for org.apache.commons.math3.linear RealMatrix setEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealMatrix setEntry.

Prototype

void setEntry(int row, int column, double value) throws OutOfRangeException;

Source Link

Document

Set the entry in the specified row and column.

Usage

From source file:org.rhwlab.dispim.nucleus.NucleusData.java

public Ellipse2d ellipse(int xi, int yi, int zi, Coeff coef) {
    Array2DRowRealMatrix Q = new Array2DRowRealMatrix(3, 3);
    Q.setEntry(0, 0, coef.A);/*from  w  ww  . j  a v  a  2s .  c  o  m*/
    Q.setEntry(1, 0, coef.B / 2);
    Q.setEntry(0, 1, coef.B / 2);
    Q.setEntry(1, 1, coef.C);
    Q.setEntry(2, 0, coef.D / 2);
    Q.setEntry(0, 2, coef.D / 2);
    Q.setEntry(2, 1, coef.E / 2);
    Q.setEntry(1, 2, coef.E / 2);
    Q.setEntry(2, 2, coef.F);
    EigenDecomposition ed = new EigenDecomposition(Q);
    double detQ = ed.getDeterminant();

    RealMatrix rm = new Array2DRowRealMatrix(2, 2);
    rm.setEntry(0, 0, coef.A);
    rm.setEntry(1, 1, coef.C);
    rm.setEntry(0, 1, coef.B / 2.0);
    rm.setEntry(1, 0, coef.B / 2.0);
    EigenDecomposition eigenDecomp = new EigenDecomposition(rm);
    double detA33 = eigenDecomp.getDeterminant();
    double[] eigenValues = eigenDecomp.getRealEigenvalues();
    //System.out.printf("Eigenvalues: %f,%f\n",eigenValues[0],eigenValues[1])        ;
    RealVector eigenvector0 = eigenDecomp.getEigenvector(0);
    Ellipse2d e = new Ellipse2d();
    double cot2theta = (coef.A - coef.C) / coef.B;
    if (Double.isFinite(cot2theta)) {
        double d = Math.sqrt(1.0 + cot2theta * cot2theta);
        double cos2theta = cot2theta / d;
        e.cosine = Math.sqrt((1.0 + cos2theta) / 2.0);
        e.sine = Math.sqrt((1.0 - cos2theta) / 2.0);
    } else {
        e.cosine = 1.0;
        e.sine = 0.0;
    }

    double dd = coef.B * coef.B - 4.0 * coef.A * coef.C;
    double xc = (2.0 * coef.C * coef.D - coef.B * coef.E) / dd;
    double yc = (2.0 * coef.A * coef.E - coef.B * coef.D) / dd;
    // System.out.printf("dd=%f,xc=%f,xcn=%f,yc=%f,ycn%f\n",dd,xc,xcn,yc,ycn);
    double[] ce = this.getCenter();
    e.x = ce[xi] + xc;
    e.y = ce[yi] + yc;

    //       double f = -detQ/detA33 * 2;
    double f = -detQ / detA33;
    double a = eigenValues[0] / f;
    double b = eigenValues[1] / f;
    if (a <= 0.0 || b <= 0.0) {
        return null;
    }
    e.a = 1.0 / Math.sqrt(a);
    e.b = 1.0 / Math.sqrt(b);
    //System.out.printf("detQ=%e,detA33=%e,f=%f,a=%e,b=%e\n",detQ,detA33,f,e.a,e.b);        
    //System.out.printf("eigenValues (%f,%f)\n",eigenValues[0],eigenValues[1]);
    e.cosine = eigenvector0.getEntry(0);
    e.sine = eigenvector0.getEntry(1);
    e.low[xi] = (long) (e.x - e.a);
    e.low[yi] = (long) (e.y - e.b);
    e.low[zi] = 0;
    e.high[xi] = (long) (e.x + e.a);
    e.high[yi] = (long) (e.y + e.b);
    e.high[zi] = 0;
    //System.out.printf("Ellipse: a=%f,b=%f,x=%f,y=%f\n", e.a,e.b,e.x,e.y);
    return e;
}

From source file:org.rhwlab.dispim.nucleus.NucleusData.java

public RealMatrix quadraticSurfaceMatrix() {
    int D = 4;/*ww w  .  j  a va  2s  .co m*/
    int Dm1 = 3;

    RealMatrix T = new Array2DRowRealMatrix(D, D);
    for (int r = 0; r < D; ++r) {
        for (int c = 0; c < D; ++c) {
            if (r == c) {
                T.setEntry(r, c, 1.0);
            } else {
                T.setEntry(r, c, 0.0);
            }
        }
    }
    T.setEntry(Dm1, 0, -xC);
    T.setEntry(Dm1, 1, -yC);
    T.setEntry(Dm1, 2, -zC);

    RealMatrix TT = T.transpose();

    RealMatrix C = new Array2DRowRealMatrix(D, D);
    for (int r = 0; r < adjustedA.getRowDimension(); ++r) {
        for (int c = 0; c < adjustedA.getColumnDimension(); ++c) {
            C.setEntry(r, c, .8 * adjustedA.getEntry(r, c)); // make the effective radii bigger to get separation of the nuclei
        }
    }
    for (int d = 0; d < Dm1; ++d) {
        C.setEntry(Dm1, d, 0.0);
        C.setEntry(d, Dm1, 0.0);
    }
    C.setEntry(Dm1, Dm1, -1.0);

    return T.multiply(C.multiply(TT));
}

From source file:org.um.feri.ears.algorithms.moo.dbea.DBEA.java

/**
 * Updates the ideal point and intercepts given the new solution.
 * //from w  w  w . j a va2s  .c  om
 * @param solution the new solution
 */
void updateIdealPointAndIntercepts(MOSolutionBase<Type> solution) {
    if (!solution.violatesConstraints()) {
        // update the ideal point
        for (int j = 0; j < num_obj; j++) {
            idealPoint[j] = Math.min(idealPoint[j], solution.getObjective(j));
            intercepts[j] = Math.max(intercepts[j], solution.getObjective(j));
        }

        // compute the axis intercepts
        ParetoSolution<Type> feasibleSolutions = getFeasibleSolutions(population);
        feasibleSolutions.add(solution);

        ParetoSolution<Type> nondominatedSolutions = getNondominatedFront(feasibleSolutions);

        if (!nondominatedSolutions.isEmpty()) {
            // find the points with the largest value in each objective
            ParetoSolution<Type> extremePoints = new ParetoSolution<Type>();

            for (int i = 0; i < num_obj; i++) {
                extremePoints.add(largestObjectiveValue(i, nondominatedSolutions));
            }

            if (numberOfUniqueSolutions(extremePoints) != num_obj) {
                for (int i = 0; i < num_obj; i++) {
                    intercepts[i] = extremePoints.get(i).getObjective(i);
                }
            } else {
                try {
                    RealMatrix b = new Array2DRowRealMatrix(num_obj, 1);
                    RealMatrix A = new Array2DRowRealMatrix(num_obj, num_obj);

                    for (int i = 0; i < num_obj; i++) {
                        b.setEntry(i, 0, 1.0);

                        for (int j = 0; j < num_obj; j++) {
                            A.setEntry(i, j, extremePoints.get(i).getObjective(j));
                        }
                    }

                    double numerator = new LUDecomposition(A).getDeterminant();
                    b.scalarMultiply(numerator);
                    RealMatrix normal = MatrixUtils.inverse(A).multiply(b);

                    for (int i = 0; i < num_obj; i++) {
                        intercepts[i] = numerator / normal.getEntry(i, 0);

                        if (intercepts[i] <= 0 || Double.isNaN(intercepts[i])
                                || Double.isInfinite(intercepts[i])) {
                            intercepts[i] = extremePoints.get(i).getObjective(i);
                        }
                    }
                } catch (RuntimeException e) {
                    for (int i = 0; i < num_obj; i++) {
                        intercepts[i] = extremePoints.get(i).getObjective(i);
                    }
                }
            }
        }
    }
}

From source file:pl.matrix.core.MatrixCalculator.java

public Matrix transformToTriangularUpperMatrix(Matrix a) throws Exception {
    RealMatrix aRealMatrix = a.toRealMatrix();

    if (aRealMatrix.getRowDimension() != aRealMatrix.getColumnDimension()) {
        throw new Exception();
    }// w  ww  .  j  av a2s . c  om

    int n = aRealMatrix.getRowDimension();
    // iteracja (zerowanie i-tej kolumny)
    for (int i = 0; i < n - 1; i++) {
        // po wierszach
        for (int j = i + 1; j < n; j++) {
            double factor = aRealMatrix.getEntry(j, i) / aRealMatrix.getEntry(i, i);

            // po kolumnach
            for (int k = i; k < n; k++) {
                double newValue = aRealMatrix.getEntry(j, k) - factor * aRealMatrix.getEntry(i, k);
                aRealMatrix.setEntry(j, k, newValue);
            }
        }
    }
    Matrix result = new Matrix(aRealMatrix);

    return result;
}

From source file:playground.sergioo.facilitiesGenerator2012.WorkFacilitiesGeneration.java

private static Set<PointPerson> getPCATransformation(Collection<PointPerson> points) {
    RealMatrix pointsM = new Array2DRowRealMatrix(points.iterator().next().getDimension(), points.size());
    int k = 0;//from  w  w w.  j  a  va2 s . c o  m
    for (PointND<Double> point : points) {
        for (int f = 0; f < point.getDimension(); f++)
            pointsM.setEntry(f, k, point.getElement(f));
        k++;
    }
    RealMatrix means = new Array2DRowRealMatrix(pointsM.getRowDimension(), 1);
    for (int r = 0; r < means.getRowDimension(); r++) {
        double mean = 0;
        for (int c = 0; c < pointsM.getColumnDimension(); c++)
            mean += pointsM.getEntry(r, c) / pointsM.getColumnDimension();
        means.setEntry(r, 0, mean);
    }
    RealMatrix deviations = new Array2DRowRealMatrix(pointsM.getRowDimension(), pointsM.getColumnDimension());
    for (int r = 0; r < deviations.getRowDimension(); r++)
        for (int c = 0; c < deviations.getColumnDimension(); c++)
            deviations.setEntry(r, c, pointsM.getEntry(r, c) - means.getEntry(r, 0));
    RealMatrix covariance = deviations.multiply(deviations.transpose())
            .scalarMultiply(1 / (double) pointsM.getColumnDimension());
    EigenDecomposition eigenDecomposition = new EigenDecomposition(covariance, 0);
    RealMatrix eigenVectorsT = eigenDecomposition.getVT();
    RealVector eigenValues = new ArrayRealVector(eigenDecomposition.getD().getRowDimension());
    for (int r = 0; r < eigenDecomposition.getD().getRowDimension(); r++)
        eigenValues.setEntry(r, eigenDecomposition.getD().getEntry(r, r));
    for (int i = 0; i < eigenValues.getDimension(); i++) {
        for (int j = i + 1; j < eigenValues.getDimension(); j++)
            if (eigenValues.getEntry(i) < eigenValues.getEntry(j)) {
                double tempValue = eigenValues.getEntry(i);
                eigenValues.setEntry(i, eigenValues.getEntry(j));
                eigenValues.setEntry(j, tempValue);
                RealVector tempVector = eigenVectorsT.getRowVector(i);
                eigenVectorsT.setRowVector(i, eigenVectorsT.getRowVector(j));
                eigenVectorsT.setRowVector(j, tempVector);
            }
        eigenVectorsT.setRowVector(i,
                eigenVectorsT.getRowVector(i).mapMultiply(Math.sqrt(1 / eigenValues.getEntry(i))));
    }
    RealVector standardDeviations = new ArrayRealVector(pointsM.getRowDimension());
    for (int r = 0; r < covariance.getRowDimension(); r++)
        standardDeviations.setEntry(r, Math.sqrt(covariance.getEntry(r, r)));
    double zValue = standardDeviations.dotProduct(new ArrayRealVector(pointsM.getRowDimension(), 1));
    RealMatrix zScore = deviations.scalarMultiply(1 / zValue);
    pointsM = eigenVectorsT.multiply(zScore);
    Set<PointPerson> pointsC = new HashSet<PointPerson>();
    k = 0;
    for (PointPerson point : points) {
        PointPerson pointC = new PointPerson(point.getId(), point.getOccupation(),
                new Double[] { pointsM.getEntry(0, k), pointsM.getEntry(1, k) }, point.getPlaceType());
        pointC.setWeight(point.getWeight());
        pointsC.add(pointC);
        k++;
    }
    return pointsC;
}

From source file:plugins.SURFPixelMatching.java

private void run() {

    try {//from w w w. j  av a2s  .  c o m
        // variables
        int a, b, c, i, j, k, n, r;
        int row, col;
        int progress, oldProgress;
        double x, y, z, newX, newY;
        double x2, y2;
        double north, south, east, west;
        double newNorth, newSouth, newEast, newWest;
        double rightNodata;
        double leftNodata;
        Object[] rowData;
        whitebox.geospatialfiles.shapefile.Point outputPoint;
        ShapeFile rightTiePoints;
        ShapeFile leftTiePoints;
        ShapeFile rightFiducials;
        ShapeFile leftFiducials;
        XYPoint xyPoint;
        ArrayList<XYPoint> leftTiePointsList = new ArrayList<>();
        ArrayList<XYPoint> rightTiePointsList = new ArrayList<>();

        float balanceValue = 0.81f;
        float threshold = 0.004f;
        int octaves = 4;
        double maxAllowableRMSE = 1.0;
        double matchingThreshold = 0.6;

        // left image
        //String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus_C6430-74072-L9_253_Blue_clipped.dep";
        //String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/Guelph_A19409-82_Blue.dep";
        //String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus 253.dep";
        //String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus 253 epipolar.dep";
        String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/Guelph_A19409-82_Blue low res.dep";
        //String leftImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/tmp1.dep";

        // right image
        //String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus_C6430-74072-L9_254_Blue_clipped.dep";
        //String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/Guelph_A19409-83_Blue.dep";
        //String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus 254.dep";
        //String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus 254 epipolar.dep";
        String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/Guelph_A19409-83_Blue low res.dep";
        //String rightImageName = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/GuelphCampus 253.dep";

        String leftOutputHeader = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/tmp4.shp";

        String rightOutputHeader = "/Users/johnlindsay/Documents/Teaching/GEOG2420/airphotos/tmp4_2.shp";

        DBFField[] fields = new DBFField[5];
        fields[0] = new DBFField();
        fields[0].setName("FID");
        fields[0].setDataType(DBFField.DBFDataType.NUMERIC);
        fields[0].setDecimalCount(4);
        fields[0].setFieldLength(10);

        fields[1] = new DBFField();
        fields[1].setName("ORIENT");
        fields[1].setDataType(DBFField.DBFDataType.NUMERIC);
        fields[1].setDecimalCount(4);
        fields[1].setFieldLength(10);

        fields[2] = new DBFField();
        fields[2].setName("SCALE");
        fields[2].setDataType(DBFField.DBFDataType.NUMERIC);
        fields[2].setDecimalCount(4);
        fields[2].setFieldLength(10);

        fields[3] = new DBFField();
        fields[3].setName("LAPLAC");
        fields[3].setDataType(DBFField.DBFDataType.NUMERIC);
        fields[3].setDecimalCount(4);
        fields[3].setFieldLength(10);

        fields[4] = new DBFField();
        fields[4].setName("RESID");
        fields[4].setDataType(DBFField.DBFDataType.NUMERIC);
        fields[4].setDecimalCount(4);
        fields[4].setFieldLength(10);

        // read the input data
        WhiteboxRaster leftImage = new WhiteboxRaster(leftImageName, "r");
        //            leftImage.setForceAllDataInMemory(true);
        int nRowsLeft = leftImage.getNumberRows();
        int nColsLeft = leftImage.getNumberColumns();
        leftNodata = leftImage.getNoDataValue();

        WhiteboxRaster rightImage = new WhiteboxRaster(rightImageName, "r");
        //rightImage.setForceAllDataInMemory(true);
        //            int nRowsRight = rightImage.getNumberRows();
        //            int nColsRight = rightImage.getNumberColumns();
        rightNodata = rightImage.getNoDataValue();

        //            ArrayList<InterestPoint> interest_points;
        //            double threshold = 600;
        //            double balanceValue = 0.9;
        //            int octaves = 4;
        //            ISURFfactory mySURF = SURF.createInstance(leftImage, balanceValue, threshold, octaves);
        //            IDetector detector = mySURF.createDetector();
        //            interest_points = detector.generateInterestPoints();
        //            System.out.println("Interest points generated");
        //            IDescriptor descriptor = mySURF.createDescriptor(interest_points);
        //            descriptor.generateAllDescriptors();
        System.out.println("Performing SURF analysis on left image...");
        Surf leftSurf = new Surf(leftImage, balanceValue, threshold, octaves);
        //            if (leftSurf.getNumberOfPoints() > 500000) {
        //                System.out.println("Number of points exceeds limit, reset threshold: " + leftSurf.getNumberOfPoints());
        //                return;
        //            }
        if (leftSurf.getNumberOfPoints() == 0) {
            System.out
                    .println("Number of points equals zero, reset threshold: " + leftSurf.getNumberOfPoints());
            return;
        }

        System.out.println("Performing SURF analysis on right image...");
        Surf rightSurf = new Surf(rightImage, balanceValue, threshold, octaves);
        if (rightSurf.getNumberOfPoints() == 0) {
            System.out
                    .println("Number of points equals zero, reset threshold: " + leftSurf.getNumberOfPoints());
            return;
        }

        System.out.println("Matching points of interest...");
        Map<SURFInterestPoint, SURFInterestPoint> matchingPoints = leftSurf.getMatchingPoints(rightSurf,
                matchingThreshold, false);

        int numTiePoints = matchingPoints.size();
        if (numTiePoints < 3) {
            System.err.println(
                    "The number of potential tie points is less than 3. Adjust your threshold parameters and retry.");
            return;
        }
        System.out.println(numTiePoints + " potential tie points located");
        System.out.println("Trimming outlier tie points...");

        boolean flag;
        do {
            flag = false;
            leftTiePointsList.clear();
            rightTiePointsList.clear();
            i = 0;
            for (SURFInterestPoint point : matchingPoints.keySet()) {
                x = point.getX();
                y = point.getY();

                SURFInterestPoint target = matchingPoints.get(point);
                x2 = target.getX();
                y2 = target.getY();

                leftTiePointsList.add(new XYPoint(x, y));
                rightTiePointsList.add(new XYPoint(x2, y2));

                i++;
            }

            PolynomialLeastSquares2DFitting overallFit = new PolynomialLeastSquares2DFitting(leftTiePointsList,
                    rightTiePointsList, 1);

            double maxDist = 0;
            SURFInterestPoint mostInfluentialPoint = null;
            i = 0;
            for (SURFInterestPoint point : matchingPoints.keySet()) {
                leftTiePointsList.clear();
                rightTiePointsList.clear();
                for (SURFInterestPoint point2 : matchingPoints.keySet()) {
                    if (point2 != point) {
                        x = point2.getX();
                        y = point2.getY();

                        SURFInterestPoint target = matchingPoints.get(point2);
                        x2 = target.getX();
                        y2 = target.getY();

                        leftTiePointsList.add(new XYPoint(x, y));
                        rightTiePointsList.add(new XYPoint(x2, y2));
                    }
                }
                PolynomialLeastSquares2DFitting newFit = new PolynomialLeastSquares2DFitting(leftTiePointsList,
                        rightTiePointsList, 1);

                x = point.getX();
                y = point.getY();
                XYPoint pt1 = overallFit.getForwardCoordinates(x, y);
                XYPoint pt2 = newFit.getForwardCoordinates(x, y);
                double dist = pt1.getSquareDistance(pt2);
                if (dist > maxDist) {
                    maxDist = dist;
                    mostInfluentialPoint = point;
                }
            }

            if (maxDist > 10 && mostInfluentialPoint != null) {
                matchingPoints.remove(mostInfluentialPoint);
                flag = true;
            }
            System.out.println(maxDist);
        } while (flag);

        int numPoints = matchingPoints.size();

        // create homogeneous points matrices
        double[][] leftPoints = new double[3][numPoints];
        double[][] rightPoints = new double[3][numPoints];

        i = 0;
        for (SURFInterestPoint point : matchingPoints.keySet()) {
            leftPoints[0][i] = point.getX();
            leftPoints[1][i] = point.getY();
            leftPoints[2][i] = 1;

            SURFInterestPoint target = matchingPoints.get(point);

            rightPoints[0][i] = target.getX();
            rightPoints[1][i] = target.getY();
            rightPoints[2][i] = 1;
            i++;
        }

        double[][] normalizedLeftPoints = Normalize2DHomogeneousPoints.normalize(leftPoints);
        RealMatrix Tl = MatrixUtils.createRealMatrix(Normalize2DHomogeneousPoints.T);
        double[][] normalizedRightPoints = Normalize2DHomogeneousPoints.normalize(rightPoints);
        RealMatrix Tr = MatrixUtils.createRealMatrix(Normalize2DHomogeneousPoints.T);

        RealMatrix pnts1 = MatrixUtils.createRealMatrix(normalizedLeftPoints);
        RealMatrix pnts2 = MatrixUtils.createRealMatrix(normalizedRightPoints);

        RealMatrix A = MatrixUtils.createRealMatrix(buildA(normalizedLeftPoints, normalizedRightPoints));

        //RealMatrix ata = A.transpose().multiply(A);
        SingularValueDecomposition svd = new SingularValueDecomposition(A);

        RealMatrix V = svd.getV();
        RealVector V_smallestSingularValue = V.getColumnVector(8);
        RealMatrix F = MatrixUtils.createRealMatrix(3, 3);
        for (i = 0; i < 9; i++) {
            F.setEntry(i / 3, i % 3, V_smallestSingularValue.getEntry(i));
        }

        for (i = 0; i < V.getRowDimension(); i++) {
            System.out.println(V.getRowVector(i).toString());
        }

        SingularValueDecomposition svd2 = new SingularValueDecomposition(F);
        RealMatrix U = svd2.getU();
        RealMatrix S = svd2.getS();
        V = svd2.getV();
        RealMatrix m = MatrixUtils.createRealMatrix(
                new double[][] { { S.getEntry(1, 1), 0, 0 }, { 0, S.getEntry(2, 2), 0 }, { 0, 0, 0 } });
        F = U.multiply(m).multiply(V).transpose();

        // Denormalise
        F = Tr.transpose().multiply(F).multiply(Tl);
        for (i = 0; i < F.getRowDimension(); i++) {
            System.out.println(F.getRowVector(i).toString());
        }

        svd2 = new SingularValueDecomposition(F);
        //[U,D,V] = svd(F,0);
        RealMatrix e1 = svd2.getV().getColumnMatrix(2); //hnormalise(svd2.getV(:,3));
        RealMatrix e2 = svd2.getU().getColumnMatrix(2); //e2 = hnormalise(U(:,3));

        e1.setEntry(0, 0, (e1.getEntry(0, 0) / e1.getEntry(2, 0)));
        e1.setEntry(1, 0, (e1.getEntry(1, 0) / e1.getEntry(2, 0)));
        e1.setEntry(2, 0, 1);

        e2.setEntry(0, 0, (e2.getEntry(0, 0) / e2.getEntry(2, 0)));
        e2.setEntry(1, 0, (e2.getEntry(1, 0) / e2.getEntry(2, 0)));
        e2.setEntry(2, 0, 1);

        System.out.println("");

        //                boolean[] removeTiePoint = new boolean[numTiePoints];
        //                double[] residuals = null;
        //                double[] residualsOrientation = null;
        //                boolean flag;
        //                do {
        //                    // perform the initial tie point transformation
        //                    leftTiePointsList.clear();
        //                    rightTiePointsList.clear();
        //                    int numPointsIncluded = 0;
        //                    i = 0;
        //                    for (SURFInterestPoint point : matchingPoints.keySet()) {
        //                        if (i < numTiePoints && !removeTiePoint[i]) {
        //                            x = point.getX();
        //                            y = point.getY();
        //
        //                            SURFInterestPoint target = matchingPoints.get(point);
        //                            x2 = target.getX();
        //                            y2 = target.getY();
        //
        //                            leftTiePointsList.add(new XYPoint(x, y));
        //                            rightTiePointsList.add(new XYPoint(x2, y2));
        //
        //                            numPointsIncluded++;
        //                        }
        //                        i++;
        //                    }
        //
        //                    PolynomialLeastSquares2DFitting plsFit = new PolynomialLeastSquares2DFitting(
        //                            leftTiePointsList, rightTiePointsList, 1);
        //
        //                    double rmse = plsFit.getOverallRMSE();
        //                    System.out.println("RMSE: " + rmse + " with " + numPointsIncluded + " points included.");
        //
        //                    flag = false;
        //                    residuals = plsFit.getResidualsXY();
        //                    residualsOrientation = plsFit.getResidualsOrientation();
        //                    if (rmse > maxAllowableRMSE) {
        //                        i = 0;
        //                        for (k = 0; k < numTiePoints; k++) {
        //                            if (!removeTiePoint[k]) {
        //                                if (residuals[i] > 3 * rmse) {
        //                                    removeTiePoint[k] = true;
        //                                    flag = true;
        //                                }
        //                                i++;
        //                            }
        //                        }
        //                    }
        //                } while (flag);
        //
        //                i = 0;
        //                for (k = 0; k < numTiePoints; k++) {
        //                    if (!removeTiePoint[k]) {
        //                        i++;
        //                    }
        //                }
        System.out.println(numPoints + " tie points remain.");

        System.out.println("Outputing tie point files...");

        ShapeFile leftOutput = new ShapeFile(leftOutputHeader, ShapeType.POINT, fields);

        ShapeFile rightOutput = new ShapeFile(rightOutputHeader, ShapeType.POINT, fields);

        i = 0;
        k = 0;
        for (SURFInterestPoint point : matchingPoints.keySet()) {
            //                    if (i < numTiePoints && !removeTiePoint[i]) {
            x = leftImage.getXCoordinateFromColumn((int) point.getX());
            y = leftImage.getYCoordinateFromRow((int) point.getY());

            SURFInterestPoint target = matchingPoints.get(point);
            x2 = rightImage.getXCoordinateFromColumn((int) target.getX());
            y2 = rightImage.getYCoordinateFromRow((int) target.getY());

            outputPoint = new whitebox.geospatialfiles.shapefile.Point(x, y);
            rowData = new Object[5];
            rowData[0] = new Double(k + 1);
            rowData[1] = new Double(point.getOrientation());
            rowData[2] = new Double(point.getScale());
            rowData[3] = new Double(point.getLaplacian());
            rowData[4] = new Double(0); //residuals[k]);
            leftOutput.addRecord(outputPoint, rowData);

            outputPoint = new whitebox.geospatialfiles.shapefile.Point(x2, y2);
            rowData = new Object[5];
            rowData[0] = new Double(k + 1);
            rowData[1] = new Double(target.getOrientation());
            rowData[2] = new Double(target.getScale());
            rowData[3] = new Double(target.getLaplacian());
            rowData[4] = new Double(0); //residuals[k]);
            rightOutput.addRecord(outputPoint, rowData);

            k++;
            //                    }
            i++;
        }

        leftOutput.write();
        rightOutput.write();

        System.out.println("Done!");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Pruning.Experiments.KendallsCorrelation.java

/**
 * Computes the Kendall's Tau rank correlation matrix for the columns of
 * the input matrix.//  ww  w  .  ja  v  a  2s  . c o m
 *
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(final RealMatrix matrix) {
    int nVars = matrix.getColumnDimension();
    RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars);
    for (int i = 0; i < nVars; i++) {
        for (int j = 0; j < i; j++) {
            double corr = correlation(matrix.getColumn(i), matrix.getColumn(j), matrix.getColumn(i).length);
            outMatrix.setEntry(i, j, corr);
            outMatrix.setEntry(j, i, corr);
        }
        outMatrix.setEntry(i, i, 1d);
    }
    return outMatrix;
}

From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java

/**
 * Copies a column from m1 to m2./* w w w .ja v a2s. c  om*/
 *
 * @param m1   Source matrix.
 * @param col1 Source column.
 * @param m2   Target matrix.
 * @param col2 Target column.
 */
private static void copyColumn(final RealMatrix m1, int col1, RealMatrix m2, int col2) {
    for (int i = 0; i < m1.getRowDimension(); i++) {
        m2.setEntry(i, col2, m1.getEntry(i, col1));
    }
}

From source file:RBFNN.MainFrame.java

public static int[] compare(RealMatrix YactM, RealMatrix YexpM) {
    int[] confusion = new int[4];
    int len = YactM.getRowDimension();
    for (int i = 0; i < len; i++) {//classify the result into the category 
        if (YactM.getEntry(i, 0) > 0.5)
            YactM.setEntry(i, 0, 1);
        else// w w w. j a v a2 s .c o  m
            YactM.setEntry(i, 0, 0);
        if (YactM.getEntry(i, 0) == 1 && YexpM.getEntry(i, 0) == 1)
            confusion[0]++;
        if (YactM.getEntry(i, 0) == 1 && YexpM.getEntry(i, 0) == 0)
            confusion[1]++;
        if (YactM.getEntry(i, 0) == 0 && YexpM.getEntry(i, 0) == 1)
            confusion[2]++;
        if (YactM.getEntry(i, 0) == 0 && YexpM.getEntry(i, 0) == 0)
            confusion[3]++;
    }
    return confusion;
}

From source file:rcdemo.math.ClosedHermiteSpline.java

public static RealMatrix generate(RealVector p) {
    int n = p.getDimension();
    RealMatrix A = MatrixUtils.createRealMatrix(n, n);
    RealMatrix B = MatrixUtils.createRealMatrix(n, n);
    for (int i = 0; i < n; i++) {
        int ip = (i + 1) % n;
        int im = (i - 1 + n) % n;
        A.setEntry(i, im, 2);
        A.setEntry(i, i, 8);/*from ww w.j a  v a  2  s . com*/
        A.setEntry(i, ip, 2);
        B.setEntry(i, im, -6);
        B.setEntry(i, ip, 6);
    }
    RealVector Bp = B.operate(p);
    DecompositionSolver solver = new CholeskyDecomposition(A).getSolver();
    RealVector m = solver.solve(Bp);
    RealMatrix a = MatrixUtils.createRealMatrix(4, n);
    for (int i = 0; i < n; i++) {
        int ip = (i + 1) % n;
        a.setEntry(0, i, p.getEntry(i));
        a.setEntry(1, i, m.getEntry(i));
        a.setEntry(2, i, p.getEntry(ip));
        a.setEntry(3, i, m.getEntry(ip));
    }
    return a;
}