package svd;
import cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D;
public class SVDDemo {
public static void main(String[] args) {
double[][] da = new double[][]{{3,2,2},{2,3,-2}};
SVDResults svdr = SVDWrapper.denseSVD(da, 3);
output(svdr);
SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(3, 2);
matrix.set(0, 0, 1);
matrix.set(0, 1, -1);
matrix.set(1, 0, 1);
matrix.set(1, 1, -1);
matrix.set(2, 0, Math.sqrt(3));
matrix.set(2, 1, 0);
SVDResults svdr2 = SVDWrapper.sparseSVD(matrix, 3);
output(svdr2);
}
private static void output(SVDResults svdr) {
System.out.println("Ut");
for(double[] row: svdr.Ut)
{
for(double col: row)
System.out.print(col + "\t");
System.out.println();
}
System.out.println("s");
for(double row: svdr.S)
System.out.println(row);
System.out.println("Vt");
for(double[] row: svdr.Vt)
{
for(double col: row)
System.out.print(col + "\t");
System.out.println();
}
}
}