papaya
Class SVD

java.lang.Object
  extended by papaya.SVD

public class SVD
extends Object

Singular Value Decomposition.

For an m x n matrix A with m > n, the singular value decomposition is an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and an n-by-n orthogonal matrix V so that A = U*S*V'.

The singular values, sigma[k] = S[k][k], are ordered so that sigma[0] > sigma[1] > ... > sigma[n-1].

The singular value decompostion always exists, so the constructor will never fail. The matrix condition number and the effective numerical rank can be computed from this decomposition.

Shamelessly copied (and modified) from the JAMA Java Matrix package. To make things compatible with how most users use Processing, the class take in float matrices. However, to preserve the acccuracy of the computations, the algorithm first casts the input into a double array, prior to doing anything. All methods also return doubles; Use Cast.doubleToFloat(double[][]) if you want/need to cast everything back to floats for further (non-high-accuracy-dependant) processing (pun intended).


Constructor Summary
SVD(float[][] AA)
          Construct the singular value decomposition.
 
Method Summary
 double cond()
          Two norm condition number
 double[][] getS()
          Return the diagonal matrix of singular values
 double[] getSingularValues()
          Return the one-dimensional array of singular values
 double[][] getU()
          Return the left singular vectors
 double[][] getV()
          Return the right singular vectors
 double norm2()
          Two norm
 int rank()
          Effective numerical matrix rank
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVD

public SVD(float[][] AA)
Construct the singular value decomposition. At the end of this call, U, V, and S have been computed.

Parameters:
AA - Rectangular matrix
Method Detail

getU

public double[][] getU()
Return the left singular vectors

Returns:
U

getV

public double[][] getV()
Return the right singular vectors

Returns:
V

getSingularValues

public double[] getSingularValues()
Return the one-dimensional array of singular values

Returns:
diagonal of S.

getS

public double[][] getS()
Return the diagonal matrix of singular values

Returns:
S

norm2

public double norm2()
Two norm

Returns:
max(S)

cond

public double cond()
Two norm condition number

Returns:
max(S)/min(S)

rank

public int rank()
Effective numerical matrix rank

Returns:
Number of nonnegligible singular values.


Processing library papaya by Adila Faruk. (C) 2014