nr
Class SingularValueDecomposition

java.lang.Object
  extended by nr.SingularValueDecomposition
All Implemented Interfaces:
MatDecomposition

public class SingularValueDecomposition
extends java.lang.Object
implements MatDecomposition

Singular Value Decomposition. Copied from the jama package from the NIST, but using nr.Mat and limited to square matrices

For an n-by-n matrix A, the singular value decomposition is an n-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and an n-by-n orthogonal matrix V so that A*V = U*S.
Solving A*x = b for vectors x and b is x = V*(1/S)*U'*b, where U' is the transform (=the inverse; it's orthogonal) of U and 1/S is the diagonal matrix with elements 1/S[i][i].
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.
Since this was developed by the US government, it is in the public domain.


Constructor Summary
SingularValueDecomposition(Mat Arg)
          Construct the singular value decomposition
 
Method Summary
 double cond()
          Two norm condition number
 Mat getS()
          Return the diagonal matrix of singular values
 double[] getSingularValues()
          Return the one-dimensional array of singular values
 Mat getU()
          Return the left singular vectors
 Mat getV()
          Return the right singular vectors
static double hypot(double a, double b)
          Utility function to determine the hypotenuse function without over/under flow.
 Mat inverse()
           
 double norm2()
          Two norm
 int rank()
          Effective numerical matrix rank
 Vec solve(Vec B)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingularValueDecomposition

public SingularValueDecomposition(Mat Arg)
Construct the singular value decomposition

Parameters:
Arg - a square matrix
Method Detail

solve

public Vec solve(Vec B)
Specified by:
solve in interface MatDecomposition

inverse

public Mat inverse()
Specified by:
inverse in interface MatDecomposition

getU

public Mat getU()
Return the left singular vectors

Returns:
U. Note: this returns the actual matrix, so if it is modified, the SVD is no longer valid

getV

public Mat getV()
Return the right singular vectors

Returns:
V. Note: this returns the actual matrix, so if it is modified, the SVD is no longer valid

getSingularValues

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

Returns:
diagonal of S. Note: this returns the actual array used internally, so the values may be edited

getS

public Mat getS()
Return the diagonal matrix of singular values

Returns:
S (a copy of the singular value matrix

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.

hypot

public static double hypot(double a,
                           double b)
Utility function to determine the hypotenuse function without over/under flow.

Parameters:
a - a number
b - another number
Returns:
sqrt (a^2 + b^2)