#include <matrix/matrixMat.h>
Public Member Functions | |
SVDMatrix (const Matrix< T > &A) | |
int | decompose (const Matrix< T > &A) |
void | minMax (T &min_sig, T &max_sig) const |
double | q_cond_number (void) const |
void | cut_off (const double min_sig) |
void | inverseIn (Matrix< T > &inv, double tau=0) |
Matrix< T > | inverse (double tau=0) |
int | solve (const Matrix< T > &B, Matrix< T > &X, double tau=0) |
Public Attributes | |
const Matrix< T > & | U |
const Matrix< T > & | V |
const Vector< T > & | sig |
Protected Member Functions | |
double | left_householder (Matrix< T > &A, const int i) |
double | right_householder (Matrix< T > &A, const int i) |
double | bidiagonalize (Vector< T > &super_diag, const Matrix< T > &_A) |
void | rotate (Matrix< T > &U, const int i, const int j, const double cos_ph, const double sin_ph) |
void | rip_through (Vector< T > &super_diag, const int k, const int l, const double eps) |
int | get_submatrix_to_work_on (Vector< T > &super_diag, const int k, const double eps) |
void | diagonalize (Vector< T > &super_diag, const double eps) |
Protected Attributes | |
int | M |
int | N |
Matrix< T > | U_ |
Matrix< T > | V_ |
Vector< T > | sig_ |
This matrix was adapted from the Numerical Math Class Library developed by Oleg Kiselyov.
This class can only be used with floating point values (float or double).
The following comments are from Oleg Kiselyov.
Singular Value Decomposition of a rectangular matrix
A=U Sig V'
where matrices U and V are orthogonal and Sig is a
diagonal matrix.
The singular value decomposition is performed by constructing an SVD object from an M*N matrix A with M \ge N (that is, at least as many rows as columns). Note, in case M > N, matrix Sig has to be a M*N diagonal matrix. However, it has only N diagonal elements, which we store in a vector sig.
Algorithm: Bidiagonalization with Householder reflections followed by a modification of a QR-algorithm. For more details, see G.E. Forsythe, M.A. Malcolm, C.B. Moler Computer methods for mathematical computations, Prentice-Hall, 1977. However, in the present implementation, matrices U and V are computed right away rather than delayed until after all Householder reflections.
This code is based for the most part on a Algol68 code I (Oleg Kiselyov) wrote ca. 1987.
Look at the source code for more information about the algorithm.
PLib::SVDMatrix< T >::SVDMatrix | ( | const Matrix< T > & | A | ) |
Performs the SVD decomposition of A.
Performs the SVD decomposition of A. It is not recommended to use this routine has errors from the decomposition routine are discarded
A | the matrix to decompose |
int PLib::SVDMatrix< T >::decompose | ( | const Matrix< T > & | A | ) |
Performs the SVD decomposition of A.
Performs the SVD decomposition of A.
A | the matrix to decompose |
void PLib::SVDMatrix< T >::minMax | ( | T & | min_sig, | |
T & | max_sig | |||
) | const |
Finds the minimal and maximal sigma values.
Finds the minimal and maximal sigma values.
min_sig | the minimal sigma value | |
max_sig | the maximal sigma value |
double PLib::SVDMatrix< T >::q_cond_number | ( | void | ) | const |
Finds the condition number.
Finds the condition number which corresponds to the maximal sigma value divided by its minimal value.
void PLib::SVDMatrix< T >::inverseIn | ( | Matrix< T > & | A, | |
double | tau = 0 | |||
) |
Finds the (pseudo-)inverse of a SVD matrix.
Finds the (pseudo-)inverse of a SVD matrix.
A | the inverse of the SVD matrix | |
tau | the minimal singular value accepted |
Matrix< T > PLib::SVDMatrix< T >::inverse | ( | double | tau = 0 |
) |
Finds the (pseudo-)inverse of a SVD matrix.
Finds the (pseudo-)inverse of a SVD matrix.
tau | the minimal singular value accepted |
int PLib::SVDMatrix< T >::solve | ( | const Matrix< T > & | B, | |
Matrix< T > & | X, | |||
double | tau = 0 | |||
) |
Solves the linear system A X = B.
Solves the linear system A X = B. Given A and B it finds the value of X. A is the SVD matrix properly initialized and the only other input parameter is B.
B | the right hand side of the equation | |
X | the resulting matrix | |
tau | the minimal singular value accepted |
int PLib::SVDMatrix< T >::N [protected] |
Dimensions of the problem (M > N).
Matrix<T> PLib::SVDMatrix< T >::U_ [protected] |
M * M orthogonal matrix U.
Matrix<T> PLib::SVDMatrix< T >::V_ [protected] |
N * N orthogonal matrix V.
Vector<T> PLib::SVDMatrix< T >::sig_ [protected] |
Vector of N unordered singular values.