NumericAL
A header-only C++20 lexer built on REAL
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
numerical::svd_decomposition< T > Class Template Reference

The singular value decomposition A = U Σ Vᴴ of an m × n matrix. More...

#include <decomposition.hpp>

Collaboration diagram for numerical::svd_decomposition< T >:
[legend]

Public Member Functions

 svd_decomposition (const matrix< T > &a, svd_method method=svd_method::divide_and_conquer, bool full=false)
 Decomposes a.
 
const vector< double > & singular_values () const noexcept
 The singular values, descending.
 
const matrix< T > & u () const &noexcept
 The left singular vectors U (columns): m × k, or m × m full.
 
matrix< T > u () &&
 U, moved out of an expiring decomposition (v and the singular values stay).
 
const matrix< T > & v () const &noexcept
 The right singular vectors V (columns): n × k, or n × n full.
 
matrix< T > vh () const
 Vᴴ (k × n, or n × n full), so that A = U Σ Vᴴ reads u() * diag(singular_values()) * vh() (full, Σ padded with zeros to m × n).
 

Private Member Functions

void factor (const matrix< T > &a, svd_method method, bool full)
 Decomposes an m × n a with m ≥ n into u_, singular_values_ and v_, U square when full.
 

Static Private Member Functions

static matrix< T > left_vectors (buffer< T > q, buffer< T > left, std::size_t rows, std::size_t cols, std::size_t width)
 U from the Householder q (rows × width) and the left vectors left of R (cols × cols): Q times them, and when Q is complete (width = rows) its columns past cols after them.
 
static void orthogonalise (buffer< T > &x, const buffer< T > &basis, std::size_t n, std::size_t count)
 Removes from x its components along the first count columns of the n × n basis.
 

Private Attributes

vector< double > singular_values_
 Singular values, descending.
 
matrix< T > u_
 m×k left singular vectors.
 
matrix< T > v_
 n×k right singular vectors.
 

Detailed Description

template<typename T>
class numerical::svd_decomposition< T >

The singular value decomposition A = U Σ Vᴴ of an m × n matrix.

Template Parameters
TThe scalar element type (double or std::complex<double>).

With k = min(m, n): the k singular values, descending; U (m × k) and V (n × k) with orthonormal columns, also where A is rank-deficient. Computed after a Householder QR of A (of Aᴴ when m < n): by default R is reduced to bidiagonal form and the bidiagonal decomposed by divide and conquer (svd_method::divide_and_conquer), the method of LAPACK's dgesdd, most of its work in matrix products, or by implicit-shift QR (svd_method::bidiagonal_qr, dgesvd's); either way each singular value to an absolute accuracy of the largest times the machine epsilon. One-sided Jacobi on R (svd_method::jacobi) gives every singular value to high relative accuracy — the small ones of a graded matrix too — at several times the cost. vh is Vᴴ, the third factor NumPy's svd returns. Full (full true, NumPy's full_matrices=True), U is m × m and V n × n: the columns past k are an orthonormal basis of the complement, the rest of the complete Householder Q of the larger side.

Definition at line 6017 of file decomposition.hpp.

Constructor & Destructor Documentation

◆ svd_decomposition()

template<typename T >
numerical::svd_decomposition< T >::svd_decomposition ( const matrix< T > &  a,
svd_method  method = svd_method::divide_and_conquer,
bool  full = false 
)
inlineexplicit

Decomposes a.

Parameters
[in]aThe matrix.
[in]methodThe algorithm for R.
[in]fullWhether U and V are square (m × m, n × n), as NumPy's full_matrices=True.
Exceptions
non_finite_errorIf an entry is infinite or NaN.
convergence_errorIf the iteration does not converge within its bound (not observed).

Definition at line 6029 of file decomposition.hpp.

Member Function Documentation

◆ factor()

template<typename T >
void numerical::svd_decomposition< T >::factor ( const matrix< T > &  a,
svd_method  method,
bool  full 
)
inlineprivate

Decomposes an m × n a with m ≥ n into u_, singular_values_ and v_, U square when full.

Definition at line 6101 of file decomposition.hpp.

◆ left_vectors()

template<typename T >
static matrix< T > numerical::svd_decomposition< T >::left_vectors ( buffer< T >  q,
buffer< T >  left,
std::size_t  rows,
std::size_t  cols,
std::size_t  width 
)
inlinestaticprivate

U from the Householder q (rows × width) and the left vectors left of R (cols × cols): Q times them, and when Q is complete (width = rows) its columns past cols after them.

Definition at line 6080 of file decomposition.hpp.

◆ orthogonalise()

template<typename T >
static void numerical::svd_decomposition< T >::orthogonalise ( buffer< T > &  x,
const buffer< T > &  basis,
std::size_t  n,
std::size_t  count 
)
inlinestaticprivate

Removes from x its components along the first count columns of the n × n basis.

Definition at line 6227 of file decomposition.hpp.

◆ singular_values()

template<typename T >
const vector< double > & numerical::svd_decomposition< T >::singular_values ( ) const
inlinenoexcept

The singular values, descending.

Definition at line 6044 of file decomposition.hpp.

◆ u() [1/2]

template<typename T >
matrix< T > numerical::svd_decomposition< T >::u ( ) &&
inline

U, moved out of an expiring decomposition (v and the singular values stay).

Definition at line 6056 of file decomposition.hpp.

◆ u() [2/2]

template<typename T >
const matrix< T > & numerical::svd_decomposition< T >::u ( ) const &
inlinenoexcept

The left singular vectors U (columns): m × k, or m × m full.

Definition at line 6050 of file decomposition.hpp.

◆ v()

template<typename T >
const matrix< T > & numerical::svd_decomposition< T >::v ( ) const &
inlinenoexcept

The right singular vectors V (columns): n × k, or n × n full.

Definition at line 6062 of file decomposition.hpp.

◆ vh()

template<typename T >
matrix< T > numerical::svd_decomposition< T >::vh ( ) const
inline

Vᴴ (k × n, or n × n full), so that A = U Σ Vᴴ reads u() * diag(singular_values()) * vh() (full, Σ padded with zeros to m × n).

Definition at line 6069 of file decomposition.hpp.

Member Data Documentation

◆ singular_values_

template<typename T >
vector<double> numerical::svd_decomposition< T >::singular_values_
private

Singular values, descending.

Definition at line 6243 of file decomposition.hpp.

◆ u_

template<typename T >
matrix<T> numerical::svd_decomposition< T >::u_
private

m×k left singular vectors.

Definition at line 6244 of file decomposition.hpp.

◆ v_

template<typename T >
matrix<T> numerical::svd_decomposition< T >::v_
private

n×k right singular vectors.

Definition at line 6245 of file decomposition.hpp.


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