Search in sources :

Example 56 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project systemml by apache.

the class LibCommonsMath method computeQR.

/**
 * Function to perform QR decomposition on a given matrix.
 *
 * @param in matrix object
 * @return array of matrix blocks
 */
private static MatrixBlock[] computeQR(MatrixObject in) {
    Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in);
    // Perform QR decomposition
    QRDecomposition qrdecompose = new QRDecomposition(matrixInput);
    RealMatrix H = qrdecompose.getH();
    RealMatrix R = qrdecompose.getR();
    // Read the results into native format
    MatrixBlock mbH = DataConverter.convertToMatrixBlock(H.getData());
    MatrixBlock mbR = DataConverter.convertToMatrixBlock(R.getData());
    return new MatrixBlock[] { mbH, mbR };
}
Also used : QRDecomposition(org.apache.commons.math3.linear.QRDecomposition) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 57 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project systemml by apache.

the class LibCommonsMath method computeCholesky.

/**
 * Function to compute Cholesky decomposition of the given input matrix.
 * The input must be a real symmetric positive-definite matrix.
 *
 * @param in commons-math3 Array2DRowRealMatrix
 * @return matrix block
 */
private static MatrixBlock computeCholesky(Array2DRowRealMatrix in) {
    if (!in.isSquare())
        throw new DMLRuntimeException("Input to cholesky() must be square matrix -- given: a " + in.getRowDimension() + "x" + in.getColumnDimension() + " matrix.");
    CholeskyDecomposition cholesky = new CholeskyDecomposition(in, 1e-14, CholeskyDecomposition.DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD);
    RealMatrix rmL = cholesky.getL();
    return DataConverter.convertToMatrixBlock(rmL.getData());
}
Also used : CholeskyDecomposition(org.apache.commons.math3.linear.CholeskyDecomposition) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 58 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project FSensor by KalebKE.

the class CalibrationUtil method getCalibration.

/**
 * Transforms the ellipsoid into a sphere with the offset vector = [0,0,0]
 * and the radii vector = [1,1,1].
 *
 * @param fitPoints the representation of the calibration ellipsoid
 */
public static Calibration getCalibration(FitPoints fitPoints) {
    // The scalar values to transform the radii vector into [1,1,1]
    RealMatrix scalar = new Array2DRowRealMatrix(3, 3);
    // RIV determines the magnitude of the radii. We have to know the
    // magnitudes because the eigenvalues, and thus the radii, are returned
    // in ascending order. Without knowing the magnitudes, we wouldn't know
    // what radii to apply to what axis.
    // Find the max and minimum magnitudes.
    double max = fitPoints.riv.getEntry(0);
    double min = fitPoints.riv.getEntry(0);
    // The indexes of the maximum, median, and minimum radii.
    // Note that these are the opposite of the max and min
    // because a smaller riv value means a greater magnitude.
    int maxi = 0, midi = 0, mini = 0;
    // Find max and min radii
    for (int i = 0; i < fitPoints.riv.getDimension(); i++) {
        if (fitPoints.riv.getEntry(i) > max) {
            max = fitPoints.riv.getEntry(i);
            mini = i;
        }
        if (fitPoints.riv.getEntry(i) < min) {
            min = fitPoints.riv.getEntry(i);
            maxi = i;
        }
    }
    // Find median radii
    for (int i = 0; i < fitPoints.riv.getDimension(); i++) {
        if (fitPoints.riv.getEntry(i) < max && fitPoints.riv.getEntry(i) > min) {
            midi = i;
        }
    }
    // Create the scalar vector in the correct orientation.
    scalar.setEntry(0, 0, 1 / fitPoints.radii.getEntry(mini));
    scalar.setEntry(1, 1, 1 / fitPoints.radii.getEntry(midi));
    scalar.setEntry(2, 2, 1 / fitPoints.radii.getEntry(maxi));
    return new Calibration(scalar, fitPoints.center);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Example 59 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project FSensor by KalebKE.

the class FitPoints method formAlgebraicMatrix.

/**
 * Create a matrix in the algebraic form of the polynomial Ax^2 + By^2 +
 * Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1.
 *
 * @param v the vector polynomial.
 * @return the matrix of the algebraic form of the polynomial.
 */
private RealMatrix formAlgebraicMatrix(RealVector v) {
    // a =
    // [ Ax^2 2Dxy 2Exz 2Gx ]
    // [ 2Dxy By^2 2Fyz 2Hy ]
    // [ 2Exz 2Fyz Cz^2 2Iz ]
    // [ 2Gx 2Hy 2Iz -1 ] ]
    RealMatrix a = new Array2DRowRealMatrix(4, 4);
    a.setEntry(0, 0, v.getEntry(0));
    a.setEntry(0, 1, v.getEntry(3));
    a.setEntry(0, 2, v.getEntry(4));
    a.setEntry(0, 3, v.getEntry(6));
    a.setEntry(1, 0, v.getEntry(3));
    a.setEntry(1, 1, v.getEntry(1));
    a.setEntry(1, 2, v.getEntry(5));
    a.setEntry(1, 3, v.getEntry(7));
    a.setEntry(2, 0, v.getEntry(4));
    a.setEntry(2, 1, v.getEntry(5));
    a.setEntry(2, 2, v.getEntry(2));
    a.setEntry(2, 3, v.getEntry(8));
    a.setEntry(3, 0, v.getEntry(6));
    a.setEntry(3, 1, v.getEntry(7));
    a.setEntry(3, 2, v.getEntry(8));
    a.setEntry(3, 3, -1);
    return a;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Example 60 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project FSensor by KalebKE.

the class FitPoints method translateToCenter.

/**
 * Translate the algebraic form of the ellipsoid to the offset.
 *
 * @param center vector containing the offset of the ellipsoid.
 * @param a      the algebraic form of the polynomial.
 * @return the offset translated form of the algebraic ellipsoid.
 */
private RealMatrix translateToCenter(RealVector center, RealMatrix a) {
    // Form the corresponding translation matrix.
    RealMatrix t = MatrixUtils.createRealIdentityMatrix(4);
    RealMatrix centerMatrix = new Array2DRowRealMatrix(1, 3);
    centerMatrix.setRowVector(0, center);
    t.setSubMatrix(centerMatrix.getData(), 3, 0);
    // Translate to the offset.
    RealMatrix r = t.multiply(a).multiply(t.transpose());
    return r;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Aggregations

Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)141 RealMatrix (org.apache.commons.math3.linear.RealMatrix)101 Test (org.testng.annotations.Test)60 IntStream (java.util.stream.IntStream)31 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)28 File (java.io.File)27 Collectors (java.util.stream.Collectors)25 ArrayList (java.util.ArrayList)24 Assert (org.testng.Assert)24 List (java.util.List)22 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)22 Target (org.broadinstitute.hellbender.tools.exome.Target)18 java.util (java.util)15 Random (java.util.Random)14 ReadCountCollection (org.broadinstitute.hellbender.tools.exome.ReadCountCollection)14 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)14 DataProvider (org.testng.annotations.DataProvider)14 Stream (java.util.stream.Stream)13 Arrays (java.util.Arrays)12 DoubleStream (java.util.stream.DoubleStream)12