Exemplo n.º 1
0
  @Test
  public void testSVD() {

    AMatrix a = Matrixx.createRandomMatrix(5, 3);
    AMatrix[] ms = ThinSVD.decompose(a);

    AMatrix u = ms[0];
    AMatrix s = ms[1];
    AMatrix v = ms[2];

    // we are testing that A = USV*
    AMatrix usvt = u.innerProduct(s.innerProduct(v.getTranspose()));
    // assertEquals(a,usvt);
    assertTrue(usvt.epsilonEquals(a));

    assertTrue(v.isOrthogonal());
    assertTrue(s.isRectangularDiagonal());
    assertTrue(u.hasOrthonormalColumns());
  }
Exemplo n.º 2
0
  @Test
  public void testQR() {

    AMatrix a = Matrixx.createRandomMatrix(5, 4);
    AMatrix[] ms = QR.decompose(a);

    AMatrix q = ms[0];
    AMatrix r = ms[1];

    // we are testing that A = QR
    assertTrue(q.innerProduct(r).epsilonEquals(a));

    // check properties of Q - should be orthogonal
    assertTrue(q.hasOrthonormalColumns());
    // assertTrue(q.isSquare()); // TODO: should be square??

    // check properties of R - should be upper triangular
    assertTrue(r.isUpperTriangular());
  }