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, WeightBase
 

Public Member Functions

 MultidimRegression (Array const *y=0, Array const *x=0)
 Constructor.
 
virtual ~MultidimRegression ()
 Destructor.
 
Array constcoefs () const
 
virtual Array extrapolate (Array const &x) const
 
- Public Member Functions inherited from STK::IRegression< Array, Array, Weight >
virtual ~IRegression ()
 virtual destructor.
 
Array constpredicted () const
 
Array constresiduals () 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 consterror () const
 get the last error message.
 

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.
 
- Protected Attributes inherited from STK::IRunnerSupervised< YArray_, XArray_, Weights_ >
YArray_ constp_y_
 A pointer on the y data set.
 
XArray_ constp_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, WeightBase
 
- 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{}
IRegression< Array, Array, Weight > Base

◆ ~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 STK::MultidimRegression< Array, Weight >::coefs_.

Referenced by STK::BSplineCoefficients< Data >::extrapolate().

◆ 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(); }
int sizeRows() const
int sizeCols() const

References STK::MultidimRegression< Array, Weight >::coefs_, STK::IArray2D< Derived >::sizeCols(), and STK::IArray2D< Derived >::sizeRows().

Referenced by STK::IRegression< YArray, XArray, Weights >::run(), and STK::IRegression< YArray, XArray, Weights >::run().

◆ 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 STK::MultidimRegression< Array, Weight >::coefs_, and STK::mult().

Referenced by STK::AdditiveBSplineCoefficients< Array >::extrapolate().

◆ predictionStep()

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

◆ 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
102 ArraySquareX prod;
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}
Derived & move(Derived const &T)
move T to this.
YArray_ 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
Array2DSquare< Real > ArraySquareX

References STK::MultidimRegression< Array, Weight >::coefs_, STK::invert(), STK::IArray2D< Derived >::move(), STK::mult(), STK::multLeftTranspose(), STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_x_, STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, and STK::ArrayBase< Derived >::symmetrize().

Referenced by STK::LinearAAModel< Array >::run(), STK::IRegression< YArray, XArray, Weights >::run(), STK::LinearAAModel< Array >::run(), and STK::IRegression< YArray, XArray, Weights >::run().

◆ 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
117 ArraySquareX prod;
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.
Arrays::MultLeftTransposeOp< Lhs, Rhs >::result_type wmultLeftTranspose(Lhs const &lhs, Rhs const &rhs, Weights const &weights)
convenience function for the multiplication of two matrices

References STK::MultidimRegression< Array, Weight >::coefs_, STK::invert(), STK::IArray2D< Derived >::move(), STK::mult(), STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_x_, STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, STK::ArrayBase< Derived >::symmetrize(), STK::weightedMultLeftTranspose(), and STK::wmultLeftTranspose().

Member Data Documentation

◆ coefs_


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