/** test matrices values */ @Test public void testMatricesValues1() { SingularValueDecomposition svd = new SingularValueDecomposition(new DenseMatrix(testSquare)); Matrix uRef = new DenseMatrix(new double[][] { { 3.0 / 5.0, 4.0 / 5.0 }, { 4.0 / 5.0, -3.0 / 5.0 } }); Matrix sRef = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 0.0, 1.0 } }); Matrix vRef = new DenseMatrix(new double[][] { { 4.0 / 5.0, -3.0 / 5.0 }, { 3.0 / 5.0, 4.0 / 5.0 } }); // check values against known references Matrix u = svd.getU(); assertEquals(0, Algebra.getNorm(u.minus(uRef)), NORM_TOLERANCE); Matrix s = svd.getS(); assertEquals(0, Algebra.getNorm(s.minus(sRef)), NORM_TOLERANCE); Matrix v = svd.getV(); assertEquals(0, Algebra.getNorm(v.minus(vRef)), NORM_TOLERANCE); }
public static void checkOrthogonal(Matrix m) { Matrix mTm = m.transpose().times(m); Matrix id = new DenseMatrix(mTm.numRows(),mTm.numRows()); for (int i = 0; i < mTm.numRows(); i++) { id.set(i, i, 1); } assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE); }
double norm = Algebra.getNorm(u.times(s).times(v.transpose()).minus(matrix)); assertEquals(0, norm, NORM_TOLERANCE);
/** test matrices values */ @Test public void testMatricesValues1() { SingularValueDecomposition svd = new SingularValueDecomposition(new DenseMatrix(testSquare)); Matrix uRef = new DenseMatrix(new double[][] { { 3.0 / 5.0, 4.0 / 5.0 }, { 4.0 / 5.0, -3.0 / 5.0 } }); Matrix sRef = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 0.0, 1.0 } }); Matrix vRef = new DenseMatrix(new double[][] { { 4.0 / 5.0, -3.0 / 5.0 }, { 3.0 / 5.0, 4.0 / 5.0 } }); // check values against known references Matrix u = svd.getU(); assertEquals(0, Algebra.getNorm(u.minus(uRef)), NORM_TOLERANCE); Matrix s = svd.getS(); assertEquals(0, Algebra.getNorm(s.minus(sRef)), NORM_TOLERANCE); Matrix v = svd.getV(); assertEquals(0, Algebra.getNorm(v.minus(vRef)), NORM_TOLERANCE); }
public static void checkOrthogonal(Matrix m) { Matrix mTm = m.transpose().times(m); Matrix id = new DenseMatrix(mTm.numRows(),mTm.numRows()); for (int i = 0; i < mTm.numRows(); i++) { id.set(i, i, 1); } assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE); }
double norm = Algebra.getNorm(u.times(s).times(v.transpose()).minus(matrix)); assertEquals(0, norm, NORM_TOLERANCE);