Example usage for org.apache.commons.math3.linear Array2DRowRealMatrix addToEntry

List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix addToEntry

Introduction

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

Prototype

@Override
public void addToEntry(final int row, final int column, final double increment) throws OutOfRangeException 

Source Link

Usage

From source file:de.biomedical_imaging.traj.math.RadiusGyrationTensor2D.java

/**
 * Calculates the radius of gyration tensor according to formula (6.3) in
 * //from www.ja v a 2  s .c  o m
 * ELEMENTS OF THE RANDOM WALK by Rudnick and Gaspari
 * 
 * @return Radius of gyration tensor
 */
public static Array2DRowRealMatrix getRadiusOfGyrationTensor(Trajectory t) {
    double meanx = 0;
    double meany = 0;
    for (int i = 0; i < t.size(); i++) {
        meanx += t.get(i).x;
        meany += t.get(i).y;
    }
    meanx = meanx / t.size();
    meany = meany / t.size();

    double e11 = 0;
    double e12 = 0;
    double e21 = 0;
    double e22 = 0;

    for (int i = 0; i < t.size(); i++) {
        e11 += Math.pow(t.get(i).x - meanx, 2);
        e12 += (t.get(i).x - meanx) * (t.get(i).y - meany);
        e22 += Math.pow(t.get(i).y - meany, 2);
    }
    e11 = e11 / t.size();
    e12 = e12 / t.size();
    e21 = e12;
    e22 = e22 / t.size();
    int rows = 2;
    int columns = 2;
    Array2DRowRealMatrix gyr = new Array2DRowRealMatrix(rows, columns);

    gyr.addToEntry(0, 0, e11);
    gyr.addToEntry(0, 1, e12);
    gyr.addToEntry(1, 0, e21);
    gyr.addToEntry(1, 1, e22);

    return gyr;
}

From source file:outlineDescriptor.Transform.java

private Array2DRowRealMatrix simpleHoughTransform(Array2DRowRealMatrix inputMatrix, int aSteps, double step) {

    double xMax = StatUtils.max(inputMatrix.getColumn(0));
    double yMax = StatUtils.max(inputMatrix.getColumn(1));

    int maxDst = (int) Math.sqrt(xMax * xMax + yMax * yMax);

    Array2DRowRealMatrix angleOffset = new Array2DRowRealMatrix(2 * maxDst + 1, aSteps);

    //calculating all possible line/distance pairs for each point
    for (int i = 0; i < aSteps; i++) {
        double angle = i * step;

        double xc = Math.cos(Math.PI / 2 - angle);
        double yc = Math.sin(Math.PI / 2 - angle);

        for (int row = 0; row < inputMatrix.getRowDimension(); row++) {

            if (inputMatrix.getEntry(row, 2) == 0)
                continue;

            int distance = (int) (xc * inputMatrix.getEntry(row, 0) + yc * inputMatrix.getEntry(row, 1));

            distance += maxDst;// w  w  w . j a v a  2s.  c om
            angleOffset.addToEntry(distance, i, inputMatrix.getEntry(row, 2));
        }
    }

    return angleOffset;
}