public class SVDecomposition
extends java.lang.Object
Providing a separate class for the SVD allows an application to perform such decompositions repeatedly without having to reallocate temporary storage space.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_ITERATION_LIMIT
The default iteration limit for computing the SVD.
|
static int |
OMIT_U
Specifies that the matrix U should not be computed.
|
static int |
OMIT_V
Specifies that the matrix V should not be computed.
|
Constructor and Description |
---|
SVDecomposition()
Creates an uninitialized SVDecomposition.
|
SVDecomposition(int flags)
Creates an uninitialized SVDecomposition with the specified computation
flags.
|
SVDecomposition(Matrix M)
Creates an SVDecomposition and initializes it to the SVD for the matrix M.
|
SVDecomposition(Matrix M,
int flags)
Creates an SVDecomposition, sets the computation flags, and initializes it
to the SVD for the matrix M.
|
Modifier and Type | Method and Description |
---|---|
double |
condition()
Computes the condition number of the original matrix M associated with
this SVD.
|
double |
determinant()
Computes the determinant of the original matrix M associated with this
SVD.
|
void |
factor(Matrix M)
Peforms an SVD on the Matrix M.
|
void |
get(DenseMatrix U,
Vector svec,
DenseMatrix V)
Gets the matrices associated with the SVD.
|
VectorNd |
getEigenValues(DenseMatrix U)
Gets the eigen decomposition for the currently factore (symmetric) matrix M:
|
VectorNd |
getEigenValues(DenseMatrix M,
DenseMatrix U)
Factors a matrix M and returns its eigen decomposition:
|
int |
getFlags()
Gets the flags associated with SVD computation.
|
int |
getIterationLimit()
Gets the iteration limit for SVD computations.
|
boolean |
inverse(MatrixNd R)
Computes the inverse of the original matrix M associated this SVD, and
places the result in R.
|
double |
norm()
Computes the 2-norm of the original matrix M associated with this SVD.
|
boolean |
pseudoInverse(MatrixNd R)
Computes the psuedo inverse of the original matrix M associated this SVD,
and places the result in R.
|
void |
setFlags(int flags)
Sets the flags associated with SVD computation.
|
void |
setIterationLimit(int lim)
Sets the iteration limit for SVD computations.
|
boolean |
solve(MatrixNd X,
MatrixNd B)
Solves the linear equation
M X = B where M is the original matrix associated with this SVD, and X and B are matrices. |
boolean |
solve(VectorNd x,
VectorNd b)
Solves the linear equation
M x = b where M is the original matrix associated with this SVD, and x and b are vectors. |
public static final int OMIT_U
public static final int OMIT_V
public static final int DEFAULT_ITERATION_LIMIT
public SVDecomposition(Matrix M)
M
- matrix to perform the SVD onpublic SVDecomposition(Matrix M, int flags)
M
- matrix to perform the SVD onflags
- flags associated with SVD computationsetFlags(int)
public SVDecomposition(int flags)
flags
- flags associated with SVD computationsetFlags(int)
public SVDecomposition()
public void setFlags(int flags)
OMIT_V
and OMIT_U
.flags
- an or-ed combination of flags.getFlags()
public int getFlags()
setFlags(int)
public int getIterationLimit()
setIterationLimit(int)
public void setIterationLimit(int lim)
lim
- iteration limitgetIterationLimit()
public void factor(Matrix M)
M
- matrix to perform the SVD onpublic void get(DenseMatrix U, Vector svec, DenseMatrix V)
U
- left-hand orthogonal matrixsvec
- vector giving the diagonal elements of SV
- right-hand orthogonal matrix (note that this is V, and not it's transpose
V').ImproperStateException
- if this SVDecomposition is uninitializedImproperSizeException
- if U, svec, or V are not of the proper dimension and cannot be resized.public VectorNd getEigenValues(DenseMatrix M, DenseMatrix U)
M = U E U^Twhere U is orthogonal and E is a diagonal matrix of eigenvalues. It is assumed that M is symmetric. If M is not symmetric, then a symmetric matrix is formed from
1/2 (M + M')
M
- matrix to be factoredU
- left-hand orthogonal matrix (optional, may be null)java.lang.IllegalArgumentException
- if M is not squareImproperSizeException
- if U is not of the proper dimension and cannot be resized.public VectorNd getEigenValues(DenseMatrix U)
M = U E U^Twhere U is orthogonal and E is a diagonal matrix of eigenvalues. It is assumed that
factor(M)
was called previously, and
that M is symmetric.U
- left-hand orthogonal matrix (optional, may be null)ImproperStateException
- if this SVDecomposition does not contain a factored matrix, or if
that matrix is not squareImproperSizeException
- if U is not of the proper dimension and cannot be resized.public double condition()
ImproperStateException
- if this SVDecomposition is uninitializedpublic double norm()
ImproperStateException
- if this SVDecomposition is uninitializedpublic double determinant()
ImproperStateException
- if this SVDecomposition is uninitializedpublic boolean solve(VectorNd x, VectorNd b)
x
- unknown vector to solve forb
- constant vectorImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if b does not have a size compatible with M, or if x does not have a size
compatible with M and cannot be resized.public boolean solve(MatrixNd X, MatrixNd B)
X
- unknown matrix to solve forB
- constant matrixImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if B has a different number of rows than M, or if X has a different number
of rows than M or a different number of columns than B and cannot be
resized.public boolean inverse(MatrixNd R)
R
- matrix in which the inverse is storedImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if M is not square, or if R does not have the same size as M and cannot be
resized.public boolean pseudoInverse(MatrixNd R)
R
- matrix in which the inverse is storedImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if M is not square, or if R does not have the same size as M and cannot be
resized.