TooN
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V > Class Template Reference

Performs SVD and back substitute to solve equations. More...

#include <TooN/GR_SVD.h>

Collaboration diagram for TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V >:
Collaboration graph
[legend]

Public Member Functions

template<class Precision2 , class Base >
 GR_SVD (const Matrix< M, N, Precision2, Base > &A)
 
const Matrix< M, N, Precision > & get_U ()
 
const Matrix< N, N, Precision > & get_V ()
 
const Vector< N, Precision > & get_diagonal ()
 
Precision get_largest_singular_value ()
 
Precision get_smallest_singular_value ()
 
int get_smallest_singular_value_index ()
 
void get_inv_diag (Vector< N > &inv_diag, const Precision condition)
 Return the pesudo-inverse diagonal. More...
 
template<int Rows2, int Cols2, typename P2 , typename B2 >
Matrix< N, Cols2, typename Internal::MultiplyType< Precision, P2 >::type > backsub (const Matrix< Rows2, Cols2, P2, B2 > &rhs, const Precision condition=1e9)
 Calculate result of multiplying the (pseudo-)inverse of M by another matrix. More...
 
template<int Size, typename P2 , typename B2 >
Vector< N, typename Internal::MultiplyType< Precision, P2 >::type > backsub (const Vector< Size, P2, B2 > &rhs, const Precision condition=1e9)
 Calculate result of multiplying the (pseudo-)inverse of M by a vector. More...
 
Matrix< N, M, Precision > get_pinv (const Precision condition=1e9)
 Get the pseudo-inverse \(M^{\dagger}\).
 
void reorder ()
 Reorder the components so the singular values are in descending order.
 

Static Public Attributes

static const int BigDim = M>N?M:N
 
static const int SmallDim = M<N?M:N
 

Protected Member Functions

void Bidiagonalize ()
 
void Accumulate_RHS ()
 
void Accumulate_LHS ()
 
void Diagonalize ()
 
bool Diagonalize_SubLoop (int k, Precision &z)
 

Protected Attributes

Vector< N, Precision > vDiagonal
 
Vector< BigDim, Precision > vOffDiagonal
 
Matrix< M, N, Precision > mU
 
Matrix< N, N, Precision > mV
 
int nError
 
int nIterations
 
Precision anorm
 

Detailed Description

template<int M, int N = M, class Precision = DefaultPrecision, bool WANT_U = 1, bool WANT_V = 1>
class TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V >

Performs SVD and back substitute to solve equations.

This code is a c++ translation of the FORTRAN routine give in George E. Forsythe et al, Computer Methods for Mathematical Computations, Prentice-Hall 1977. That code itself is a translation of the ALGOL routine by Golub and Reinsch, Num. Math. 14, 403-420, 1970.

N.b. the singular values returned by this routine are not sorted. N.b. this also means that even for MxN matrices with M<N, N singular values are computed and used.

The template parameters WANT_U and WANT_V may be set to false to indicate that U and/or V are not needed for a minor speed-up.

Member Function Documentation

◆ backsub() [1/2]

template<int M, int N = M, class Precision = DefaultPrecision, bool WANT_U = 1, bool WANT_V = 1>
template<int Rows2, int Cols2, typename P2 , typename B2 >
Matrix<N,Cols2, typename Internal::MultiplyType<Precision,P2>::type > TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V >::backsub ( const Matrix< Rows2, Cols2, P2, B2 > &  rhs,
const Precision  condition = 1e9 
)
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.

◆ backsub() [2/2]

template<int M, int N = M, class Precision = DefaultPrecision, bool WANT_U = 1, bool WANT_V = 1>
template<int Size, typename P2 , typename B2 >
Vector<N, typename Internal::MultiplyType<Precision,P2>::type > TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V >::backsub ( const Vector< Size, P2, B2 > &  rhs,
const Precision  condition = 1e9 
)
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.

◆ get_inv_diag()

template<int M, int N = M, class Precision = DefaultPrecision, bool WANT_U = 1, bool WANT_V = 1>
void TooN::GR_SVD< M, N, Precision, WANT_U, WANT_V >::get_inv_diag ( Vector< N > &  inv_diag,
const Precision  condition 
)
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.

Parameters
inv_diagVector in which to return the inverse diagonal.
conditionElements must be larger than this factor times the largest diagonal element to be considered well scaled.

The documentation for this class was generated from the following file: