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 matrix U should not be computed.
|
static int |
OMIT_UV
Specifies that neither matrix U nor matrix V should not be computed.
|
static int |
OMIT_V
Specifies that matrix V should not be computed.
|
Constructor and Description |
---|
SVDecomposition()
Creates an uninitialized SVDecomposition.
|
SVDecomposition(Matrix M)
Creates an SVDecomposition and initializes it to the SVD for the matrix
M.
|
SVDecomposition(Matrix M,
int flags)
Creates an SVDecomposition 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.
|
static SVDecomposition |
factor(DenseMatrix U,
Vector svec,
DenseMatrix V,
Matrix M)
Convenience method that creates an SVDecomposition, factors it for the
matrix M, and stores the resulting U, S and V values into the
corresponding arguments.
|
void |
factor(Matrix M)
Peforms an SVD on the Matrix M.
|
void |
factor(Matrix M,
int flags)
Peforms an SVD on the Matrix M.
|
void |
get(DenseMatrix U,
Vector svec,
DenseMatrix V)
Gets the matrices associated with the SVD.
|
int |
getIterationLimit()
Gets the iteration limit for SVD computations.
|
VectorNd |
getS()
Returns the current singular values associated with this
decomposition.
|
MatrixNd |
getU()
Returns the current U matrix associated with this decomposition.
|
MatrixNd |
getV()
Returns the current V matrix associated with this decomposition.
|
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(DenseMatrix R)
Computes the psuedo inverse of the original matrix M associated this SVD,
and places the result in R.
|
boolean |
pseudoInverse(MatrixNd R)
Computes the psuedo inverse of the original matrix M associated this SVD,
and places the result in R.
|
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 OMIT_UV
public static final int DEFAULT_ITERATION_LIMIT
public SVDecomposition(Matrix M)
M
- matrix to perform the SVD onpublic SVDecomposition(Matrix M, int flags)
OMIT_U
and/or OMIT_V
.M
- matrix to perform the SVD onflags
- flags controlling the factorizationpublic SVDecomposition()
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 factor(Matrix M, int flags)
OMIT_U
and/or OMIT_V
.M
- matrix to perform the SVD onflags
- controlling the factorization.public void get(DenseMatrix U, Vector svec, DenseMatrix V)
U
- If not null
, returns the left-hand orthogonal matrixsvec
- If not null
, returns the diagonal elements of SV
- If not null
, returns the right-hand orthogonal matrix
(note that this is V, and not it's transpose V^T).ImproperStateException
- if this SVDecomposition is uninitialized, or if either U or V are requested
but were not computedImproperSizeException
- if U, svec, or V are not of the proper dimension and cannot be resized.public MatrixNd getU()
null
. Subsequent factorizations will
cause a different U to be created. The returned matrix should not be
modified if any subsequent calls are to be made which depend on U
(including solve and inverse methods).ImproperStateException
- if this SVDecomposition is uninitializedpublic MatrixNd getV()
null
. Subsequent factorizations will
cause a different V to be created. The returned matrix should not be
modified if any subsequent calls are to be made which depend on V
(including solve and inverse methods).ImproperStateException
- if this SVDecomposition is uninitializedpublic VectorNd getS()
ImproperStateException
- if this SVDecomposition is uninitializedpublic static SVDecomposition factor(DenseMatrix U, Vector svec, DenseMatrix V, Matrix M)
null
, then U and/or V will not be computed.U
- If not null
, returns the left-hand orthogonal matrixsvec
- If not null
, returns the diagonal elements of SV
- If not null
, returns the right-hand orthogonal matrix
(note that this is V, and not it's transpose V^T).M
- matrix to be factoredpublic 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 uninitialized, or if U or V were not computedImproperSizeException
- 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 uninitialized, or if U or V were not computedImproperSizeException
- 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 uninitialized, or if U or V were not computedImproperSizeException
- 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 uninitialized, or if U or V were not computedImproperSizeException
- if M is not square, or if R does not have the same size as M and cannot be
resized.public boolean pseudoInverse(DenseMatrix R)
R
- matrix in which the inverse is storedImproperStateException
- if this decomposition is uninitialized, or if U or V were not computedImproperSizeException
- if M is not square, or if R does not have the same size as M and cannot be
resized.