MATLAB's svd() function computes the singular value decomposition, with
orthogonal matrices U and V. Mahout computes a singular value
factorization, which does not contain the subspaces that do not contribute
to the data matrix. Compare against
svd(x,0) instead. Also, watch out for transposes.
On Jun 13, 2014 3:10 AM, "Han Fan" <[email protected]> wrote:
>
> import org.apache.mahout.math.DenseMatrix;
> import org.apache.mahout.math.Matrix;
> import org.apache.mahout.math.SingularValueDecomposition;
>
> public class testMPInverse {
> public void test() {
> Matrix matrix = new DenseMatrix(new double[][] {
> {1,2},
> {3,4},
> {5,6}
> });
> SingularValueDecomposition svd = new
> SingularValueDecomposition(matrix);
> Matrix u = svd.getU();
> Matrix v = svd.getV();
> Matrix s = svd.getS();
> System.out.println(u);
> System.out.println(v);
> System.out.println(s);
> }
>
> public static void main(String[] args) {
> testMPInverse t = new testMPInverse();
> t.test();
> }
> }
>
> v is
>
> {
> 0 => {0:0.42866713354862623,1:-0.8059639085892977}
> 1 => {0:0.5663069188480352,1:-0.1123824140965937}
> 2 => {0:0.7039467041474443,1:0.5811990803961101}
> }
>
> MATLAB gives a different answer
>
> x=[1,2,3;4,5,6];
> [u s v]=svd(x);
> v
> v =
>
> -0.4287 0.8060 0.4082
> -0.5663 0.1124 -0.8165
> -0.7039 -0.5812 0.4082
>
> Why the last column of v produced by Mahout SingularValueDecomposition is
> 0?
>
> Thanks for your time.
>
>