STK++ 0.9.13
STK::MultidimRegression< Array, Weight > Class Template Reference

The MultidimRegression class allows to regress a multidimensional output variable among a multivariate explanation variable. More...

#include <STK_MultidimRegression.h>

Inheritance diagram for STK::MultidimRegression< Array, Weight >:
Inheritance graph

Public Types

typedef IRegression< Array, Array, Weight > Base

Public Member Functions

 MultidimRegression (Array const *y=0, Array const *x=0)
 Constructor.
virtual ~MultidimRegression ()
 Destructor.
Array const & coefs () const
virtual Array extrapolate (Array const &x) const
Public Member Functions inherited from STK::IRegression< Array, Array, Weight >
virtual ~IRegression ()
 virtual destructor.
Array const & predicted () const
Array const & residuals () const
Array * p_predicted ()
Array * p_residuals ()
int nbFreeParameter () const
virtual bool run ()
 run the computations.
virtual bool run (Weight const &weights)
 run the weighted computations.
Public Member Functions inherited from STK::IRunnerSupervised< YArray_, XArray_, Weights_ >
virtual void setX (XArray_ const &x)
 set the x data set (predictors).
virtual void setY (YArray_ const &y)
 set the data set.
virtual void setData (YArray_ const &y, XArray_ const &x)
 set the data set.
virtual bool run (Weights_ const &weights)=0
 run the weighted computations.
Public Member Functions inherited from STK::IRunnerBase
String const & error () const
 get the last error message.

Public Attributes

Array const * p_x_
 A pointer on the x data set.
Array const * p_y_
 A pointer on the y data set.

Protected Attributes

ArrayXX coefs_
Protected Attributes inherited from STK::IRegression< Array, Array, Weight >
Array predicted_
 Container of the predicted output.
Array residuals_
 Container of the residuals.
Array const * p_x_
 A pointer on the x data set.
Array const * p_y_
 A pointer on the y data set.
Protected Attributes inherited from STK::IRunnerSupervised< YArray_, XArray_, Weights_ >
YArray_ const * p_y_
 A pointer on the y data set.
XArray_ const * p_x_
 A pointer on the x data set.
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

Private Member Functions

virtual bool regressionStep ()
 compute the regression function.
virtual bool regressionStep (Weight const &weights)
 compute the weighted regression function.
virtual bool predictionStep ()
 Compute the predicted outputs by the regression function.
virtual int computeNbFreeParameter () const
 Compute the number of parameter of the regression function.

Additional Inherited Members

Protected Types inherited from STK::IRegression< Array, Array, Weight >
typedef IRunnerSupervised< Array, Array, Weight > Base
Protected Member Functions inherited from STK::IRegression< Array, Array, Weight >
 IRegression ()
 Default constructor.
 IRegression (ArrayBase< Array > const *p_y, ArrayBase< Array > const *p_x)
 constructor
 IRegression (ArrayBase< Array > const &y, ArrayBase< Array > const &x)
 Constructor.
virtual bool initializeStep ()
 perform any computation needed before the call of the regression method.
virtual bool finalizeStep ()
 perform any computation needed after the call of the regression method.
bool residualsStep ()
 Compute the residuals of the model.
Protected Member Functions inherited from STK::IRunnerSupervised< YArray_, XArray_, Weights_ >
 IRunnerSupervised ()
 default constructor
 IRunnerSupervised (YArray_ const *const &p_y, XArray_ const *const &p_x)
 constructor
 IRunnerSupervised (YArray_ const &y, XArray_ const &x)
 default constructor
 IRunnerSupervised (IRunnerSupervised const &runner)
 copy constructor
 ~IRunnerSupervised ()
 destructor
virtual void updateY ()
 update the runner when y data set is set.
virtual void updateX ()
 update the runner when x data set is set.
virtual void update ()
 update the runner.
Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
virtual ~IRunnerBase ()
 destructor

Detailed Description

template<class Array, class Weight>
class STK::MultidimRegression< Array, Weight >

The MultidimRegression class allows to regress a multidimensional output variable among a multivariate explanation variable.

Definition at line 51 of file STK_MultidimRegression.h.

Member Typedef Documentation

◆ Base

template<class Array, class Weight>
typedef IRegression<Array, Array, Weight> STK::MultidimRegression< Array, Weight >::Base

Definition at line 54 of file STK_MultidimRegression.h.

Constructor & Destructor Documentation

◆ MultidimRegression()

template<class Array, class Weight>
STK::MultidimRegression< Array, Weight >::MultidimRegression ( Array const * y = 0,
Array const * x = 0 )

Constructor.

Parameters
y,xVariates to predict and co-variates

Definition at line 92 of file STK_MultidimRegression.h.

93 : Base(y, x)
94 , coefs_()
95{}
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
IRegression< Array, Array, Weight > Base

References coefs_.

◆ ~MultidimRegression()

template<class Array, class Weight>
virtual STK::MultidimRegression< Array, Weight >::~MultidimRegression ( )
inlinevirtual

Destructor.

Definition at line 62 of file STK_MultidimRegression.h.

62{}

Member Function Documentation

◆ coefs()

template<class Array, class Weight>
Array const & STK::MultidimRegression< Array, Weight >::coefs ( ) const
inline
Returns
the coefficients

Definition at line 64 of file STK_MultidimRegression.h.

64{ return coefs_;}

References coefs_.

◆ computeNbFreeParameter()

template<class Array, class Weight>
virtual int STK::MultidimRegression< Array, Weight >::computeNbFreeParameter ( ) const
inlineprivatevirtual

Compute the number of parameter of the regression function.

Returns
the number of parameter of the regression function

Implements STK::IRegression< Array, Array, Weight >.

Definition at line 87 of file STK_MultidimRegression.h.

88 { return coefs_.sizeCols() * coefs_.sizeRows(); }

References coefs_.

◆ extrapolate()

template<class Array, class Weight>
Array STK::MultidimRegression< Array, Weight >::extrapolate ( Array const & x) const
virtual
Returns
the extrapolated values y from the value x. Given the data set x will compute the values $ y = x.\hat{\beta} $. The coefficients coefs_ have to be estimated previously.
Parameters
xthe input data set

Implements STK::IRegression< Array, Array, Weight >.

Definition at line 137 of file STK_MultidimRegression.h.

138{ return(mult(x, coefs_));}
Arrays::MultOp< Lhs, Rhs >::result_type mult(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices

References coefs_, and STK::mult().

◆ predictionStep()

template<class Array, class Weight>
bool STK::MultidimRegression< Array, Weight >::predictionStep ( )
privatevirtual

Compute the predicted outputs by the regression function.

Implements STK::IRegression< Array, Array, Weight >.

Definition at line 129 of file STK_MultidimRegression.h.

130{ this->predicted_.move(mult(*p_x_, coefs_)); return true;}
Array const * p_x_
A pointer on the x data set.

References coefs_, STK::mult(), p_x_, and STK::IRegression< Array, Array, Weight >::predicted_.

◆ regressionStep() [1/2]

template<class Array, class Weight>
bool STK::MultidimRegression< Array, Weight >::regressionStep ( )
privatevirtual

compute the regression function.

Implements STK::IRegression< Array, Array, Weight >.

Definition at line 99 of file STK_MultidimRegression.h.

100{
101 // compute X'X
103 prod.move(multLeftTranspose(p_x_->asDerived()));
104 // compute (X'X)^{-1}
105// GInvertSymMatrix<ArraySquareX>()(prod);
106 // compute (X'X)^{-1}X'Y
107 coefs_.move(mult(invert(prod.symmetrize()), multLeftTranspose(p_x_->asDerived(), p_y_->asDerived())));
108 //coefs_.move(mult(prod, multLeftTranspose(p_x_->asDerived(), p_y_->asDerived())));
109 return true;
110}
Array const * p_y_
A pointer on the y data set.
hidden::AlgebraTraits< InvertMatrix< Matrix, hidden::Traits< Matrix >::sizeRows_ > >::Result invert(Matrix const &mat)
Utility function allowing to compute the inverse of a matrix.
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type multLeftTranspose(Lhs const &lhs, Rhs const &rhs)
convenience function for the multiplication of two matrices

References coefs_, STK::invert(), STK::IArray2D< Derived >::move(), STK::mult(), STK::multLeftTranspose(), p_x_, p_y_, and STK::ArrayBase< Derived >::symmetrize().

◆ regressionStep() [2/2]

template<class Array, class Weight>
bool STK::MultidimRegression< Array, Weight >::regressionStep ( Weight const & weights)
privatevirtual

compute the weighted regression function.

Parameters
weightsthe weights of the samples

Implements STK::IRegression< Array, Array, Weight >.

Definition at line 114 of file STK_MultidimRegression.h.

115{
116 // compute X'WX
118 prod.move(weightedMultLeftTranspose(p_x_->asDerived(), weights));
119 // compute (X'WX)^{-1}
120 //GInvertSymMatrix<ArraySquareX>()(prod);
121 // compute (X'WX)^{-1}X'WY
122 coefs_.move(mult(invert(prod.symmetrize()), wmultLeftTranspose(p_x_->asDerived(), p_y_->asDerived(), weights)));
123// coefs_.move(mult(prod, wmultLeftTranspose(p_x_->asDerived(), p_y_->asDerived(), weights)));
124 return true;
125}
Array2DSquare< typename Derived::Type > weightedMultLeftTranspose(ExprBase< Derived > const &A, ExprBase< Weights > const &weights)
Weighted matrix multiplication by its transpose.

References coefs_, STK::invert(), STK::IArray2D< Derived >::move(), STK::mult(), p_x_, p_y_, STK::ArrayBase< Derived >::symmetrize(), STK::weightedMultLeftTranspose(), and STK::wmultLeftTranspose().

Member Data Documentation

◆ coefs_

template<class Array, class Weight>
ArrayXX STK::MultidimRegression< Array, Weight >::coefs_
protected

◆ p_x_

template<class Array, class Weight>

A pointer on the x data set.

Referenced by predictionStep(), regressionStep(), and regressionStep().

◆ p_y_

template<class Array, class Weight>

A pointer on the y data set.

Referenced by regressionStep(), and regressionStep().


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