use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk-protected by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowSum.
@Test
public void testRowSum() {
final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] guess = GATKProtectedMathUtils.rowSums(new Array2DRowRealMatrix(array));
final double[] gt = { 6, 15, 24, -1 };
Assert.assertEquals(guess.length, 4);
Assert.assertEquals(guess, gt);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk-protected by broadinstitute.
the class MatrixSummaryUtilsUnitTest method testGetRowVariances.
@Test(dataProvider = "rowVarianceTestData")
public void testGetRowVariances(double[][] testdata, double[] gtRowVariances) {
final RealMatrix tmp = new Array2DRowRealMatrix(testdata);
PoNTestUtils.assertEqualsDoubleArrays(MatrixSummaryUtils.getRowVariances(tmp), gtRowVariances);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk-protected by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowStdDevs.
@Test
public void testRowStdDevs() {
final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] rowStdDevs = GATKProtectedMathUtils.rowStdDevs(new Array2DRowRealMatrix(array));
Assert.assertEquals(rowStdDevs[0], 1, 1e-8);
Assert.assertEquals(rowStdDevs[1], 0, 1e-8);
Assert.assertEquals(rowStdDevs[2], 1, 1e-8);
Assert.assertEquals(rowStdDevs[3], 13.65039682, 1e-8);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk-protected by broadinstitute.
the class GATKProtectedMathUtilsTest method testColumnInf.
@Test
public void testColumnInf() {
final double[][] array = { { 1, 2, Double.POSITIVE_INFINITY }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] guess = GATKProtectedMathUtils.columnSums(new Array2DRowRealMatrix(array));
final double[] gt = { -2, 17, Double.POSITIVE_INFINITY };
Assert.assertEquals(guess.length, 3);
Assert.assertEquals(guess[0], gt[0]);
Assert.assertEquals(guess[1], gt[1]);
Assert.assertTrue(Double.isInfinite(guess[2]));
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project incubator-systemml by apache.
the class LibCommonsMath method computeEigen.
/**
* Function to perform Eigen decomposition on a given matrix.
* Input must be a symmetric matrix.
*
* @param in matrix object
* @return array of matrix blocks
*/
private static MatrixBlock[] computeEigen(MatrixObject in) {
if (in.getNumRows() != in.getNumColumns()) {
throw new DMLRuntimeException("Eigen Decomposition can only be done on a square matrix. Input matrix is rectangular (rows=" + in.getNumRows() + ", cols=" + in.getNumColumns() + ")");
}
Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in);
EigenDecomposition eigendecompose = new EigenDecomposition(matrixInput);
RealMatrix eVectorsMatrix = eigendecompose.getV();
double[][] eVectors = eVectorsMatrix.getData();
double[] eValues = eigendecompose.getRealEigenvalues();
// Sort the eigen values (and vectors) in increasing order (to be compatible w/ LAPACK.DSYEVR())
int n = eValues.length;
for (int i = 0; i < n; i++) {
int k = i;
double p = eValues[i];
for (int j = i + 1; j < n; j++) {
if (eValues[j] < p) {
k = j;
p = eValues[j];
}
}
if (k != i) {
eValues[k] = eValues[i];
eValues[i] = p;
for (int j = 0; j < n; j++) {
p = eVectors[j][i];
eVectors[j][i] = eVectors[j][k];
eVectors[j][k] = p;
}
}
}
MatrixBlock mbValues = DataConverter.convertToMatrixBlock(eValues, true);
MatrixBlock mbVectors = DataConverter.convertToMatrixBlock(eVectors);
return new MatrixBlock[] { mbValues, mbVectors };
}
Aggregations