SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWLeastSqSV< TypeT, SVDCalc > Class Template Reference

Represents a factorization of a system of equations with no exact solution such that the singular value method of least squares can be used. More...

#include <rw/lapack/lssv.h>

Inheritance diagram for RWLeastSqSV< TypeT, SVDCalc >:
RWSVDecomp< TypeT, SVDCalc >

Public Member Functions

 RWLeastSqSV ()
 
 RWLeastSqSV (const RWGenMat< TypeT > &A, double tol=0)
 
 RWLeastSqSV (const RWSVDecomp< TypeT, SVDCalc > &A, double tol=0)
 
RWMathVec< TypeT > residual (const RWMathVec< TypeT > &b) const
 
rw_numeric_traits< TypeT >::norm_type residualNorm (const RWMathVec< TypeT > &b) const
 
RWMathVec< TypeT > solve (const RWMathVec< TypeT > &b) const
 
- Public Member Functions inherited from RWSVDecomp< TypeT, SVDCalc >
 RWSVDecomp ()
 
 RWSVDecomp (const RWGenMat< TypeT > &A, norm_type tol=0)
 
 RWSVDecomp (const RWSVDecomp< TypeT, SVDCalc > &A)
 
unsigned cols () const
 
void factor (const RWGenMat< TypeT > &A, norm_type tol=0)
 
bool fail () const
 
bool good () const
 
const RWMathVec< TypeT > leftVector (int i) const
 
const RWGenMat< TypeT > leftVectors () const
 
unsigned numLeftVectors () const
 
unsigned numRightVectors () const
 
RWSVDecomp< TypeT, SVDCalc > & operator= (const RWSVDecomp< TypeT, SVDCalc > &x)
 
unsigned rank () const
 
const RWMathVec< TypeT > rightVector (int i) const
 
const RWGenMat< TypeT > rightVectors () const
 
unsigned rows () const
 
norm_type singularValue (int i) const
 
const RWMathVec< norm_typesingularValues () const
 
void truncate (norm_type tol)
 

Additional Inherited Members

- Public Types inherited from RWSVDecomp< TypeT, SVDCalc >
typedef rw_numeric_traits< TypeT >::norm_type norm_type
 

Detailed Description

template<class TypeT, class SVDCalc>
class RWLeastSqSV< TypeT, SVDCalc >

A linear system of equations has the form \( Ax = b \), where A contains more rows than columns and generally has no exact solution; it is overdetermined. The best that we can do is to find a solution vector x such that the norm of the residual vector, \( Ax-b \), is made as small as possible. The vector x is then a solution in the least squares sense, and this sort of problem is called a least squares problem.

There are three classes in the Linear Algebra Module for solving least squares problems. The approach is to construct a factorization of the matrix A that can be used to solve the problem. The classes RWLeastSqCh RWLeastSqQR and RWLeastSqSV encapsulate this factorization object. There are three methods provided:

  • Cholesky method or method of normal equations, encoded by Ch
  • Complete orthogonal factorization method, encoded by QR
  • Singular value method, encoded by SV.

Which method you choose depends on the trade-off between speed and robustness that you want to make. As you move down the list, the methods decrease in speed, but increase in accuracy and robustness.

A system of equations \( Ax = b \) is underdetermined if the columns of A are linearly dependent. In this case, there are infinitely many solutions. Often, the one that is desired is the one with minimum norm. The classes RWLeastSqQR and RWLeastSqSV allow you to compute this solution.

Note that the classes RWLeastSqQR and RWLeastSqSV are publicly derived from their underlying decomposition types, so that advanced users can manipulate the underlying decomposition directly.

Note
For greater flexibility with RWLeastSqQR, the user can implement this method, or the Linear Algebra Module provides two classes to perform this function - RWQRCalc and RWQRCalcP3. Please see their descriptions in this reference guide for more information.
Synopsis
#include <rw/lapack/dvddccalc.h>
#include <rw/lapack/lsch.h>
#include <rw/lapack/lsqr.h>
#include <rw/lapack/lssv.h>
// A is an RWGenMat<double>
RWMathVec<double> x = SVD.solve(b); // b is an RWMathVec<double>
Represents a factorization of a system of equations with no exact solution such that the singular val...
Definition lssv.h:119
A templatized vector class.
Definition mathvec.h:667
Example
// Find the least squares (if overdetermined) or
// minimum norm (if underdetermined) solution to
// the linear system of equations Ax=b. Also input
// a tolerance called epsilon which represents the
// accuracy of the entries in A. This makes the
// procedure robust in the event that A has nearly
// linearly dependent columns.
#include <rw/lapack/lsch.h>
#include <rw/lapack/lsqr.h>
#include <rw/lapack/lssv.h>
#include <rw/lapack/svddccalc.h>
#include <iostream>
int main() {
double tol;
std::cin >> A >> tol >> b;
RWMathVec<double> x = decomp.solve(b);
std::cout << "Solution is " << x << std::endl;
return 0;
}
A templatized general matrix class.
Definition genmat.h:741

Constructor & Destructor Documentation

◆ RWLeastSqSV() [1/3]

template<class TypeT , class SVDCalc >
RWLeastSqSV< TypeT, SVDCalc >::RWLeastSqSV ( )

Default constructor. Builds an empty decomposition. The decomposition is filled in using the factor function.

◆ RWLeastSqSV() [2/3]

template<class TypeT , class SVDCalc >
RWLeastSqSV< TypeT, SVDCalc >::RWLeastSqSV ( const RWGenMat< TypeT > & A,
double tol = 0 )

Constructs a factorization representing the given matrix. The supplied tolerance tells when to consider entries along the diagonal of the underlying decomposition as 0. The tolerance should indicate the accuracy to which you know entries in A.

◆ RWLeastSqSV() [3/3]

template<class TypeT , class SVDCalc >
RWLeastSqSV< TypeT, SVDCalc >::RWLeastSqSV ( const RWSVDecomp< TypeT, SVDCalc > & A,
double tol = 0 )

Constructs a factorization representing the linear system represented by the given decomposition. The parameter tol tells when to consider entries along the diagonal of the given SV decomposition as 0. The tolerance should indicate the accuracy to which you know the entries in the matrix.

Member Function Documentation

◆ residual()

template<class TypeT , class SVDCalc >
RWMathVec< TypeT > RWLeastSqSV< TypeT, SVDCalc >::residual ( const RWMathVec< TypeT > & b) const

Returns the residual vector, \( b-Ax \), associated with the right-hand side vector b and the corresponding least squares solution vector x

◆ residualNorm()

template<class TypeT , class SVDCalc >
rw_numeric_traits< TypeT >::norm_type RWLeastSqSV< TypeT, SVDCalc >::residualNorm ( const RWMathVec< TypeT > & b) const

Returns the norm of the residual vector, \( (b-Ax)'(b-Ax) \), associated with the right-hand side vector b and the corresponding least squares solution vector x.

◆ solve()

template<class TypeT , class SVDCalc >
RWMathVec< TypeT > RWLeastSqSV< TypeT, SVDCalc >::solve ( const RWMathVec< TypeT > & b) const

Returns the solution to the least squares problem for the given right-hand-side vector b. If the system matrix is overdetermined, this is the vector that minimizes the norm of the residual vector. If the system matrix is not overdetermined, this is the minimum norm vector that satisfies the system equations.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.