SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWLeastSqQR< TypeT, QRCalc > Class Template Reference

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

#include <rw/lapack/lsqr.h>

Inheritance diagram for RWLeastSqQR< TypeT, QRCalc >:
RWCODecomp< TypeT, QRCalc >

Public Member Functions

 RWLeastSqQR ()
 
 RWLeastSqQR (const RWGenMat< TypeT > &A, double tol=0)
 
 RWLeastSqQR (const RWQRDecomp< TypeT, QRCalc > &A, double tol=0)
 
 RWLeastSqQR (const RWCODecomp< TypeT, QRCalc > &A)
 
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 RWCODecomp< TypeT, QRCalc >
 RWCODecomp ()
 
 RWCODecomp (const RWCODecomp< TypeT, QRCalc > &A)
 
 RWCODecomp (const RWQRDecomp< TypeT, QRCalc > &A, double tol=0)
 
 RWCODecomp (const RWGenMat< TypeT > &A, double tol=0)
 
unsigned cols () const
 
void factor (const RWQRDecomp< TypeT, QRCalc > &A, double tol=0)
 
void factor (const RWGenMat< TypeT > &A, double tol=0)
 
RWGenMat< TypeT > P () const
 
RWMathVec< TypeT > PTx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > Px (const RWMathVec< TypeT > &x) const
 
RWGenMat< TypeT > Q () const
 
RWMathVec< TypeT > QTx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > Qx (const RWMathVec< TypeT > &x) const
 
unsigned rank () const
 
unsigned rows () const
 
RWUpperTriMat< TypeT > T () const
 
RWMathVec< TypeT > Tinvx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > TTinvx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > TTx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > Tx (const RWMathVec< TypeT > &x) const
 
RWGenMat< TypeT > Z () const
 
RWMathVec< TypeT > ZTx (const RWMathVec< TypeT > &x) const
 
RWMathVec< TypeT > Zx (const RWMathVec< TypeT > &x) const
 

Detailed Description

template<class TypeT, class QRCalc>
class RWLeastSqQR< TypeT, QRCalc >

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:

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/lsch.h>
#include <rw/lapack/lsqr.h>
#include <rw/lapack/lssv.h>
#include <rw/lapack/qrcalc.h>
// an RWGenMat<double>
RWMathVec<double> x = QR.solve(b); // b is an RWMathVec<double>
Example
Please see the example shown in RWLeastSqSV

Constructor & Destructor Documentation

template<class TypeT, class QRCalc>
RWLeastSqQR< TypeT, QRCalc >::RWLeastSqQR ( )

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

template<class TypeT, class QRCalc>
RWLeastSqQR< TypeT, QRCalc >::RWLeastSqQR ( 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.

template<class TypeT, class QRCalc>
RWLeastSqQR< TypeT, QRCalc >::RWLeastSqQR ( const RWQRDecomp< TypeT, QRCalc > &  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 QR decomposition as 0. The tolerance should indicate the accuracy to which you know the entries in the matrix.

template<class TypeT, class QRCalc>
RWLeastSqQR< TypeT, QRCalc >::RWLeastSqQR ( const RWCODecomp< TypeT, QRCalc > &  A)

Constructs a factorization representing the linear system represented by the given decomposition.

Member Function Documentation

template<class TypeT, class QRCalc>
RWMathVec<TypeT> RWLeastSqQR< TypeT, QRCalc >::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.

template<class TypeT, class QRCalc>
rw_numeric_traits<TypeT>::norm_type RWLeastSqQR< TypeT, QRCalc >::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.

template<class TypeT, class QRCalc>
RWMathVec<TypeT> RWLeastSqQR< TypeT, QRCalc >::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 © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.