STK++ 0.9.13
STK::MultiLeastSquare< ArrayB, ArrayA > Class Template Reference

The class MultiLeastSQquare solve the least square problem when the response b is multidimensional. More...

#include <STK_MultiLeastSquare.h>

Inheritance diagram for STK::MultiLeastSquare< ArrayB, ArrayA >:
Inheritance graph

Public Types

typedef ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > > Base
 

Public Member Functions

 MultiLeastSquare (ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
 constructor
 
virtual ~MultiLeastSquare ()
 Destructor.
 
bool runImpl ()
 compute the multidimensional regression
 
template<class Weights >
bool runImpl (Weights const &weights)
 compute the weighted multidimensional regression
 
- Public Member Functions inherited from STK::ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > >
virtual ~ILeastSquare ()
 Destructor.
 
Integer constrank () const
 
ArrayA consta () const
 
ArrayB constb () const
 
ArrayB constx () const
 
virtual bool run ()
 Compute the Least-Square solution.
 
bool run (VecWeights const &weights)
 Compute the weighted Least-Square solution.
 
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.
 

Additional Inherited Members

- Protected Types inherited from STK::ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > >
typedef hidden::AlgebraTraits< MultiLeastSquare< ArrayB, ArrayA > >::ArrayB ArrayB
 
typedef hidden::AlgebraTraits< MultiLeastSquare< ArrayB, ArrayA > >::ArrayA ArrayA
 
- Protected Member Functions inherited from STK::ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > >
 ILeastSquare (ArrayB const &b, ArrayA const &a, bool isBref=false, bool isAref=false)
 Default constructor.
 
 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 inherited from STK::ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > >
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 ArrayB, class ArrayA>
class STK::MultiLeastSquare< ArrayB, ArrayA >

The class MultiLeastSQquare solve the least square problem when the response b is multidimensional.

The class MultiLeastSquare allows to solve 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.

It computes the minimum-norm solution to a real linear least squares problem: minimize 2-norm(| b - A*x |) using the singular value decomposition (SVD) of A. A is an M-by-N matrix which may be rank-deficient.

See also
ILeastSquare, lapack::MultiLeastSquare

Definition at line 80 of file STK_MultiLeastSquare.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ MultiLeastSquare()

template<class ArrayB , class ArrayA >
STK::MultiLeastSquare< ArrayB, ArrayA >::MultiLeastSquare ( ArrayB const b,
ArrayA const a,
bool  isBref = false,
bool  isAref = false 
)
inline

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 92 of file STK_MultiLeastSquare.h.

93 : Base(b, a, isBref, isAref) {}
ILeastSquare< MultiLeastSquare< ArrayB, ArrayA > > Base

◆ ~MultiLeastSquare()

Destructor.

Definition at line 95 of file STK_MultiLeastSquare.h.

95{};

Member Function Documentation

◆ runImpl() [1/2]

compute the multidimensional regression

Definition at line 104 of file STK_MultiLeastSquare.h.

105{
106 // compute a'a
107 ArraySquareX prod = a_.transpose() * a_;
108 // compute (a'a)^{-1}
109 SymEigen<ArraySquareX> decomp(prod);
110 decomp.run();
111 rank_ = decomp.rank();
112 // compute (a'a)^{-1}b'a
113 if (a_.sizeRows() < b_.sizeCols())
114 { x_ = (decomp.ginv(prod) * a_.transpose()) * b_;}
115 else
116 { x_ = decomp.ginv(prod) * (a_.transpose() * b_);}
117 return true;
118}
TransposeOperator< Derived > const transpose() const
ArrayB b_
Array or vector of the left hand side.
ArrayB x_
Array of the solution (a vector if b is a vector, a matrix otherwise)
Array2DSquare< Real > ArraySquareX

References STK::IRegression< YArray, XArray, Weights >::run(), and STK::ArrayBase< Derived >::transpose().

◆ runImpl() [2/2]

template<class ArrayB , class ArrayA >
template<class Weights >
bool STK::MultiLeastSquare< ArrayB, ArrayA >::runImpl ( Weights const weights)

compute the weighted multidimensional regression

Definition at line 123 of file STK_MultiLeastSquare.h.

124{
126 // compute a'a
127 CSquareX prod = a_.transpose() * weights.diagonalize() * a_;
128 // compute (a'a)^{-1}
129 SymEigen<CSquareX> decomp(prod);
130 decomp.run();
131 rank_ = decomp.rank();
132 // compute (a'a)^{-1}b'a
133 if (a_.sizeRows() < b_.sizeCols())
134 { x_ = (decomp.ginv(prod) * a_.transpose()) * weights.diagonalize() * b_;}
135 else
136 { x_ = decomp.ginv(prod) * (a_.transpose() * weights.diagonalize() * b_);}
137 return true;
138}
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
CArraySquare< Real, UnknownSize, Arrays::by_col_ > CSquareX

References STK::IRegression< YArray, XArray, Weights >::run(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STK::ArrayBase< Derived >::transpose().


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