The Singular Value Decomposition of matrix A is a set of three matrices: U, Σ and V such that A = U × Σ × VT. Let A be a m × n matrix, then U is a m × p orthogonal matrix, Σ is a p × p diagonal matrix with positive or null elements, V is a p × n orthogonal matrix (hence VT is also orthogonal) where p=min(m,n).
This class is similar to the class with similar name from the JAMA library, with the following changes:
norm2 method which has been renamed as getNorm,cond method which has been renamed as getConditionNumber,rank method which has been renamed as getRank,getUT method has been added,getVT method has been added,getSolver method has been added,getCovariance method has been added.| Modifier and Type | Class and Description |
|---|---|
| private static class | SingularValueDecomposition.
Specialized solver. |
| Modifier and Type | Field and Description |
|---|---|
| private RealMatrix | cachedS
Cached value of S (diagonal) matrix. |
| private final RealMatrix | cachedU
Cached value of U matrix. |
| private RealMatrix | cachedUt
Cached value of transposed U matrix. |
| private final RealMatrix | cachedV
Cached value of V matrix. |
| private RealMatrix | cachedVt
Cached value of transposed V matrix. |
| private static final double | EPS
Relative threshold for small singular values. |
| private final int | m
max(row dimension, column dimension). |
| private final int | n
min(row dimension, column dimension). |
| private final double[] | singularValues
Computed singular values. |
| private static final double | TINY
Absolute threshold for small singular values. |
| private final double | tol
Tolerance value for small singular values, calculated once we have populated "singularValues". |
| private final boolean | transposed
Indicator for transposed matrix. |
| Access | Constructor and Description |
|---|---|
| public | SingularValueDecomposition(final RealMatrix
Matrix to decompose. matrix)Calculates the compact Singular Value Decomposition of the given matrix. |
| Modifier and Type | Method and Description |
|---|---|
| public double | Returns: condition number of the matrixReturn the condition number of the matrix. |
| public RealMatrix | Returns: covariance matrixvalue below which singular values are ignored
(a 0 or negative value implies all singular value will be used) minSingularValue)Returns the n × n covariance matrix. |
| public double | Returns: the inverse of the condition number.Computes the inverse of the condition number. |
| public double | |
| public int | |
| public RealMatrix | |
| public double[] | Returns: the diagonal elements of the Σ matrixReturns the diagonal elements of the matrix Σ of the decomposition. |
| public DecompositionSolver | |
| public RealMatrix | |
| public RealMatrix | Returns: the U matrix (or null if decomposed matrix is singular)Returns the transpose of the matrix U of the decomposition. |
| public RealMatrix | Returns: the V matrix (or null if decomposed matrix is singular)Returns the matrix V of the decomposition. |
| public RealMatrix | Returns: the V matrix (or null if decomposed matrix is singular)Returns the transpose of the matrix V of the decomposition. |
| cachedS | back to summary |
|---|---|
| private RealMatrix cachedS Cached value of S (diagonal) matrix. | |
| cachedU | back to summary |
|---|---|
| private final RealMatrix cachedU Cached value of U matrix. | |
| cachedUt | back to summary |
|---|---|
| private RealMatrix cachedUt Cached value of transposed U matrix. | |
| cachedV | back to summary |
|---|---|
| private final RealMatrix cachedV Cached value of V matrix. | |
| cachedVt | back to summary |
|---|---|
| private RealMatrix cachedVt Cached value of transposed V matrix. | |
| EPS | back to summary |
|---|---|
| private static final double EPS Relative threshold for small singular values. | |
| m | back to summary |
|---|---|
| private final int m max(row dimension, column dimension). | |
| n | back to summary |
|---|---|
| private final int n min(row dimension, column dimension). | |
| singularValues | back to summary |
|---|---|
| private final double[] singularValues Computed singular values. | |
| TINY | back to summary |
|---|---|
| private static final double TINY Absolute threshold for small singular values. | |
| tol | back to summary |
|---|---|
| private final double tol Tolerance value for small singular values, calculated once we have populated "singularValues". | |
| transposed | back to summary |
|---|---|
| private final boolean transposed Indicator for transposed matrix. | |
| SingularValueDecomposition | back to summary |
|---|---|
| public SingularValueDecomposition(final RealMatrix matrix) Calculates the compact Singular Value Decomposition of the given matrix.
| |
| getConditionNumber | back to summary |
|---|---|
| public double getConditionNumber() Return the condition number of the matrix.
| |
| getCovariance | back to summary |
|---|---|
| public RealMatrix getCovariance(final double minSingularValue) Returns the n × n covariance matrix. The covariance matrix is V × J × VT where J is the diagonal matrix of the inverse of the squares of the singular values.
| |
| getInverseConditionNumber | back to summary |
|---|---|
| public double getInverseConditionNumber() Computes the inverse of the condition number.
In cases of rank deficiency, the
| |
| getNorm | back to summary |
|---|---|
| public double getNorm() Returns the L2 norm of the matrix. The L2 norm is max(|A × u|2 / |u|2), where |.|2 denotes the vectorial 2-norm (i.e. the traditional euclidian norm).
| |
| getRank | back to summary |
|---|---|
| public int getRank() Return the effective numerical matrix rank. The effective numerical rank is the number of non-negligible singular values. The threshold used to identify non-negligible terms is max(m,n) × ulp(s1) where ulp(s1) is the least significant bit of the largest singular value.
| |
| getS | back to summary |
|---|---|
| public RealMatrix getS() Returns the diagonal matrix Σ of the decomposition. Σ is a diagonal matrix. The singular values are provided in non-increasing order, for compatibility with Jama.
| |
| getSingularValues | back to summary |
|---|---|
| public double[] getSingularValues() Returns the diagonal elements of the matrix Σ of the decomposition. The singular values are provided in non-increasing order, for compatibility with Jama.
| |
| getSolver | back to summary |
|---|---|
| public DecompositionSolver getSolver() Get a solver for finding the A × X = B solution in least square sense.
| |
| getU | back to summary |
|---|---|
| public RealMatrix getU() Returns the matrix U of the decomposition. U is an orthogonal matrix, i.e. its transpose is also its inverse.
| |
| getUT | back to summary |
|---|---|
| public RealMatrix getUT() Returns the transpose of the matrix U of the decomposition. U is an orthogonal matrix, i.e. its transpose is also its inverse.
| |
| getV | back to summary |
|---|---|
| public RealMatrix getV() Returns the matrix V of the decomposition. V is an orthogonal matrix, i.e. its transpose is also its inverse.
| |
| getVT | back to summary |
|---|---|
| public RealMatrix getVT() Returns the transpose of the matrix V of the decomposition. V is an orthogonal matrix, i.e. its transpose is also its inverse.
| |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | nonSingular
Singularity indicator. |
| private final RealMatrix | pseudoInverse
Pseudo-inverse of the initial matrix. |
| Access | Constructor and Description |
|---|---|
| private | Solver(final double[]
Singular values. singularValues, final RealMatrix UT matrix of the decomposition. uT, final RealMatrix V matrix of the decomposition. v, final boolean Singularity indicator. nonSingular, final double tolerance for singular values tol)Build a solver from decomposed matrix. |
| Modifier and Type | Method and Description |
|---|---|
| public RealMatrix | Returns: the inverse matrix.Implements org. Get the pseudo-inverse of the decomposed matrix. |
| public boolean | Returns: true if the decomposed matrix is non-singular.Implements org. Check if the decomposed matrix is non-singular. |
| public RealVector | Returns: a vector X that minimizes the two norm of A × X - BRight-hand side of the equation A × X = B b)Implements org. Solve the linear equation A × X = B in least square sense. |
| public RealMatrix | Returns: a matrix X that minimizes the two norm of A × X - BRight-hand side of the equation A × X = B b)Implements org. Solve the linear equation A × X = B in least square sense. |
| nonSingular | back to summary |
|---|---|
| private boolean nonSingular Singularity indicator. | |
| pseudoInverse | back to summary |
|---|---|
| private final RealMatrix pseudoInverse Pseudo-inverse of the initial matrix. | |
| Solver | back to summary |
|---|---|
| private Solver(final double[] singularValues, final RealMatrix uT, final RealMatrix v, final boolean nonSingular, final double tol) Build a solver from decomposed matrix.
| |
| getInverse | back to summary |
|---|---|
| public RealMatrix getInverse() Implements org. Get the pseudo-inverse of the decomposed matrix.
| |
| isNonSingular | back to summary |
|---|---|
| public boolean isNonSingular() Implements org. Check if the decomposed matrix is non-singular.
| |
| solve | back to summary |
|---|---|
| public RealVector solve(final RealVector b) Implements org. Solve the linear equation A × X = B in least square sense. The m×n matrix A may not be square, the solution X is such that ||A × X - B|| is minimal.
| |
| solve | back to summary |
|---|---|
| public RealMatrix solve(final RealMatrix b) Implements org. Solve the linear equation A × X = B in least square sense. The m×n matrix A may not be square, the solution X is such that ||A × X - B|| is minimal.
| |