Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
vnl_svd< T > Class Template Reference

Holds the singular value decomposition of a vnl_matrix. More...

#include <vnl_algo_fwd.h>

Inheritance diagram for vnl_svd< T >:
Inheritance graph
[legend]

Public Types

typedef vnl_numeric_traits< T >::abs_t singval_t
 The singular values of a matrix of complex<T> are of type T, not complex<T>. More...
 

Public Member Functions

 vnl_svd (vnl_matrix< T > const &M, double zero_out_tol=0.0)
 Construct a vnl_svd<T> object from $m \times n$ matrix $M$. More...
 
virtual ~vnl_svd ()=default
 
void zero_out_absolute (double tol=1e-8)
 find weights below threshold tol, zero them out, and update W_ and Winverse_. More...
 
void zero_out_relative (double tol=1e-8)
 find weights below tol*max(w) and zero them out. More...
 
int singularities () const
 
unsigned int rank () const
 
singval_t well_condition () const
 
singval_t determinant_magnitude () const
 Calculate determinant as product of diagonals in W. More...
 
singval_t norm () const
 
vnl_matrix< T > & U ()
 Return the matrix U. More...
 
vnl_matrix< T > const & U () const
 Return the matrix U. More...
 
U (int i, int j) const
 Return the matrix U's (i,j)th entry (to avoid svd.U()(i,j); ). More...
 
vnl_diag_matrix< singval_t > & W ()
 Get at DiagMatrix (q.v.) of singular values, sorted from largest to smallest. More...
 
vnl_diag_matrix< singval_t > const & W () const
 Get at DiagMatrix (q.v.) of singular values, sorted from largest to smallest. More...
 
vnl_diag_matrix< singval_t > & Winverse ()
 
vnl_diag_matrix< singval_t > const & Winverse () const
 
singval_tW (int i, int j)
 
singval_tW (int i)
 
singval_t sigma_max () const
 
singval_t sigma_min () const
 
vnl_matrix< T > & V ()
 Return the matrix V. More...
 
vnl_matrix< T > const & V () const
 Return the matrix V. More...
 
V (int i, int j) const
 Return the matrix V's (i,j)th entry (to avoid svd.V()(i,j); ). More...
 
vnl_matrix< T > inverse () const
 
vnl_matrix< T > pinverse (unsigned int rank=~0u) const
 pseudo-inverse (for non-square matrix) of desired rank. More...
 
vnl_matrix< T > tinverse (unsigned int rank=~0u) const
 Calculate inverse of transpose, using desired rank. More...
 
vnl_matrix< T > recompose (unsigned int rank=~0u) const
 Recompose SVD to U*W*V', using desired rank. More...
 
vnl_matrix< T > solve (vnl_matrix< T > const &B) const
 Solve the matrix equation M X = B, returning X. More...
 
vnl_vector< T > solve (vnl_vector< T > const &y) const
 Solve the matrix-vector system M x = y, returning x. More...
 
void solve (T const *rhs, T *lhs) const
 
void solve_preinverted (vnl_vector< T > const &rhs, vnl_vector< T > *out) const
 Solve the matrix-vector system M x = y. More...
 
vnl_matrix< T > nullspace () const
 Return N such that M * N = 0. More...
 
vnl_matrix< T > left_nullspace () const
 Return N such that M' * N = 0. More...
 
vnl_matrix< T > nullspace (int required_nullspace_dimension) const
 Return N such that M * N = 0. More...
 
vnl_matrix< T > left_nullspace (int required_nullspace_dimension) const
 Implementation to be done yet; currently returns left_nullspace(). - PVR. More...
 
vnl_vector< T > nullvector () const
 Return the rightmost column of V. More...
 
vnl_vector< T > left_nullvector () const
 Return the rightmost column of U. More...
 
bool valid () const
 

Private Member Functions

 vnl_svd (vnl_svd< T > const &)
 
vnl_svd< T > & operator= (vnl_svd< T > const &)
 

Private Attributes

int m_
 
int n_
 
vnl_matrix< T > U_
 
vnl_diag_matrix< singval_tW_
 
vnl_diag_matrix< singval_tWinverse_
 
vnl_matrix< T > V_
 
unsigned rank_
 
bool have_max_
 
singval_t max_
 
bool have_min_
 
singval_t min_
 
double last_tol_
 
bool valid_
 

Detailed Description

template<class T>
class vnl_svd< T >

Holds the singular value decomposition of a vnl_matrix.

The class holds three matrices U, W, V such that the original matrix $M = U W V^\top$. The DiagMatrix W stores the singular values in decreasing order. The columns of U which correspond to the nonzero singular values form a basis for range of M, while the columns of V corresponding to the zero singular values are the nullspace.

The SVD is computed at construction time, and inquiries may then be made of the SVD. In particular, this allows easy access to multiple right-hand-side solves without the bother of putting all the RHS's into a Matrix.

This class is supplied even though there is an existing vnl_matrix method for several reasons:

It is more convenient to use as it manages all the storage for the U,S,V matrices, allowing repeated queries of the same SVD results.

It avoids namespace clutter in the Matrix class. While svd() is a perfectly reasonable method for a Matrix, there are many other decompositions that might be of interest, and adding them all would make for a very large Matrix class.

It demonstrates the holder model of compute class, implementing an algorithm on an object without adding a member that may not be of general interest. A similar pattern can be used for other decompositions which are not defined as members of the library Matrix class.

It extends readily to n-ary operations, such as generalized eigensystems, which cannot be members of just one matrix.

Definition at line 7 of file vnl_algo_fwd.h.

Member Typedef Documentation

◆ singval_t

template<class T>
typedef vnl_numeric_traits<T>::abs_t vnl_svd< T >::singval_t

The singular values of a matrix of complex<T> are of type T, not complex<T>.

Definition at line 67 of file vnl_svd.h.

Constructor & Destructor Documentation

◆ vnl_svd() [1/2]

template<class T>
vnl_svd< T >::vnl_svd ( vnl_matrix< T > const &  M,
double  zero_out_tol = 0.0 
)

Construct a vnl_svd<T> object from $m \times n$ matrix $M$.

The vnl_svd<T> object contains matrices $U$, $W$, $V$ such that $U W V^\top = M$.

Uses linpack routine DSVDC to calculate an `‘economy-size’' SVD where the returned $U$ is the same size as $M$, while $W$ and $V$ are both $n \times n$. This is efficient for large rectangular solves where $m > n$, typical in least squares.

The optional argument zero_out_tol is used to mark the zero singular values: If nonnegative, any s.v. smaller than zero_out_tol in absolute value is set to zero. If zero_out_tol is negative, the zeroing is relative to |zero_out_tol| * sigma_max();

Definition at line 38 of file vnl_svd.hxx.

◆ ~vnl_svd()

template<class T>
virtual vnl_svd< T >::~vnl_svd ( )
virtualdefault

◆ vnl_svd() [2/2]

template<class T>
vnl_svd< T >::vnl_svd ( vnl_svd< T > const &  )
inlineprivate

Definition at line 194 of file vnl_svd.h.

Member Function Documentation

◆ determinant_magnitude()

template<class T >
vnl_svd< T >::singval_t vnl_svd< T >::determinant_magnitude ( ) const

Calculate determinant as product of diagonals in W.

Definition at line 213 of file vnl_svd.hxx.

◆ inverse()

template<class T>
vnl_matrix<T> vnl_svd< T >::inverse ( ) const
inline

Definition at line 133 of file vnl_svd.h.

◆ left_nullspace() [1/2]

template<class T >
vnl_matrix< T > vnl_svd< T >::left_nullspace ( ) const

Return N such that M' * N = 0.

Return N s.t. M' * N = 0.

Definition at line 384 of file vnl_svd.hxx.

◆ left_nullspace() [2/2]

template<class T >
vnl_matrix< T > vnl_svd< T >::left_nullspace ( int  required_nullspace_dimension) const

Implementation to be done yet; currently returns left_nullspace(). - PVR.

Todo:
Implementation to be done yet; currently returns left_nullspace().

- PVr.

Definition at line 395 of file vnl_svd.hxx.

◆ left_nullvector()

template<class T >
vnl_vector< T > vnl_svd< T >::left_nullvector ( ) const

Return the rightmost column of U.

Does not check to see whether or not the matrix actually was rank-deficient.

Definition at line 418 of file vnl_svd.hxx.

◆ norm()

template<class T >
vnl_svd< T >::singval_t vnl_svd< T >::norm ( ) const

Definition at line 226 of file vnl_svd.hxx.

◆ nullspace() [1/2]

template<class T >
vnl_matrix< T > vnl_svd< T >::nullspace ( ) const

Return N such that M * N = 0.

Return N s.t. M * N = 0.

Definition at line 365 of file vnl_svd.hxx.

◆ nullspace() [2/2]

template<class T >
vnl_matrix< T > vnl_svd< T >::nullspace ( int  required_nullspace_dimension) const

Return N such that M * N = 0.

Return N s.t. M * N = 0.

Definition at line 376 of file vnl_svd.hxx.

◆ nullvector()

template<class T >
vnl_vector< T > vnl_svd< T >::nullvector ( ) const

Return the rightmost column of V.

Does not check to see whether or not the matrix actually was rank-deficient - the caller is assumed to have examined W and decided that to his or her satisfaction.

Definition at line 406 of file vnl_svd.hxx.

◆ operator=()

template<class T>
vnl_svd<T>& vnl_svd< T >::operator= ( vnl_svd< T > const &  )
inlineprivate

Definition at line 195 of file vnl_svd.h.

◆ pinverse()

template<class T >
vnl_matrix< T > vnl_svd< T >::pinverse ( unsigned int  rank = ~0u) const

pseudo-inverse (for non-square matrix) of desired rank.

Calculate pseudo-inverse.

Definition at line 247 of file vnl_svd.hxx.

◆ rank()

template<class T>
unsigned int vnl_svd< T >::rank ( ) const
inline

Definition at line 95 of file vnl_svd.h.

◆ recompose()

template<class T >
vnl_matrix< T > vnl_svd< T >::recompose ( unsigned int  rank = ~0u) const

Recompose SVD to U*W*V', using desired rank.

Recompose SVD to U*W*V'.

Definition at line 233 of file vnl_svd.hxx.

◆ sigma_max()

template<class T>
singval_t vnl_svd< T >::sigma_max ( ) const
inline

Definition at line 120 of file vnl_svd.h.

◆ sigma_min()

template<class T>
singval_t vnl_svd< T >::sigma_min ( ) const
inline

Definition at line 121 of file vnl_svd.h.

◆ singularities()

template<class T>
int vnl_svd< T >::singularities ( ) const
inline

Definition at line 94 of file vnl_svd.h.

◆ solve() [1/3]

template<class T>
vnl_matrix< T > vnl_svd< T >::solve ( vnl_matrix< T > const &  B) const

Solve the matrix equation M X = B, returning X.

Definition at line 275 of file vnl_svd.hxx.

◆ solve() [2/3]

template<class T>
vnl_vector< T > vnl_svd< T >::solve ( vnl_vector< T > const &  y) const

Solve the matrix-vector system M x = y, returning x.

Definition at line 298 of file vnl_svd.hxx.

◆ solve() [3/3]

template<class T>
void vnl_svd< T >::solve ( T const *  rhs,
T *  lhs 
) const

Definition at line 337 of file vnl_svd.hxx.

◆ solve_preinverted()

template<class T>
void vnl_svd< T >::solve_preinverted ( vnl_vector< T > const &  y,
vnl_vector< T > *  x_out 
) const

Solve the matrix-vector system M x = y.

Assuming that the singular values W have been preinverted by the caller.

Assume that the singular values W have been preinverted by the caller.

Definition at line 345 of file vnl_svd.hxx.

◆ tinverse()

template<class T >
vnl_matrix< T > vnl_svd< T >::tinverse ( unsigned int  rank = ~0u) const

Calculate inverse of transpose, using desired rank.

Calculate (pseudo-)inverse of transpose.

Definition at line 261 of file vnl_svd.hxx.

◆ U() [1/3]

template<class T>
vnl_matrix<T>& vnl_svd< T >::U ( )
inline

Return the matrix U.

Definition at line 103 of file vnl_svd.h.

◆ U() [2/3]

template<class T>
vnl_matrix<T> const& vnl_svd< T >::U ( ) const
inline

Return the matrix U.

Definition at line 106 of file vnl_svd.h.

◆ U() [3/3]

template<class T>
T vnl_svd< T >::U ( int  i,
int  j 
) const
inline

Return the matrix U's (i,j)th entry (to avoid svd.U()(i,j); ).

Definition at line 109 of file vnl_svd.h.

◆ V() [1/3]

template<class T>
vnl_matrix<T>& vnl_svd< T >::V ( )
inline

Return the matrix V.

Definition at line 124 of file vnl_svd.h.

◆ V() [2/3]

template<class T>
vnl_matrix<T> const& vnl_svd< T >::V ( ) const
inline

Return the matrix V.

Definition at line 127 of file vnl_svd.h.

◆ V() [3/3]

template<class T>
T vnl_svd< T >::V ( int  i,
int  j 
) const
inline

Return the matrix V's (i,j)th entry (to avoid svd.V()(i,j); ).

Definition at line 130 of file vnl_svd.h.

◆ valid()

template<class T>
bool vnl_svd< T >::valid ( ) const
inline

Definition at line 176 of file vnl_svd.h.

◆ W() [1/4]

template<class T>
vnl_diag_matrix<singval_t>& vnl_svd< T >::W ( )
inline

Get at DiagMatrix (q.v.) of singular values, sorted from largest to smallest.

Definition at line 112 of file vnl_svd.h.

◆ W() [2/4]

template<class T>
vnl_diag_matrix<singval_t> const& vnl_svd< T >::W ( ) const
inline

Get at DiagMatrix (q.v.) of singular values, sorted from largest to smallest.

Definition at line 115 of file vnl_svd.h.

◆ W() [3/4]

template<class T>
singval_t& vnl_svd< T >::W ( int  i,
int  j 
)
inline

Definition at line 118 of file vnl_svd.h.

◆ W() [4/4]

template<class T>
singval_t& vnl_svd< T >::W ( int  i)
inline

Definition at line 119 of file vnl_svd.h.

◆ well_condition()

template<class T>
singval_t vnl_svd< T >::well_condition ( ) const
inline

Definition at line 96 of file vnl_svd.h.

◆ Winverse() [1/2]

template<class T>
vnl_diag_matrix<singval_t>& vnl_svd< T >::Winverse ( )
inline

Definition at line 116 of file vnl_svd.h.

◆ Winverse() [2/2]

template<class T>
vnl_diag_matrix<singval_t> const& vnl_svd< T >::Winverse ( ) const
inline

Definition at line 117 of file vnl_svd.h.

◆ zero_out_absolute()

template<class T >
void vnl_svd< T >::zero_out_absolute ( double  tol = 1e-8)

find weights below threshold tol, zero them out, and update W_ and Winverse_.

Definition at line 182 of file vnl_svd.hxx.

◆ zero_out_relative()

template<class T >
void vnl_svd< T >::zero_out_relative ( double  tol = 1e-8)

find weights below tol*max(w) and zero them out.

Definition at line 203 of file vnl_svd.hxx.

Member Data Documentation

◆ have_max_

template<class T>
bool vnl_svd< T >::have_max_
private

Definition at line 186 of file vnl_svd.h.

◆ have_min_

template<class T>
bool vnl_svd< T >::have_min_
private

Definition at line 188 of file vnl_svd.h.

◆ last_tol_

template<class T>
double vnl_svd< T >::last_tol_
private

Definition at line 190 of file vnl_svd.h.

◆ m_

template<class T>
int vnl_svd< T >::m_
private

Definition at line 180 of file vnl_svd.h.

◆ max_

template<class T>
singval_t vnl_svd< T >::max_
private

Definition at line 187 of file vnl_svd.h.

◆ min_

template<class T>
singval_t vnl_svd< T >::min_
private

Definition at line 189 of file vnl_svd.h.

◆ n_

template<class T>
int vnl_svd< T >::n_
private

Definition at line 180 of file vnl_svd.h.

◆ rank_

template<class T>
unsigned vnl_svd< T >::rank_
private

Definition at line 185 of file vnl_svd.h.

◆ U_

template<class T>
vnl_matrix<T> vnl_svd< T >::U_
private

Definition at line 181 of file vnl_svd.h.

◆ V_

template<class T>
vnl_matrix<T> vnl_svd< T >::V_
private

Definition at line 184 of file vnl_svd.h.

◆ valid_

template<class T>
bool vnl_svd< T >::valid_
private

Definition at line 191 of file vnl_svd.h.

◆ W_

template<class T>
vnl_diag_matrix<singval_t> vnl_svd< T >::W_
private

Definition at line 182 of file vnl_svd.h.

◆ Winverse_

template<class T>
vnl_diag_matrix<singval_t> vnl_svd< T >::Winverse_
private

Definition at line 183 of file vnl_svd.h.


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