STK++ 0.9.13
STK::AdditiveBSplineRegression< YArray, XArray, Weights > Class Template Reference

Compute an additive BSpline, multivalued, regression function using BSpline basis. More...

#include <STK_AdditiveBSplineRegression.h>

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

Public Types

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

Public Member Functions

 AdditiveBSplineRegression (YArray const *p_y, XArray const *p_x, int nbControlPoints, int degree=3, KnotsPosition const &position=Regress::uniformKnotsPositions_)
 Constructor.
 
 AdditiveBSplineRegression (YArray const &y, XArray const &x, int nbControlPoints, int degree=3, KnotsPosition const &position=Regress::uniformKnotsPositions_)
 Constructor.
 
virtual ~AdditiveBSplineRegression ()
 virtual destructor.
 
int degree () const
 
int nbControlPoints () const
 
YArray constcontrolPoints () const
 
ArrayXX constcoefficients () const
 This is a matrix of size (p_x_->range(), 0:lastControlPoints).
 
virtual YArray extrapolate (XArray 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.
 
- 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 weighted regression.
 
virtual bool predictionStep ()
 Compute the predicted outputs.
 
virtual int computeNbFreeParameter () const
 
- 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
 
AdditiveBSplineCoefficients< XArraycoefs_
 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 XArray, class Weights = VectorX>
class STK::AdditiveBSplineRegression< YArray, XArray, Weights >

Compute an additive BSpline, multivalued, regression function using BSpline basis.

Definition at line 56 of file STK_AdditiveBSplineRegression.h.

Member Typedef Documentation

◆ Base

◆ KnotsPosition

Constructor & Destructor Documentation

◆ AdditiveBSplineRegression() [1/2]

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

Constructor.

Parameters
p_yp-dimensional array of output to fit
p_xd-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 147 of file STK_AdditiveBSplineRegression.h.

154 : Base(p_y, p_x)
156 , degree_(degree)
157 , position_(position)
160{}
int nbControlPoints_
number of control points of the B-spline curve.
AdditiveBSplineCoefficients< XArray > coefs_
Coefficients of the regression matrix.
KnotsPosition position_
method of position of the knots of the B-spline curve
YArray controlPoints_
Estimated control points of the B-spline curve.
int degree_
degree of the B_Spline curve
IRegression< YArray, XArray, Weights > Base

◆ AdditiveBSplineRegression() [2/2]

STK::AdditiveBSplineRegression< YArray, XArray, Weights >::AdditiveBSplineRegression ( YArray const y,
XArray const x,
int  nbControlPoints,
int  degree = 3,
KnotsPosition const position = Regress::uniformKnotsPositions_ 
)

Constructor.

Parameters
yp-dimensional array of output to fit
xd-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 169 of file STK_AdditiveBSplineRegression.h.

175 : Base(&y, &x)
177 , degree_(degree)
178 , position_(position)
181{}

◆ ~AdditiveBSplineRegression()

virtual destructor.

Definition at line 92 of file STK_AdditiveBSplineRegression.h.

92{}

Member Function Documentation

◆ coefficients()

template<class YArray , class XArray , class Weights = VectorX>
ArrayXX const & STK::AdditiveBSplineRegression< YArray, XArray, Weights >::coefficients ( ) const
inline

This is a matrix of size (p_x_->range(), 0:lastControlPoints).

Returns
the coefficients of the B-spline curves

Definition at line 102 of file STK_AdditiveBSplineRegression.h.

102{ return coefs_.coefficients();}
ArrayXX const & coefficients() const
give the computed coefficients of the B-spline curves.

References STK::AdditiveBSplineCoefficients< Array >::coefficients(), and STK::AdditiveBSplineRegression< YArray, XArray, Weights >::coefs_.

◆ computeNbFreeParameter()

template<class YArray , class XArray , class Weights = VectorX>
virtual int STK::AdditiveBSplineRegression< YArray, XArray, Weights >::computeNbFreeParameter ( ) const
inlineprotectedvirtual
Returns
the number of parameter of the regression function

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

Definition at line 135 of file STK_AdditiveBSplineRegression.h.

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

References STK::AdditiveBSplineRegression< YArray, XArray, Weights >::controlPoints_.

◆ controlPoints()

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

Definition at line 98 of file STK_AdditiveBSplineRegression.h.

98{ return controlPoints_; }

References STK::AdditiveBSplineRegression< YArray, XArray, Weights >::controlPoints_.

◆ degree()

template<class YArray , class XArray , class Weights = VectorX>
int STK::AdditiveBSplineRegression< YArray, XArray, Weights >::degree ( ) const
inline
Returns
the degree of the B-spline curves

Definition at line 94 of file STK_AdditiveBSplineRegression.h.

94{ return degree_;}

References STK::AdditiveBSplineRegression< YArray, XArray, Weights >::degree_.

◆ extrapolate()

YArray STK::AdditiveBSplineRegression< YArray, XArray, Weights >::extrapolate ( XArray const x) const
virtual
Returns
The extrapolated 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

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

Definition at line 250 of file STK_AdditiveBSplineRegression.h.

251{
253 return res;
254}

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

◆ initializeStep()

bool STK::AdditiveBSplineRegression< YArray, XArray, Weights >::initializeStep ( )
protectedvirtual

compute the coefficients of the BSpline basis.

This method will be called in the base class IRegression::run()

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

Definition at line 187 of file STK_AdditiveBSplineRegression.h.

188{
190 if (!coefs_.run())
191 {
192 this->msg_error_ = coefs_.error();
193 return false;
194 }
195 return true;
196}
void setData(Array const *p_data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
Compute the coefficients of the B-spline curve for the given values.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
XArray const * p_x_
A pointer on the x data set.

References STK::MultidimRegression< Array, Weight >::coefs_, STK::IRunnerBase::msg_error_, and STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_x_.

◆ nbControlPoints()

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

Definition at line 96 of file STK_AdditiveBSplineRegression.h.

96{ return nbControlPoints_;}

References STK::AdditiveBSplineRegression< YArray, XArray, Weights >::nbControlPoints_.

◆ predictionStep()

bool STK::AdditiveBSplineRegression< YArray, XArray, Weights >::predictionStep ( )
protectedvirtual

Compute the predicted outputs.

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

Definition at line 237 of file STK_AdditiveBSplineRegression.h.

238{
240 return true;
241}
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::AdditiveBSplineRegression< YArray, XArray, Weights >::regressionStep ( )
protectedvirtual

Compute the regression function.

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

Definition at line 200 of file STK_AdditiveBSplineRegression.h.

201{
202 // coefs_.coefficients() is Array2D
203#ifdef STKUSELAPACK
204 lapack::MultiLeastSquare<YArray, ArrayXX> reg(*p_y_, coefs_.coefficients(), false, false);
205#else
206 MultiLeastSquare<YArray, ArrayXX> reg(*p_y_, coefs_.coefficients(), false, false);
207#endif
208 if (!reg.run())
209 {
210 this->msg_error_ = reg.error();
211 return false;
212 }
213 controlPoints_.move(reg.x());
214 return true;
215}
YArray const * p_y_
A pointer on the y data set.

References STK::MultidimRegression< Array, Weight >::coefs_, STK::IRunnerBase::error(), STK::IRunnerBase::msg_error_, STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, and STK::IRegression< YArray, XArray, Weights >::run().

◆ regressionStep() [2/2]

bool STK::AdditiveBSplineRegression< YArray, XArray, Weights >::regressionStep ( Weights const weights)
protectedvirtual

Compute the weighted regression.

Parameters
weightsweights of the samples

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

Definition at line 219 of file STK_AdditiveBSplineRegression.h.

220{
221#ifdef STKUSELAPACK
222 lapack::MultiLeastSquare<YArray, ArrayXX> reg(*p_y_, coefs_.coefficients(), false, false);
223#else
224 MultiLeastSquare<YArray, ArrayXX> reg(*p_y_, coefs_.coefficients(), false, false);
225#endif
226 if (!reg.run(weights))
227 {
228 this->msg_error_ = reg.error();
229 return false;
230 }
231 controlPoints_ = reg.x();
232 return true;
233}

References STK::MultidimRegression< Array, Weight >::coefs_, STK::IRunnerBase::error(), STK::IRunnerBase::msg_error_, STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::p_y_, and STK::IRegression< YArray, XArray, Weights >::run().

Member Data Documentation

◆ coefs_

◆ controlPoints_

◆ degree_

template<class YArray , class XArray , class Weights = VectorX>
int STK::AdditiveBSplineRegression< YArray, XArray, Weights >::degree_
protected

degree of the B_Spline curve

Definition at line 115 of file STK_AdditiveBSplineRegression.h.

Referenced by STK::AdditiveBSplineRegression< YArray, XArray, Weights >::degree().

◆ nbControlPoints_

template<class YArray , class XArray , class Weights = VectorX>
int STK::AdditiveBSplineRegression< YArray, XArray, Weights >::nbControlPoints_
protected

number of control points of the B-spline curve.

Definition at line 113 of file STK_AdditiveBSplineRegression.h.

Referenced by STK::AdditiveBSplineRegression< YArray, XArray, Weights >::nbControlPoints().

◆ position_

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

Definition at line 117 of file STK_AdditiveBSplineRegression.h.

◆ predicted_

template<class YArray , class XArray , 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 XArray , 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: