TooN
|
Performs SVD and back substitute to solve equations. More...
#include <TooN/SVD.h>
Public Member Functions | |
SVD () | |
default constructor for Rows>0 and Cols>0 | |
SVD (int rows, int cols) | |
constructor for Rows=-1 or Cols=-1 (or both) | |
template<int R2, int C2, typename P2 , typename B2 > | |
SVD (const Matrix< R2, C2, P2, B2 > &m) | |
Construct the SVD decomposition of a matrix. More... | |
template<int R2, int C2, typename P2 , typename B2 > | |
void | compute (const Matrix< R2, C2, P2, B2 > &m) |
Compute the SVD decomposition of M, typically used after the default constructor. | |
template<int Rows2, int Cols2, typename P2 , typename B2 > | |
Matrix< Cols, Cols2, typename Internal::MultiplyType< Precision, P2 >::type > | backsub (const Matrix< Rows2, Cols2, P2, B2 > &rhs, const Precision condition=condition_no) |
Calculate result of multiplying the (pseudo-)inverse of M by another matrix. More... | |
template<int Size, typename P2 , typename B2 > | |
Vector< Cols, typename Internal::MultiplyType< Precision, P2 >::type > | backsub (const Vector< Size, P2, B2 > &rhs, const Precision condition=condition_no) |
Calculate result of multiplying the (pseudo-)inverse of M by a vector. More... | |
Matrix< Cols, Rows > | get_pinv (const Precision condition=condition_no) |
Calculate (pseudo-)inverse of the matrix. More... | |
Precision | determinant () |
Calculate the product of the singular values for square matrices this is the determinant. | |
int | rank (const Precision condition=condition_no) |
Calculate the rank of the matrix. More... | |
Matrix< Rows, Min_Dim, Precision, Reference::RowMajor > | get_U () |
Return the U matrix from the decomposition The size of this depends on the shape of the original matrix it is square if the original matrix is wide or tall if the original matrix is tall. | |
Vector< Min_Dim, Precision > & | get_diagonal () |
Return the singular values as a vector. | |
Matrix< Min_Dim, Cols, Precision, Reference::RowMajor > | get_VT () |
Return the VT matrix from the decomposition The size of this depends on the shape of the original matrix it is square if the original matrix is tall or wide if the original matrix is wide. | |
void | get_inv_diag (Vector< Min_Dim > &inv_diag, const Precision condition) |
Return the pesudo-inverse diagonal. More... | |
Performs SVD and back substitute to solve equations.
Singular value decompositions are more robust than LU decompositions in the face of singular or nearly singular matrices. They decompose a matrix (of any shape) \(M\) into:
\[M = U \times D \times V^T\]
where \(D\) is a diagonal matrix of positive numbers whose dimension is the minimum of the dimensions of \(M\). If \(M\) is tall and thin (more rows than columns) then \(U\) has the same shape as \(M\) and \(V\) is square (vice-versa if \(M\) is short and fat). The columns of \(U\) and the rows of \(V\) are orthogonal and of unit norm (so one of them lies in SO(N)). The inverse of \(M\) (or pseudo-inverse if \(M\) is not square) is then given by
\[M^{\dagger} = V \times D^{-1} \times U^T\]
If \(M\) is nearly singular then the diagonal matrix \(D\) has some small values (relative to its largest value) and these terms dominate \(D^{-1}\). To deal with this problem, the inverse is conditioned by setting a maximum ratio between the largest and smallest values in \(D\) (passed as the condition
parameter to the various functions). Any values which are too small are set to zero in the inverse (rather than a large number)
It can be used as follows to solve the \(M\underline{x} = \underline{c}\) problem as follows:
SVD<> (= SVD<-1>) can be used to create an SVD whose size is determined at run-time.
|
inline |
Construct the SVD decomposition of a matrix.
This initialises the class, and performs the decomposition immediately.
|
inline |
Calculate result of multiplying the (pseudo-)inverse of M by another matrix.
For a matrix \(A\), this calculates \(M^{\dagger}A\) by back substitution (i.e. without explictly calculating the (pseudo-)inverse). See the detailed description for a description of condition variables.
|
inline |
Calculate result of multiplying the (pseudo-)inverse of M by a vector.
For a vector \(b\), this calculates \(M^{\dagger}b\) by back substitution (i.e. without explictly calculating the (pseudo-)inverse). See the detailed description for a description of condition variables.
|
inline |
Return the pesudo-inverse diagonal.
The reciprocal of the diagonal elements is returned if the elements are well scaled with respect to the largest element, otherwise 0 is returned.
inv_diag | Vector in which to return the inverse diagonal. |
condition | Elements must be larger than this factor times the largest diagonal element to be considered well scaled. |
|
inline |
Calculate (pseudo-)inverse of the matrix.
This is not usually needed: if you need the inverse just to multiply it by a matrix or a vector, use one of the backsub() functions, which will be faster. See the detailed description of the pseudo-inverse and condition variables.
|
inline |
Calculate the rank of the matrix.
See the detailed description of the pseudo-inverse and condition variables.