Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BIAS::LeastSquaresSVD Class Reference

Linear least squares solver based on singular value decomposition. More...

#include <MathAlgo/LeastSquares.hh>

+ Inheritance diagram for BIAS::LeastSquaresSVD:
+ Collaboration diagram for BIAS::LeastSquaresSVD:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
int GetDebugLevel () const
 
std::ostream & GetDebugStream () const
 
void GetDebugStream (std::ostream &os) const
 
int Init (unsigned SolutionSize, bool ReduceToATA=true)
 Initialize least squares solver. More...
 
 LeastSquaresSVD ()
 
long int Name2DebugLevel (const std::string &name) const
 looks up a debuglevel in the internal map, returns 0 if not found More...
 
long int NewDebugLevel (const std::string &name)
 creates a new debuglevel More...
 
void PrintDebugLevel (std::ostream &os=std::cout) const
 
void RemoveDebugLevel (const long int lv)
 
void RemoveDebugLevel (const std::string &name)
 
void SetDebugLevel (const long int lv)
 
void SetDebugLevel (const std::string &name)
 
void SetDebugStream (const std::ostream &os)
 
void ShowDebugLevel (std::ostream &os=std::cout) const
 prints all internally known debuglevels More...
 
virtual int Solve (Matrix< double > &A, Vector< double > &b, Vector< double > &x)
 LeastSquaresSVD. More...
 
virtual int Solve (Matrix< double > &A, Vector< double > &x)
 Solve linear equation system A*x = 0 using linear least squares, i.e. More...
 
virtual int WeightedSolve (Matrix< double > &A, Vector< double > &b, Vector< double > &weights, Vector< double > &x)
 Solve linear equation system A*x = b using weighted linear least squares, i.e. More...
 
virtual int WeightedSolve (Matrix< double > &A, Vector< double > &weights, Vector< double > &x)
 Solve linear equation system A*x = 0 using weighted linear least squares, i.e. More...
 
virtual ~LeastSquaresSVD ()
 

Static Public Member Functions

static long int GetGlobalDebugLevel ()
 
static void SetGlobalDebugLevel (long int lev)
 

Protected Member Functions

long ConsumeNextFreeDebuglevel_ ()
 returns the next available debuglevel More...
 

Protected Attributes

Matrix< double > _AT
 
Matrix< double > _ATA
 
Vector< double > _ATb
 
long int _liDebugLevel
 
long int _liNextDebugLevel
 new concept, debuglevel are managed here in the debug class More...
 
bool _ReduceToATA
 
Vector< double > _S
 
unsigned _SolutionSize
 
std::map< std::string, long int > _String2Debuglevel
 
SVD _svd
 
Matrix< double > _VT
 
Matrix< double > _Weight
 

Static Protected Attributes

static std::ostream _zDebugStream
 
static long int GlobalDebugLevel = 0
 

Detailed Description

Linear least squares solver based on singular value decomposition.

Author
MIP
Examples:
ExampleLeastSquares.cpp.

Definition at line 129 of file LeastSquares.hh.

Constructor & Destructor Documentation

BIAS::LeastSquaresSVD::LeastSquaresSVD ( )
inline

Definition at line 133 of file LeastSquares.hh.

virtual BIAS::LeastSquaresSVD::~LeastSquaresSVD ( )
inlinevirtual

Definition at line 135 of file LeastSquares.hh.

Member Function Documentation

void BIAS::Debug::AddDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::AddDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 362 of file Debug.hh.

long BIAS::Debug::ConsumeNextFreeDebuglevel_ ( )
inlineprotectedinherited

returns the next available debuglevel

Author
woelk 09/2006

Definition at line 521 of file Debug.hh.

bool BIAS::Debug::DebugLevelIsSet ( const long int  lv) const
inlineinherited
bool BIAS::Debug::DebugLevelIsSet ( const std::string &  name) const
inlineinherited

Definition at line 350 of file Debug.hh.

int BIAS::Debug::GetDebugLevel ( ) const
inlineinherited
std::ostream& BIAS::Debug::GetDebugStream ( ) const
inlineinherited

Definition at line 405 of file Debug.hh.

void BIAS::Debug::GetDebugStream ( std::ostream &  os) const
inlineinherited

Definition at line 414 of file Debug.hh.

static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

int LeastSquaresBase::Init ( unsigned  SolutionSize,
bool  ReduceToATA = true 
)
inherited

Initialize least squares solver.

LeastSquaresBase.

Parameters
[in]SolutionSizeNumber of parameters
[in]ReduceToATAReduce minimization of |Ax-b| to solution of (A'A)x = A'b
Examples:
ExampleLeastSquares.cpp.

Definition at line 36 of file LeastSquares.cpp.

long int BIAS::Debug::Name2DebugLevel ( const std::string &  name) const
inlineinherited

looks up a debuglevel in the internal map, returns 0 if not found

Author
woelk 09/2006

Definition at line 454 of file Debug.hh.

long int BIAS::Debug::NewDebugLevel ( const std::string &  name)
inlineinherited
void BIAS::Debug::PrintDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

Definition at line 383 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const long int  lv)
inlineinherited

Definition at line 369 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 376 of file Debug.hh.

void BIAS::Debug::SetDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::SetDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 325 of file Debug.hh.

void BIAS::Debug::SetDebugStream ( const std::ostream &  os)
inlineinherited

Definition at line 398 of file Debug.hh.

static void BIAS::Debug::SetGlobalDebugLevel ( long int  lev)
inlinestaticinherited

Definition at line 424 of file Debug.hh.

void BIAS::Debug::ShowDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

prints all internally known debuglevels

Author
woelk 09/2006

Definition at line 496 of file Debug.hh.

int LeastSquaresSVD::Solve ( Matrix< double > &  A,
Vector< double > &  b,
Vector< double > &  x 
)
virtual

LeastSquaresSVD.

solve |Ax-b|=min using svd with mxn Matrix A

|r|^2 = |Ax-b|^2 = (Ax-b)^T(Ax-b) = x^T A^T A x - x^T A^T b - b^T A x + b^T b = use x^T A^T b = b^T A x (both are real) = x^T A^T A x - 2 x^T A^T b + b^T b = use SVD(A^T A) := W S W^T since A^T A is symmetric = x^T W S W^T x - 2 x^T A^T b + b^T b = set z:=W^T x -> x=Wz or x^T = z^T W^T = z^T S z - 2 z^T W^T A^T b + b^T b = set d:= W^T A^T b = z^T S z - 2 z^T d + b^T b = = sum_i(S_i*z_i^2 - 2 z_i d_i + b_i^2)

d |r|^2 / dx = d|r|^2/dz * dz/dx == 0 -> d|r|^2/dz=0 -> z_i = d_i / S_i

x = W z

solve least squares using svd:

  1. calculate SVD(A^T A) = W S W^T
  2. calculate d = W^T A^T b
  3. calculate z: z_i = d_i/S_i
  4. calculate x = W z
Author
woelk 04 2003

Reimplemented from BIAS::LeastSquaresBase.

Examples:
ExampleLeastSquares.cpp.

Definition at line 172 of file LeastSquares.cpp.

References BIAS::Matrix< T >::Mult(), TNT::Matrix< T >::num_cols(), TNT::Matrix< T >::num_rows(), and BIAS::Matrix< T >::Transpose().

int LeastSquaresSVD::Solve ( Matrix< double > &  A,
Vector< double > &  x 
)
virtual

Solve linear equation system A*x = 0 using linear least squares, i.e.

minimize |A*x|^2, subject to |x| = 1.

Returns
Returns 0 in case of success, <0 otherwise.

Reimplemented from BIAS::LeastSquaresBase.

Definition at line 195 of file LeastSquares.cpp.

References General_singular_value_decomposition(), BIAS::Matrix< T >::Mult(), TNT::Vector< T >::newsize(), TNT::Vector< T >::size(), and BIAS::Matrix< T >::Transpose().

int LeastSquaresSVD::WeightedSolve ( Matrix< double > &  A,
Vector< double > &  b,
Vector< double > &  weights,
Vector< double > &  x 
)
virtual

Solve linear equation system A*x = b using weighted linear least squares, i.e.

minimize |W*(A*x - b)|^2 with diagonal matrix W composed of given weights.

Returns
Returns 0 in case of success, <0 otherwise.

Reimplemented from BIAS::LeastSquaresBase.

Examples:
ExampleLeastSquares.cpp.

Definition at line 225 of file LeastSquares.cpp.

int LeastSquaresSVD::WeightedSolve ( Matrix< double > &  A,
Vector< double > &  weights,
Vector< double > &  x 
)
virtual

Solve linear equation system A*x = 0 using weighted linear least squares, i.e.

minimize |W*(A*x - b)|^2 with diagonal matrix W composed of given weights, subject to |x| = 1.

Returns
Returns 0 in case of success, <0 otherwise.

Reimplemented from BIAS::LeastSquaresBase.

Definition at line 232 of file LeastSquares.cpp.

References General_singular_value_decomposition(), BIAS::Matrix< T >::Mult(), TNT::Vector< T >::newsize(), BIAS::Matrix< T >::ScaleRow(), TNT::Vector< T >::size(), and BIAS::Matrix< T >::Transpose().

Member Data Documentation

Matrix<double> BIAS::LeastSquaresBase::_AT
protectedinherited

Definition at line 92 of file LeastSquares.hh.

Matrix<double> BIAS::LeastSquaresBase::_ATA
protectedinherited

Definition at line 92 of file LeastSquares.hh.

Vector<double> BIAS::LeastSquaresBase::_ATb
protectedinherited

Definition at line 93 of file LeastSquares.hh.

long int BIAS::Debug::_liDebugLevel
protectedinherited

Definition at line 510 of file Debug.hh.

Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().

long int BIAS::Debug::_liNextDebugLevel
protectedinherited

new concept, debuglevel are managed here in the debug class

Definition at line 516 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

bool BIAS::LeastSquaresBase::_ReduceToATA
protectedinherited

Definition at line 90 of file LeastSquares.hh.

Vector<double> BIAS::LeastSquaresSVD::_S
protected

Definition at line 151 of file LeastSquares.hh.

unsigned BIAS::LeastSquaresBase::_SolutionSize
protectedinherited

Definition at line 91 of file LeastSquares.hh.

std::map<std::string, long int> BIAS::Debug::_String2Debuglevel
protectedinherited

Definition at line 517 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

SVD BIAS::LeastSquaresSVD::_svd
protected

Definition at line 149 of file LeastSquares.hh.

Matrix<double> BIAS::LeastSquaresSVD::_VT
protected

Definition at line 150 of file LeastSquares.hh.

Matrix<double> BIAS::LeastSquaresBase::_Weight
protectedinherited

Definition at line 92 of file LeastSquares.hh.

std::ostream BIAS::Debug::_zDebugStream
staticprotectedinherited

Definition at line 511 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

long int BIAS::Debug::GlobalDebugLevel = 0
staticprotectedinherited

Definition at line 513 of file Debug.hh.


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