TRIQS/nda 1.3.0
Multi-dimensional array library for C++
|
#include <nda/lapack/gelss_worker.hpp>
Worker class for solving linear least squares problems.
Solving a linear least squares problem means finding the minimum norm solution \( \mathbf{x} \) of a linear system of equations, i.e.
\[ \min_x | \mathbf{b} - \mathbf{A x} |_2 \; , \]
where \( \mathbf{A} \) is a given matrix and \( \mathbf{b} \) is a given vector (although it can also be a matrix, in this case one searches for a solution matrix \( \mathbf{X} \)).
Let \( \mathbf{A} \in \mathbb{C}^{M \times N} \) with rank \( \rho \leq \min(M, N) \). Its singular value decomposition (SVD) is given by
\[ \mathbf{A} = \mathbf{U} \mathbf{\Sigma} \mathbf{V}^H = \begin{bmatrix} \mathbf{U}_R & \mathbf{U}_N \end{bmatrix} \begin{bmatrix} \mathbf{S} & 0 \\ 0 & 0 \end{bmatrix} \begin{bmatrix} \mathbf{V}_R^H \\ \mathbf{V}_N^H \end{bmatrix} \; , \]
where \( \mathbf{U}_R \in \mathbb{C}^{M \times \rho} \), \( \mathbf{U}_N \in \mathbb{C}^{M \times (M - \rho)} \), \( \mathbf{S} \in \mathbb{R}^{\rho \times \rho} \), \( \mathbf{V}_R \in \mathbb{C}^{N \times \rho} \), and \( \mathbf{V}_N \in \mathbb{C}^{N \times (N - \rho)} \).
The least squares solution can then be written as
\[ \mathbf{x} = \mathbf{A}^{+} \mathbf{b} = \mathbf{V} \mathbf{\Sigma}^{+} \mathbf{U}^H \mathbf{b} = \mathbf{V}_R \mathbf{S}^{-1} \mathbf{U}_R^H \mathbf{b} \; , \]
where \( \mathbf{M}^{+} \) denotes the Moore-Penrose pseudo-inverse of the matrix \( \mathbf{M} \), and the residual error as
\[ \epsilon = \left\| \mathbf{A} \mathbf{x} - \mathbf{b} \right\|_2 = \left\| \mathbf{U}_N^H \mathbf{b} \right\|_2 \; . \]
See this question on math.stackexchange for more information.
T | Value type of the given problem. |
Definition at line 88 of file gelss_worker.hpp.
Public Member Functions | |
gelss_worker (matrix_const_view< T > A) | |
Construct a new worker object for a given matrix \( \mathbf{A} \) . | |
int | n_var () const |
Get the number of variables of the given problem, i.e. the size of the vector \( \mathbf{x} \). | |
auto | operator() (matrix_const_view< T > B, std::optional< long >={}) const |
Solve the least squares problem for a given right hand side matrix \( \mathbf{B} \). | |
auto | operator() (vector_const_view< T > b, std::optional< long >={}) const |
Solve the least squares problem for a given right hand side vector \( \mathbf{b} \). | |
array< double, 1 > const & | S_vec () const |
Get the singular values, i.e. the diagonal elements of the matrix \( \mathbf{S} \). | |
|
inline |
Construct a new worker object for a given matrix \( \mathbf{A} \) .
It performs the SVD decomposition of the given matrix \( \mathbf{A} \) and stores its pseudo inverse \( \mathbf{A}^{+} \), its singular values \( \mathbf{s} = \mathrm{diag}(\mathbf{S}) \) and the matrix \(\mathbf{U}_N^H \). The latter is used to calculate the error of the least squares problem.
A | Matrix \( \mathbf{A} \) used in the least squares problem. |
Definition at line 123 of file gelss_worker.hpp.
|
inline |
Get the number of variables of the given problem, i.e. the size of the vector \( \mathbf{x} \).
Definition at line 106 of file gelss_worker.hpp.
|
inline |
Solve the least squares problem for a given right hand side matrix \( \mathbf{B} \).
It calculates and returns the least squares solution \( \mathbf{X} = \mathbf{A}^{+} \mathbf{B} \) and the error
\[ \epsilon = \max\left\{ \frac{ \left\| \mathbf{U}_N^H \mathbf{b} \right\|_2 }{ \sqrt{N} } : \mathbf{b} \text{ is a column vector in } \mathbf{B} \right\} \; . \]
B | Right hand side matrix. |
std::pair<matrix<T>, double>
containing the solution matrix \( \mathbf{X} \) and the error \(\epsilon \). Definition at line 158 of file gelss_worker.hpp.
|
inline |
Solve the least squares problem for a given right hand side vector \( \mathbf{b} \).
It calculates and returns the least squares solution \( \mathbf{x} = \mathbf{A}^{+} \mathbf{b} \) and the error \( \epsilon = \frac{ \left\| \mathbf{U}_N^H \mathbf{b} \right\|_2 }{ \sqrt{N} } \).
b | Right hand side vector. |
std::pair<vector<T>, double>
containing the solution vector \( \mathbf{x} \) and the error \(\epsilon \). Definition at line 179 of file gelss_worker.hpp.
|
inlinenodiscard |
Get the singular values, i.e. the diagonal elements of the matrix \( \mathbf{S} \).
Definition at line 112 of file gelss_worker.hpp.