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

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

Introduction

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

Prototype

@Override
public void setEntry(final int row, final int column, final double value) throws OutOfRangeException 

Source Link

Usage

From source file:outlineDescriptor.ODUtils.java

/**
 * Generates a 2D covariance matrix for a distribution function
 *
 * @param vX  X component//from   w  w  w.  ja va2 s .  com
 * @param vY  Y component
 * @param eV1 First eigenvalue
 * @param eV2 Second eigenvalue
 *
 * @return Resulting covariance matrix
 */
public static Array2DRowRealMatrix getDistributionCovMatrix(double vX, double vY, double eV1, double eV2) {

    double multiplier = 1 / (vX * vX + vY * vY);

    Array2DRowRealMatrix vectMat = new Array2DRowRealMatrix(2, 2);

    Array2DRowRealMatrix valMat = new Array2DRowRealMatrix(2, 2);

    valMat.setEntry(0, 0, eV1);
    valMat.setEntry(1, 1, eV2);

    vectMat.setEntry(0, 0, vX);
    vectMat.setEntry(0, 1, vY);

    vectMat.setEntry(1, 0, -vY);
    vectMat.setEntry(1, 1, vX);

    Array2DRowRealMatrix vE = vectMat.multiply(valMat);
    Array2DRowRealMatrix tempCov = vE.multiply((Array2DRowRealMatrix) vectMat.transpose());

    return (Array2DRowRealMatrix) tempCov.scalarMultiply(multiplier);

}

From source file:outlineDescriptor.Transform.java

private Array2DRowRealMatrix createSVDmatrix(Array2DRowRealMatrix angleOffset, int aSteps, double step) {

    Array2DRowRealMatrix output = new Array2DRowRealMatrix(2 * aSteps, 2);

    for (int i = 0; i < aSteps; i++) {

        double angle = Math.PI - i * step;

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

            angleOffset.multiplyEntry(row, i, angleOffset.getEntry(row, i));
        }//from   ww w .j a v a2 s  .  c om

        double stdDev = getDeviance(angleOffset.getColumn(i));
        // new StandardDeviation().evaluate(angleOffset.getColumn(i));

        double outX = Math.cos(angle) * stdDev;
        double outY = Math.sin(angle) * stdDev;

        output.setEntry(i, 0, outX);
        output.setEntry(i, 1, outY);

        output.setEntry(i + aSteps, 0, -outX);
        output.setEntry(i + aSteps, 1, -outY);

    }

    return output;

}

From source file:outlineDescriptor.Transform.java

private Array2DRowRealMatrix transform(Array2DRowRealMatrix rm, int aSteps) {
    double meanX = StatUtils.mean(rm.getColumn(0));
    double meanY = StatUtils.mean(rm.getColumn(1));
    double step = Math.PI / aSteps;
    Array2DRowRealMatrix output;//w  ww  . j  ava  2  s. com

    for (int i = 0; i < rm.getRowDimension(); i++) {
        rm.setEntry(i, 0, rm.getEntry(i, 0) - meanX);
        rm.setEntry(i, 1, rm.getEntry(i, 1) - meanY);
    }

    Array2DRowRealMatrix angleOffset = simpleHoughTransform(rm, aSteps, step);

    output = createSVDmatrix(angleOffset, aSteps, step);

    return output;
}

From source file:uk.ac.diamond.scisoft.analysis.fitting.functions.GaussianND.java

private void calcCachedParameters() {
    if (pos == null || pos.length != rank) {
        pos = new double[rank];
    }//from w  ww .  ja v  a2  s  . com
    int n = 0;
    for (int i = 0; i < rank; i++) {
        pos[i] = getParameterValue(n);
        n++;
    }
    //      logger.info("New pos at {}", pos);
    norm = getParameterValue(n);
    n++;
    if (rank == 0)
        return;
    Array2DRowRealMatrix covar = (Array2DRowRealMatrix) MatrixUtils.createRealMatrix(rank, rank);
    for (int i = 0; i < rank; i++) {
        covar.setEntry(i, i, getParameterValue(n));
        n++;
    }
    for (int i = 0; i < rank; i++) {
        double diagi = Math.sqrt(covar.getEntry(i, i));
        for (int j = i + 1; j < rank; j++) {
            double diag = Math.sqrt(covar.getEntry(j, j)) * diagi;
            double el = diag * getParameterValue(n);
            covar.setEntry(i, j, el);
            covar.setEntry(j, i, el);
            n++;
        }
    }
    //      logger.info("New cov {}", covar);
    LUDecomposition decomp = null;
    try {
        decomp = new LUDecomposition(covar);
    } catch (NonSquareMatrixException e) {
        logger.error("Non-square covariance matrix");
        throw new IllegalArgumentException("Non-square covariance matrix");
    }

    invcov = (Array2DRowRealMatrix) decomp.getSolver().getInverse();
    //      logger.info("Inverse covariance matrix is {}", invcov);
    norm /= Math.sqrt(Math.pow(2. * Math.PI, rank) * decomp.getDeterminant());
    //      logger.info("Normalization factor is {}", norm);

    setDirty(false);
}