Example usage for org.apache.mahout.math SingularValueDecomposition SingularValueDecomposition

List of usage examples for org.apache.mahout.math SingularValueDecomposition SingularValueDecomposition

Introduction

In this page you can find the example usage for org.apache.mahout.math SingularValueDecomposition SingularValueDecomposition.

Prototype

public SingularValueDecomposition(Matrix arg) 

Source Link

Document

Constructs and returns a new singular value decomposition object; The decomposed matrices can be retrieved via instance methods of the returned decomposition object.

Usage

From source file:org.carrot2.matrix.factorization.PartialSingularValueDecomposition.java

License:Open Source License

public void compute() {
    // Use Colt's SVD
    SingularValueDecomposition svd;//from   w ww.j  a v  a2  s . c  o m
    if (A.columns() > A.rows()) {
        svd = new SingularValueDecomposition(new DenseMatrix(A.viewDice().toArray()));
        V = toColtMatrix(svd.getU());
        U = toColtMatrix(svd.getV());
    } else {
        svd = new SingularValueDecomposition(new DenseMatrix(A.toArray()));
        U = toColtMatrix(svd.getU());
        V = toColtMatrix(svd.getV());
    }

    S = svd.getSingularValues();

    if (k > 0 && k < S.length) {
        U = U.viewPart(0, 0, U.rows(), k);
        V = V.viewPart(0, 0, V.rows(), k);
        S = Arrays.copyOf(S, k);
    }
}