STK++ 0.9.13
STK::BSplineRegression< YArray, XVector, Weights > Class Template Reference

Compute a BSpline, multi-valued, regression function using BSpline basis. More...

#include <STK_BSplineRegression.h>

Inheritance diagram for STK::BSplineRegression< YArray, XVector, Weights >:
Inheritance graph

Public Types

typedef IRegression< YArray, XVector, WeightsBase
 
typedef Regress::KnotsPosition KnotsPosition
 

Public Member Functions

 BSplineRegression (YArray const *p_y, XVector const *p_x, int const &nbControlPoints, int const &degree=3, KnotsPosition const &position=Regress::uniformKnotsPositions_)
 Constructor.
 
virtual ~BSplineRegression ()
 virtual destructor.
 
int degree () const
 
int nbControlPoints () const
 
YArray constcontrolPoints () const
 
VectorX constknots () const
 
YArray constcoefficients () const
 
virtual YArray extrapolate (XVector const &x) const
 
- Public Member Functions inherited from STK::IRegression< YArray, XArray, Weights >
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.
 

Public Attributes

YArray predicted_
 Container of the predicted output.
 
YArray residuals_
 Container of the residuals.
 

Protected Member Functions

virtual bool initializeStep ()
 Compute the coefficients of the BSpline basis.
 
virtual bool regressionStep ()
 Compute the regression function.
 
virtual bool regressionStep (Weights const &weights)
 Compute the 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.
 
- Protected Member Functions inherited from STK::IRegression< YArray, XArray, Weights >
 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 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

int nbControlPoints_
 number of control points of the B-spline curve.
 
int degree_
 degree of the B_Spline curve
 
KnotsPosition position_
 method of position of the knots of the B-spline curve
 
BSplineCoefficients< XVectorcoefs_
 Coefficients of the regression matrix.
 
YArray controlPoints_
 Estimated control points of the B-spline curve.
 
- Protected Attributes inherited from STK::IRegression< YArray, XArray, Weights >
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
 

Additional Inherited Members

- Protected Types inherited from STK::IRegression< YArray, XArray, Weights >
typedef IRunnerSupervised< YArray, XArray, WeightsBase
 

Detailed Description

template<class YArray, class XVector, class Weights = VectorX>
class STK::BSplineRegression< YArray, XVector, Weights >

Compute a BSpline, multi-valued, regression function using BSpline basis.

Definition at line 51 of file STK_BSplineRegression.h.

Member Typedef Documentation

◆ Base

◆ KnotsPosition

Constructor & Destructor Documentation

◆ BSplineRegression()

STK::BSplineRegression< YArray, XVector, Weights >::BSplineRegression ( YArray const p_y,
XVector const p_x,
int const nbControlPoints,
int const degree = 3,
KnotsPosition const position = Regress::uniformKnotsPositions_ 
)

Constructor.

Parameters
p_yd-dimensional array of output to fit
p_xuni-dimensional array of predictor
nbControlPointsnumber of control points of the spline
degreedegree of the BSpline basis
positionposition of the knots to used

Definition at line 129 of file STK_BSplineRegression.h.

135 : Base(p_y, p_x)
137 , degree_(degree)
138 , position_(position)
141{ }
int degree_
degree of the B_Spline curve
BSplineCoefficients< XVector > coefs_
Coefficients of the regression matrix.
YArray controlPoints_
Estimated control points of the B-spline curve.
IRegression< YArray, XVector, Weights > Base
int nbControlPoints_
number of control points of the B-spline curve.
KnotsPosition position_
method of position of the knots of the B-spline curve

◆ ~BSplineRegression()

virtual destructor.

Definition at line 144 of file STK_BSplineRegression.h.

145{}

Member Function Documentation

◆ coefficients()

template<class YArray , class XVector , class Weights = VectorX>
YArray const & STK::BSplineRegression< YArray, XVector, Weights >::coefficients ( ) const
inline
Returns
the coefficients of the B-spline curve

Definition at line 84 of file STK_BSplineRegression.h.

84{ return coefs_.coefficients();}
Coefs const & coefficients() const
Definition STK_IBasis.h:79

References STK::IBasis< Data, Coefs >::coefficients(), and STK::BSplineRegression< YArray, XVector, Weights >::coefs_.

◆ computeNbFreeParameter()

template<class YArray , class XVector , class Weights = VectorX>
virtual int STK::BSplineRegression< YArray, XVector, Weights >::computeNbFreeParameter ( ) const
inlineprotectedvirtual

Compute the number of parameter of the regression function.

Returns
the number of parameter of the regression function

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

Definition at line 124 of file STK_BSplineRegression.h.

125 { return controlPoints_.sizeCols() * controlPoints_.sizeRows(); }

References STK::BSplineRegression< YArray, XVector, Weights >::controlPoints_.

◆ controlPoints()

template<class YArray , class XVector , class Weights = VectorX>
YArray const & STK::BSplineRegression< YArray, XVector, Weights >::controlPoints ( ) const
inline
Returns
the control points of the B-spline curve

Definition at line 80 of file STK_BSplineRegression.h.

80{ return controlPoints_; }

References STK::BSplineRegression< YArray, XVector, Weights >::controlPoints_.

◆ degree()

template<class YArray , class XVector , class Weights = VectorX>
int STK::BSplineRegression< YArray, XVector, Weights >::degree ( ) const
inline
Returns
the degree of the B-spline curve

Definition at line 76 of file STK_BSplineRegression.h.

76{ return degree_;}

References STK::BSplineRegression< YArray, XVector, Weights >::degree_.

◆ extrapolate()

YArray STK::BSplineRegression< YArray, XVector, Weights >::extrapolate ( XVector const x) const
virtual
Returns
the Extrapolates values of y from the value x. Given the data set x will compute the values $ y = \psi(x) \hat{\beta} $ where $ \psi $ represents the B-spline basis functions and $ \hat{beta} $ the estimated coefficients.
Parameters
xthe input data set

Definition at line 195 of file STK_BSplineRegression.h.

196{
198 return res;
199}
ArrayXX extrapolate(OtherVector const &x) const

References STK::MultidimRegression< Array, Weight >::coefs_.

◆ initializeStep()

bool STK::BSplineRegression< YArray, XVector, Weights >::initializeStep ( )
protectedvirtual

Compute the coefficients of the BSpline basis.

This method is triggered by the base class IRegression::run()

Reimplemented from STK::IRegression< YArray, XArray, Weights >.

Definition at line 148 of file STK_BSplineRegression.h.

149{ return coefs_.run();}
virtual bool run()
run the computations.

References STK::MultidimRegression< Array, Weight >::coefs_.

◆ knots()

template<class YArray , class XVector , class Weights = VectorX>
VectorX const & STK::BSplineRegression< YArray, XVector, Weights >::knots ( ) const
inline
Returns
the knots of the B-spline curve

Definition at line 82 of file STK_BSplineRegression.h.

82{ return coefs_.knots(); }
VectorX const & knots() const

References STK::BSplineRegression< YArray, XVector, Weights >::coefs_, and STK::BSplineCoefficients< Data >::knots().

◆ nbControlPoints()

template<class YArray , class XVector , class Weights = VectorX>
int STK::BSplineRegression< YArray, XVector, Weights >::nbControlPoints ( ) const
inline
Returns
the number of control points of the B-spline curve

Definition at line 78 of file STK_BSplineRegression.h.

78{ return nbControlPoints_;}

References STK::BSplineRegression< YArray, XVector, Weights >::nbControlPoints_.

◆ predictionStep()

bool STK::BSplineRegression< YArray, XVector, Weights >::predictionStep ( )
protectedvirtual

Compute the predicted outputs by the regression function.

This method is triggered by the base class IRegression::run() after initializeStep()

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

Definition at line 182 of file STK_BSplineRegression.h.

183{
185 return true;
186}
YArray predicted_
Container of the predicted output.

References STK::MultidimRegression< Array, Weight >::coefs_, and STK::IRegression< Array, Array, Weight >::predicted_.

◆ regressionStep() [1/2]

bool STK::BSplineRegression< YArray, XVector, Weights >::regressionStep ( )
protectedvirtual

Compute the regression function.

This method is triggered by the base class IRegression::run() after initializeStep()

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

Definition at line 152 of file STK_BSplineRegression.h.

153{
154 // compute X'X
155 ArraySquareX prod = coefs_.coefficients().transpose() * coefs_.coefficients();
156 // compute (X'X)^{-1}
157// GInvertSymMatrix<ArraySquareX> inv;
158// inv(prod);
159
160 // compute (X'X)^{-1}X'Y
161 controlPoints_ = invert(prod.symmetrize()) * (coefs_.coefficients().transpose() * p_y_->asDerived());
162 return true;
163}
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.
Array2DSquare< Real > ArraySquareX

References STK::MultidimRegression< Array, Weight >::coefs_, STK::invert(), STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, STK::ArrayBase< Derived >::symmetrize(), and STK::ArrayBase< Derived >::transpose().

◆ regressionStep() [2/2]

bool STK::BSplineRegression< YArray, XVector, Weights >::regressionStep ( Weights const weights)
protectedvirtual

Compute the regression function.

This method is triggered by the base class IRegression::run(weights) after initializeStep()

Parameters
weightsthe weights of the samples

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

Definition at line 167 of file STK_BSplineRegression.h.

168{
169 // compute X'X
170 ArraySquareX prod = coefs_.coefficients().transpose() * weights.diagonalize() * coefs_.coefficients();
171 // compute (X'X)^{-1}
172 // GInvertSymMatrix<ArraySquareX> inv;
173 // inv(prod);
174 // compute (X'X)^{-1}X'Y
175 controlPoints_ = invert(prod.symmetrize()) * coefs_.coefficients().transpose() * weights.diagonalize() * p_y_->asDerived();
176 //controlPoints_ = prod * coefs_.coefficients().transpose() * weights.diagonalize() * p_y_->asDerived();
177 return true;
178}

References STK::MultidimRegression< Array, Weight >::coefs_, STK::invert(), STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, STK::ArrayBase< Derived >::symmetrize(), and STK::ArrayBase< Derived >::transpose().

Member Data Documentation

◆ coefs_

◆ controlPoints_

◆ degree_

template<class YArray , class XVector , class Weights = VectorX>
int STK::BSplineRegression< YArray, XVector, Weights >::degree_
protected

degree of the B_Spline curve

Definition at line 97 of file STK_BSplineRegression.h.

Referenced by STK::BSplineRegression< YArray, XVector, Weights >::degree().

◆ nbControlPoints_

template<class YArray , class XVector , class Weights = VectorX>
int STK::BSplineRegression< YArray, XVector, Weights >::nbControlPoints_
protected

number of control points of the B-spline curve.

Definition at line 95 of file STK_BSplineRegression.h.

Referenced by STK::BSplineRegression< YArray, XVector, Weights >::nbControlPoints().

◆ position_

template<class YArray , class XVector , class Weights = VectorX>
KnotsPosition STK::BSplineRegression< YArray, XVector, Weights >::position_
protected

method of position of the knots of the B-spline curve

Definition at line 99 of file STK_BSplineRegression.h.

◆ predicted_

template<class YArray , class XVector , class Weights = VectorX>
YArray STK::IRegression< YArray, XArray, Weights >::predicted_

Container of the predicted output.

Definition at line 184 of file STK_IRegression.h.

◆ residuals_

template<class YArray , class XVector , class Weights = VectorX>
YArray STK::IRegression< YArray, XArray, Weights >::residuals_

Container of the residuals.

Definition at line 186 of file STK_IRegression.h.


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