STK++ 0.9.13
STK::ILeastSquare< Derived > Class Template Reference

The class ILeastSquare is an interface class for the methods solving the least-square problem. More...

#include <STK_ILeastSquare.h>

Inheritance diagram for STK::ILeastSquare< Derived >:
Inheritance graph

Public Member Functions

virtual ~ILeastSquare ()
 Destructor.
 
Integer constrank () const
 
ArrayA consta () const
 
ArrayB constb () const
 
ArrayB constx () const
 
virtual bool run ()
 Compute the Least-Square solution.
 
template<class VecWeights >
bool run (VecWeights const &weights)
 Compute the weighted Least-Square solution.
 
template<class Weights >
bool run (Weights const &weights)
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Protected Types

typedef hidden::AlgebraTraits< Derived >::ArrayB ArrayB
 
typedef hidden::AlgebraTraits< Derived >::ArrayA ArrayA
 

Protected Member Functions

 ILeastSquare (ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
 Default constructor.
 
template<class OtherArrayB , class OtherArrayA >
 ILeastSquare (ExprBase< OtherArrayB > const &b, ExprBase< OtherArrayA > const &a)
 template constructor
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Protected Attributes

ArrayB b_
 Array or vector of the left hand side.
 
ArrayA a_
 Array of the right hand side.
 
ArrayB x_
 Array of the solution (a vector if b is a vector, a matrix otherwise)
 
Integer rank_
 rank of matrix A
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

template<class Derived>
class STK::ILeastSquare< Derived >

The class ILeastSquare is an interface class for the methods solving the least-square problem.

\[
\min_{x} \|b - A*x\|^2.
\]

  • A is an m-by-n matrix which may be rank-deficient.
  • B can be a vector or a Matrix.

The least-square problem can be solved using the Svd or the QR decomposition of A.

Definition at line 57 of file STK_ILeastSquare.h.

Member Typedef Documentation

◆ ArrayA

template<class Derived >
typedef hidden::AlgebraTraits<Derived>::ArrayA STK::ILeastSquare< Derived >::ArrayA
protected

Definition at line 61 of file STK_ILeastSquare.h.

◆ ArrayB

template<class Derived >
typedef hidden::AlgebraTraits<Derived>::ArrayB STK::ILeastSquare< Derived >::ArrayB
protected

Definition at line 60 of file STK_ILeastSquare.h.

Constructor & Destructor Documentation

◆ ILeastSquare() [1/2]

template<class Derived >
STK::ILeastSquare< Derived >::ILeastSquare ( ArrayB const b,
ArrayA const a,
bool  isBref = false,
bool  isAref = false 
)
inlineprotected

Default constructor.

Parameters
b,athe left hand side and the right hand side of the least square problem.
isBref,isArefare the left hand side and the right hand side references ?

Definition at line 66 of file STK_ILeastSquare.h.

67 : b_(b, isBref), a_(a, isAref), rank_(0)
68 {
69 if (b.beginRows() != b.beginCols())
70 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: b.beginRows() must be equal to b.beginCols());
71 if (a.beginRows() != a.beginCols())
72 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to a.beginCols());
73 if (a.beginRows() != b.beginRows())
74 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to b.beginRows());
75 }
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
ArrayB b_
Array or vector of the left hand side.
Integer rank_
rank of matrix A
ArrayB const & b() const
ArrayA a_
Array of the right hand side.
ArrayA const & a() const
ILeastSquare(ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
Default constructor.

References STK::ILeastSquare< Derived >::a(), STK::ILeastSquare< Derived >::b(), STK::ILeastSquare< Derived >::ILeastSquare(), and STKRUNTIME_ERROR_NO_ARG.

Referenced by STK::ILeastSquare< Derived >::ILeastSquare(), and STK::ILeastSquare< Derived >::ILeastSquare().

◆ ILeastSquare() [2/2]

template<class Derived >
STK::ILeastSquare< Derived >::ILeastSquare ( ExprBase< OtherArrayB > const b,
ExprBase< OtherArrayA > const a 
)
inlineprotected

template constructor

Parameters
b,athe left hand side and the right hand side of the least square problem.

Definition at line 81 of file STK_ILeastSquare.h.

82 : b_(b), a_(a), rank_(0)
83 {
84 if (b.beginRows() != b.beginCols())
85 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: b.beginRows() must be equal to b.beginCols());
86 if (a.beginRows() != a.beginCols())
87 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to a.beginCols());
88 if (a.beginRows() != b.beginRows())
89 STKRUNTIME_ERROR_NO_ARG(ILeastSquare::ILeastSquare,Wrong data set: a.beginRows() must be equal to b.beginRows());
90 }

References STK::ILeastSquare< Derived >::a(), STK::ILeastSquare< Derived >::b(), STK::ILeastSquare< Derived >::ILeastSquare(), and STKRUNTIME_ERROR_NO_ARG.

◆ ~ILeastSquare()

template<class Derived >
virtual STK::ILeastSquare< Derived >::~ILeastSquare ( )
inlinevirtual

Destructor.

Definition at line 94 of file STK_ILeastSquare.h.

94{};

Member Function Documentation

◆ a()

template<class Derived >
ArrayA const & STK::ILeastSquare< Derived >::a ( ) const
inline
Returns
the matrix A

Definition at line 99 of file STK_ILeastSquare.h.

99{ return a_;}

References STK::ILeastSquare< Derived >::a_.

Referenced by STK::ILeastSquare< Derived >::ILeastSquare(), and STK::ILeastSquare< Derived >::ILeastSquare().

◆ b()

template<class Derived >
ArrayB const & STK::ILeastSquare< Derived >::b ( ) const
inline
Returns
the matrix B

Definition at line 101 of file STK_ILeastSquare.h.

101{ return b_;}

References STK::ILeastSquare< Derived >::b_.

Referenced by STK::ILeastSquare< Derived >::ILeastSquare(), and STK::ILeastSquare< Derived >::ILeastSquare().

◆ rank()

template<class Derived >
Integer const & STK::ILeastSquare< Derived >::rank ( ) const
inline
Returns
the rank of the matrix A

Definition at line 97 of file STK_ILeastSquare.h.

97{ return rank_;}

References STK::ILeastSquare< Derived >::rank_.

◆ run() [1/3]

template<class Derived >
bool STK::ILeastSquare< Derived >::run ( )
virtual

Compute the Least-Square solution.

Delegate to Derived classes the concrete computation of the decomposition using runImpl method.

Returns
true if the computation succeed, false otherwise

Implements STK::IRunnerBase.

Definition at line 130 of file STK_ILeastSquare.h.

131{
132 if (a_.empty()||b_.empty()) { return true;}
133 // compute Least Square
134 return(this->asDerived().runImpl());
135}
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.

Referenced by main().

◆ run() [2/3]

template<class Derived >
template<class VecWeights >
bool STK::ILeastSquare< Derived >::run ( VecWeights const weights)

Compute the weighted Least-Square solution.

Delegate to Derived classes the concrete computation of the decomposition using runImpl method.

Returns
true if the computation succeed, false otherwise

◆ run() [3/3]

template<class Derived >
template<class Weights >
bool STK::ILeastSquare< Derived >::run ( Weights const weights)

Definition at line 139 of file STK_ILeastSquare.h.

140{
141 if (a_.empty()||b_.empty()) { return true;}
142 // compute Least Square
143 return(this->asDerived().runImpl(weights));
144}

◆ x()

template<class Derived >
ArrayB const & STK::ILeastSquare< Derived >::x ( ) const
inline
Returns
the solution of the least-square problem

Definition at line 103 of file STK_ILeastSquare.h.

103{ return x_;}
ArrayB x_
Array of the solution (a vector if b is a vector, a matrix otherwise)

References STK::ILeastSquare< Derived >::x_.

Referenced by main().

Member Data Documentation

◆ a_

template<class Derived >
ArrayA STK::ILeastSquare< Derived >::a_
protected

Array of the right hand side.

Definition at line 122 of file STK_ILeastSquare.h.

Referenced by STK::ILeastSquare< Derived >::a().

◆ b_

template<class Derived >
ArrayB STK::ILeastSquare< Derived >::b_
protected

Array or vector of the left hand side.

Definition at line 120 of file STK_ILeastSquare.h.

Referenced by STK::ILeastSquare< Derived >::b().

◆ rank_

template<class Derived >
Integer STK::ILeastSquare< Derived >::rank_
protected

rank of matrix A

Definition at line 126 of file STK_ILeastSquare.h.

Referenced by STK::ILeastSquare< Derived >::rank().

◆ x_

template<class Derived >
ArrayB STK::ILeastSquare< Derived >::x_
protected

Array of the solution (a vector if b is a vector, a matrix otherwise)

Definition at line 124 of file STK_ILeastSquare.h.

Referenced by STK::ILeastSquare< Derived >::x().


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