STK++ 0.9.13
STK::IRegression< YArray, XArray, Weights > Class Template Referenceabstract

Interface base class for Regression methods. More...

#include <STK_IRegression.h>

Inheritance diagram for STK::IRegression< YArray, XArray, Weights >:
Inheritance graph

Public Member Functions

virtual ~IRegression ()
 virtual destructor.
 
YArray constpredicted () const
 
YArray constresiduals () const
 
YArrayp_predicted ()
 
YArrayp_residuals ()
 
int nbFreeParameter () const
 
virtual bool run ()
 run the computations.
 
virtual bool run (Weights const &weights)
 run the weighted computations.
 
virtual YArray extrapolate (XArray const &x) const =0
 
- 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.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Protected Types

typedef IRunnerSupervised< YArray, XArray, WeightsBase
 

Protected Member Functions

 IRegression ()
 Default constructor.
 
 IRegression (ArrayBase< YArray > const *p_y, ArrayBase< XArray > const *p_x)
 constructor
 
 IRegression (ArrayBase< YArray > const &y, ArrayBase< XArray > 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
 

Protected Attributes

YArray predicted_
 Container of the predicted output.
 
YArray 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 ()=0
 compute the regression function.
 
virtual bool regressionStep (Weights const &weights)=0
 compute the weighted regression function.
 
virtual bool predictionStep ()=0
 Compute the predicted outputs by the regression function and store the result in the p_predicted_ array.
 
virtual int computeNbFreeParameter () const =0
 Compute the number of parameter of the regression function.
 

Private Attributes

int nbFreeParameter_
 number of parameter of the regression method.
 

Detailed Description

template<class YArray, class XArray, class Weights>
class STK::IRegression< YArray, XArray, Weights >

Interface base class for Regression methods.

Regression models involve the following variables:

  • The unknown parameters, denoted as β, which may represent a scalar or a vector.
  • The independent variables, X.
  • The dependent variable, Y.

In various fields of application, different terminologies are used in place of dependent and independent variables. A regression model relates Y to a function of X and β. $ Y \approx f (\mathbf {X}, \boldsymbol{\beta} ) $

The approximation is usually formalized as $ E(Y|X)=f(X,\beta) $. To carry out regression analysis, the form of the function f must be specified. Sometimes the form of this function is based on knowledge about the relationship between Y and X that does not rely on the data. If no such knowledge is available, a flexible or convenient form for f is chosen.

Assume now that the vector of unknown parameters β is of length k. In order to perform a regression analysis the user must provide information about the dependent variable Y:

  • If N data points of the form (Y,X) are observed, where N < k, most classical approaches to regression analysis cannot be performed: since the system of equations defining the regression model is under-determined, there is not enough data to recover β. If exactly N=k data points are observed, and the function f is linear, the equations Y=f(X, β) can be solved exactly rather than approximately. This reduces to solving a set of N equations with N unknowns (the elements of β), which has a unique solution as long as the X are linearly independent. If f is nonlinear, a solution may not exist, or many solutions may exist.
  • The most common situation is where N > k data points are observed. In this case, there is enough information in the data to estimate a unique value for β that best fits the data in some sense, and the regression model when applied to the data can be viewed as an overdetermined system in β.

In the last case, the regression analysis provides the tools for: #- Finding a solution for unknown parameters β that will, for example, minimize the distance between the measured and predicted values of the dependent variable Y (also known as method of least squares). #- Under certain statistical assumptions, the regression analysis uses the surplus of information to provide statistical information about the unknown parameters β and predicted values of the dependent variable Y.

In this interface, the pure virtual function to implement are

virtual bool regressionStep()=0;
virtual bool regressionStep( Weights const& weights) =0;
virtual bool predictionStep() =0;
virtual int computeNbFreeParameter() const =0;
virtual bool extrapolate( XArray const& x, YArray& y) const =0;
virtual bool regressionStep()=0
compute the regression function.
virtual bool predictionStep()=0
Compute the predicted outputs by the regression function and store the result in the p_predicted_ arr...
virtual int computeNbFreeParameter() const =0
Compute the number of parameter of the regression function.
virtual YArray extrapolate(XArray const &x) const =0
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...

The virtual function

virtual void initializeStep();
virtual bool initializeStep()
perform any computation needed before the call of the regression method.

can be overloaded.

Definition at line 107 of file STK_IRegression.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ IRegression() [1/3]

STK::IRegression< YArray, XArray, Weights >::IRegression ( )
inlineprotected

Default constructor.

Initialize the data members.

Definition at line 114 of file STK_IRegression.h.

int nbFreeParameter_
number of parameter of the regression method.
YArray residuals_
Container of the residuals.
YArray predicted_
Container of the predicted output.
IRunnerSupervised< YArray, XArray, Weights > Base

◆ IRegression() [2/3]

STK::IRegression< YArray, XArray, Weights >::IRegression ( ArrayBase< YArray > const p_y,
ArrayBase< XArray > const p_x 
)
inlineprotected

constructor

Parameters
p_y,p_xpointers on the y and x data sets

Definition at line 118 of file STK_IRegression.h.

119 : Base((p_y == 0) ? 0 : p_y->asPtrDerived(), (p_x == 0) ? 0 : p_x->asPtrDerived())
120 , predicted_()
121 , residuals_()
123 {}

◆ IRegression() [3/3]

STK::IRegression< YArray, XArray, Weights >::IRegression ( ArrayBase< YArray > const y,
ArrayBase< XArray > const x 
)
inlineprotected

Constructor.

Initialize the data members.

Parameters
y,xarrays with the observed output and inputs of the model

Definition at line 127 of file STK_IRegression.h.

128 : Base(y.asDerived(), x.asDerived())
129 , predicted_()
130 , residuals_()
132 {}

◆ ~IRegression()

virtual destructor.

Definition at line 136 of file STK_IRegression.h.

136{}

Member Function Documentation

◆ computeNbFreeParameter()

virtual int STK::IRegression< YArray, XArray, Weights >::computeNbFreeParameter ( ) const
privatepure virtual

Compute the number of parameter of the regression function.

Returns
the number of parameter of the regression function

Implemented in STK::AdditiveBSplineRegression< YArray, XArray, Weights >, STK::BSplineRegression< YArray, XVector, Weights >, and STK::MultidimRegression< Array, Weight >.

◆ extrapolate()

virtual YArray STK::IRegression< YArray, XArray, Weights >::extrapolate ( XArray const x) const
pure virtual
Returns
the compute values of y from the value x using the model. Given the data set x will compute the values $ y = \hat{f}(x) $. The regression function f has to be estimated previously.
Parameters
xthe input data set

Implemented in STK::MultidimRegression< Array, Weight >, and STK::AdditiveBSplineRegression< YArray, XArray, Weights >.

◆ finalizeStep()

virtual bool STK::IRegression< YArray, XArray, Weights >::finalizeStep ( )
inlineprotectedvirtual

perform any computation needed after the call of the regression method.

Default implementation is do nothing.

Definition at line 172 of file STK_IRegression.h.

172{ return true;}

Referenced by STK::IMixtureBridge< Derived >::finalizeStep(), STK::MixtureComposer::finalizeStep(), and STK::MixtureLearner::finalizeStep().

◆ initializeStep()

virtual bool STK::IRegression< YArray, XArray, Weights >::initializeStep ( )
inlineprotectedvirtual

perform any computation needed before the call of the regression method.

Default implementation is do nothing.

Reimplemented in STK::AdditiveBSplineRegression< YArray, XArray, Weights >, and STK::BSplineRegression< YArray, XVector, Weights >.

Definition at line 168 of file STK_IRegression.h.

168{ return true;}

Referenced by STK::MixtureLearner::createLearner().

◆ nbFreeParameter()

int STK::IRegression< YArray, XArray, Weights >::nbFreeParameter ( ) const
inline
Returns
the number of parameter of the regression function

Definition at line 149 of file STK_IRegression.h.

149{ return nbFreeParameter_;}

References STK::IRegression< YArray, XArray, Weights >::nbFreeParameter_.

Referenced by STK::IMixtureStatModel::registerMixture().

◆ p_predicted()

YArray * STK::IRegression< YArray, XArray, Weights >::p_predicted ( )
inline
Returns
the pointer on the predicted values

Definition at line 144 of file STK_IRegression.h.

144{ return &predicted_;}

References STK::IRegression< YArray, XArray, Weights >::predicted_.

◆ p_residuals()

YArray * STK::IRegression< YArray, XArray, Weights >::p_residuals ( )
inline
Returns
the pointer on the residuals

Definition at line 146 of file STK_IRegression.h.

146{ return &residuals_;}

References STK::IRegression< YArray, XArray, Weights >::residuals_.

◆ predicted()

YArray const & STK::IRegression< YArray, XArray, Weights >::predicted ( ) const
inline
Returns
the predicted values

Definition at line 139 of file STK_IRegression.h.

139{ return predicted_;}

References STK::IRegression< YArray, XArray, Weights >::predicted_.

◆ predictionStep()

virtual bool STK::IRegression< YArray, XArray, Weights >::predictionStep ( )
privatepure virtual

Compute the predicted outputs by the regression function and store the result in the p_predicted_ array.

Implemented in STK::AdditiveBSplineRegression< YArray, XArray, Weights >, STK::BSplineRegression< YArray, XVector, Weights >, and STK::MultidimRegression< Array, Weight >.

◆ regressionStep() [1/2]

◆ regressionStep() [2/2]

virtual bool STK::IRegression< YArray, XArray, Weights >::regressionStep ( Weights const weights)
privatepure virtual

compute the weighted regression function.

Parameters
weightsthe weights of the samples

Implemented in STK::MultidimRegression< Array, Weight >, STK::AdditiveBSplineRegression< YArray, XArray, Weights >, and STK::BSplineRegression< YArray, XVector, Weights >.

◆ residuals()

YArray const & STK::IRegression< YArray, XArray, Weights >::residuals ( ) const
inline
Returns
the residuals

Definition at line 141 of file STK_IRegression.h.

141{ return residuals_;}

References STK::IRegression< YArray, XArray, Weights >::residuals_.

◆ residualsStep()

bool STK::IRegression< YArray, XArray, Weights >::residualsStep ( )
inlineprotected

Compute the residuals of the model.

The residuals of the model are computed by computing the difference between the observed outputs and the predicted outputs of the model.

Definition at line 177 of file STK_IRegression.h.

178 {
180 return true;
181 }
YArray const * p_y_
A pointer on the y data set.

References STK::IRunnerSupervised< YArray, XArray, Weights >::p_y_, STK::IRegression< YArray, XArray, Weights >::predicted_, and STK::IRegression< YArray, XArray, Weights >::residuals_.

◆ run() [1/2]

bool STK::IRegression< YArray, XArray, Weights >::run ( )
virtual

run the computations.

Default Implementation.

Implements STK::IRunnerSupervised< YArray, XArray, Weights >.

Definition at line 208 of file STK_IRegression.h.

209{
210 // perform any initialization step needed before the regression step
211 if (!initializeStep()) { return false;}
212 // compute the regression
213 if (!regressionStep()) { return false;}
214 // Compute the number of parameter of the regression function.
216 // compute predictions
218 // compute residuals
220 // perform any post-operation needed before the regression step
221 finalizeStep();
222 // return the result of the computations
223 this->hasRun_ = true;
224 return true;
225}
bool residualsStep()
Compute the residuals of the model.
virtual bool finalizeStep()
perform any computation needed after the call of the regression method.
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98

References STK::MultidimRegression< Array, Weight >::computeNbFreeParameter(), STK::IRegression< Array, Array, Weight >::finalizeStep(), STK::IRunnerBase::hasRun_, STK::IRegression< Array, Array, Weight >::initializeStep(), STK::IRegression< Array, Array, Weight >::nbFreeParameter_, STK::MultidimRegression< Array, Weight >::predictionStep(), STK::MultidimRegression< Array, Weight >::regressionStep(), and STK::IRegression< Array, Array, Weight >::residualsStep().

Referenced by STK::LocalVariance< Array >::computeAxis(), STK::ProjectedVariance< Array >::computeAxis(), STK::LocalVariance< Array >::computeCovarianceMatrices(), STK::LocalVariance< Array >::computeCovarianceMatrices(), STK::AdditiveBSplineRegression< YArray, XArray, Weights >::regressionStep(), STK::AdditiveBSplineRegression< YArray, XArray, Weights >::regressionStep(), STK::WeightedSvd< Array, WRows, WCols >::run(), STK::MultiLeastSquare< ArrayB, ArrayA >::runImpl(), STK::MultiLeastSquare< ArrayB, ArrayA >::runImpl(), and STK::MultiLaw::Normal< RowVector >::setParameters().

◆ run() [2/2]

bool STK::IRegression< YArray, XArray, Weights >::run ( Weights const weights)
virtual

run the weighted computations.

run the computations.

Parameters
weightsweights of the samples

Default Implementation.

Implements STK::IRunnerSupervised< YArray, XArray, Weights >.

Definition at line 229 of file STK_IRegression.h.

230{
231 // perform any pre-operation needed before the regression step
232 if (!initializeStep()) { return false;}
233 // compute weighted regression
234 if (!regressionStep(weights)) { return false;}
235 // Compute the number of parameter of the regression function.
237 // create array of the predicted value and compute prediction
239 // create array of the residuals and compute them
241 // perform any post-operation needed before the regression step
242 finalizeStep();
243 // return the result of the computations
244 this->hasRun_ = true;
245 return true;
246}

References STK::MultidimRegression< Array, Weight >::computeNbFreeParameter(), STK::IRegression< Array, Array, Weight >::finalizeStep(), STK::IRunnerBase::hasRun_, STK::IRegression< Array, Array, Weight >::initializeStep(), STK::IRegression< Array, Array, Weight >::nbFreeParameter_, STK::MultidimRegression< Array, Weight >::predictionStep(), STK::MultidimRegression< Array, Weight >::regressionStep(), and STK::IRegression< Array, Array, Weight >::residualsStep().

Member Data Documentation

◆ nbFreeParameter_

int STK::IRegression< YArray, XArray, Weights >::nbFreeParameter_
private

number of parameter of the regression method.

Definition at line 190 of file STK_IRegression.h.

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

◆ predicted_

◆ residuals_


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