Examples of SingularValueDecomposition


Examples of org.apache.mahout.math.SingularValueDecomposition

    // L L' = B B'
    cd2 = new CholeskyDecomposition(b.times(b.transpose()));

    // U_0 D V_0' = L
    svd = new SingularValueDecomposition(cd2.getL());
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

      throw new CardinalityException(m.numRows(), m.numCols());
    }
    // See http://www.mlahanas.de/Math/svd.htm for details,
    // which specifically details the case of covariance matrix inversion
    // Complexity: O(min(nm2,mn2))
    SingularValueDecomposition svd = new SingularValueDecomposition(m);
    Matrix sInv = svd.getS();
    // Inverse Diagonal Elems
    for (int i = 0; i < sInv.numRows(); i++) {
      double diagElem = sInv.get(i, i);
      if (diagElem > 0.0) {
        sInv.set(i, i, 1 / diagElem);
      } else {
        throw new IllegalStateException("Eigen Value equals to 0 found.");
      }
    }
    inverseCovarianceMatrix = svd.getU().times(sInv.times(svd.getU().transpose()));
    Preconditions.checkArgument(inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

      for (int j = 0; j < n; j++) {
        a[i][j] -= xi.getQuick(j);
      }
    }

    SingularValueDecomposition svd2 =
      new SingularValueDecomposition(new DenseMatrix(a));

    Vector svalues2 = new DenseVector(svd2.getSingularValues());
    LocalSSVDSolverSparseSequentialTest.dumpSv(svalues2);

    for (int i = 0; i < k + p; i++) {
      assertTrue(Math.abs(svalues2.getQuick(i) - stochasticSValues.getQuick(i)) <= s_epsilon);
    }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

    // try to run the same thing without stochastic algo
    double[][] a = SSVDHelper.loadDistributedRowMatrix(fs, aPath, conf);

    // SingularValueDecompositionImpl svd=new SingularValueDecompositionImpl(new
    // Array2DRowRealMatrix(a));
    SingularValueDecomposition svd2 =
      new SingularValueDecomposition(new DenseMatrix(a));

    Vector svalues2 = new DenseVector(svd2.getSingularValues());
    dumpSv(svalues2);

    for (int i = 0; i < k + p; i++) {
      assertTrue(Math.abs(svalues2.getQuick(i) - stochasticSValues.getQuick(i)) <= s_epsilon);
    }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

    });
    // Verify all errors are nearly zero.
    assertEquals(0, columnNorms.norm(1) / columnNorms.size(), 0.1);

    // Verify that the centroids are a permutation of the original ones.
    SingularValueDecomposition svd = new SingularValueDecomposition(x);
    Vector s = svd.getS().viewDiagonal().assign(Functions.div(6));
    assertEquals(5, s.getLengthSquared(), 0.05);
    assertEquals(5, s.norm(1), 0.05);
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

  @Test
  public void testSingularValues() {
    Matrix A = lowRankMatrix();

    SequentialBigSvd s = new SequentialBigSvd(A, 8);
    SingularValueDecomposition svd = new SingularValueDecomposition(A);

    Vector reference = new DenseVector(svd.getSingularValues()).viewPart(0, 8);
    assertEquals(reference, s.getSingularValues());

    assertEquals(A, s.getU().times(new DiagonalMatrix(s.getSingularValues())).times(s.getV().transpose()));
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

  @Test
  public void testLeftVectors() {
    Matrix A = lowRankMatrix();

    SequentialBigSvd s = new SequentialBigSvd(A, 8);
    SingularValueDecomposition svd = new SingularValueDecomposition(A);

    // can only check first few singular vectors because once the singular values
    // go to zero, the singular vectors are not uniquely determined
    Matrix u1 = svd.getU().viewPart(0, 20, 0, 4).assign(Functions.ABS);
    Matrix u2 = s.getU().viewPart(0, 20, 0, 4).assign(Functions.ABS);
    assertEquals(0, u1.minus(u2).aggregate(Functions.PLUS, Functions.ABS), 1.0e-9);
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

  @Test
  public void testRightVectors() {
    Matrix A = lowRankMatrix();

    SequentialBigSvd s = new SequentialBigSvd(A, 6);
    SingularValueDecomposition svd = new SingularValueDecomposition(A);

    Matrix v1 = svd.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
    Matrix v2 = s.getV().viewPart(0, 20, 0, 3).assign(Functions.ABS);
    assertEquals(v1, v2);
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

        b2.assign(bTmp.get().times(bTmp.get().transpose()), Functions.PLUS);
      }
    }
    l2 = new CholeskyDecomposition(b2);
    svd = new SingularValueDecomposition(l2.getL());
  }
View Full Code Here

Examples of org.apache.mahout.math.SingularValueDecomposition

  @Test
  public void testLeftVectors() throws IOException {
    Matrix A = lowRankMatrixInMemory(20, 20);

    SequentialBigSvd s = new SequentialBigSvd(A, 6);
    SingularValueDecomposition svd = new SingularValueDecomposition(A);

    // can only check first few singular vectors
    Matrix u1 = svd.getU().viewPart(0, 20, 0, 3).assign(Functions.ABS);
    Matrix u2 = s.getU().viewPart(0, 20, 0, 3).assign(Functions.ABS);
    assertEquals(u1, u2);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.