STK++ 0.9.13
STK::AdditiveBSplineCoefficients< Array > Class Template Reference

Compute the regression splines coefficients of an additive model. More...

#include <STK_AdditiveBSplineCoefficients.h>

Inheritance diagram for STK::AdditiveBSplineCoefficients< Array >:
Inheritance graph

Public Types

typedef hidden::Traits< Array >::Row RowVector
 
typedef hidden::Traits< Array >::Col ColVector
 

Public Member Functions

 AdditiveBSplineCoefficients (Array const *p_data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
 Constructor : initialize the data members.
 
 AdditiveBSplineCoefficients (Array const &data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
 Constructor : initialize the data members.
 
 AdditiveBSplineCoefficients (AdditiveBSplineCoefficients const &coefs)
 Copy constructor.
 
virtual ~AdditiveBSplineCoefficients ()
 Destructor.
 
AdditiveBSplineCoefficientsclone () const
 clone pattern implementation
 
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.
 
bool run ()
 run the computations.
 
int degree () const
 give the degree of the B-spline curves.
 
int nbKnots () const
 give the number of knots of the B-spline curves.
 
int nbControlPoints () const
 give the number of control points of the B-spline curves.
 
ArrayXX constcoefficients () const
 give the computed coefficients of the B-spline curves.
 
ArrayXX extrapolate (Array const &x) const
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Protected Attributes

Array constp_data_
 the input data set
 
int nbKnots_
 number of knots of the B-spline curves.
 
int nbControlPoints_
 number of control points of the B-spline curves.
 
int degree_
 degree of the B-splines curves.
 
Regress::KnotsPosition position_
 Method used in order to position the knots.
 
Array1D< BSplineCoefficients< ColVector > > coefs_
 Array with the knots and coefficients in each dimension.
 
ArrayXX coefficients_
 Array of the coefficients.
 
- 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 Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 

Detailed Description

template<class Array>
class STK::AdditiveBSplineCoefficients< Array >

Compute the regression splines coefficients of an additive model.

The method is described in BSplineCoefficients documentation class and repeated for each variables of the model. The number of control points, the degree and the position of the knots are the same for all variables.

If the input data set is a matrix of size (n,p) then the output matrix of the coefficients Coefficients() is a matrix of size (n, p*nbControlPoints) where p is the number of variables.

Definition at line 56 of file STK_AdditiveBSplineCoefficients.h.

Member Typedef Documentation

◆ ColVector

template<class Array >
typedef hidden::Traits<Array>::Col STK::AdditiveBSplineCoefficients< Array >::ColVector

Definition at line 60 of file STK_AdditiveBSplineCoefficients.h.

◆ RowVector

template<class Array >
typedef hidden::Traits<Array>::Row STK::AdditiveBSplineCoefficients< Array >::RowVector

Definition at line 59 of file STK_AdditiveBSplineCoefficients.h.

Constructor & Destructor Documentation

◆ AdditiveBSplineCoefficients() [1/3]

template<class Array >
STK::AdditiveBSplineCoefficients< Array >::AdditiveBSplineCoefficients ( Array const p_data,
int  nbControlPoints,
int  degree = 3,
Regress::KnotsPosition  position = Regress::uniformKnotsPositions_ 
)
inline

Constructor : initialize the data members.

The number of knots is given by the formula nbKnots = nbControlPoints + degree +1.

Parameters
p_dataa pointer on the input data values
nbControlPointsnumber of control points
degreedegree of the B-spline curves
positionmethod to use for positioning the knots

Definition at line 68 of file STK_AdditiveBSplineCoefficients.h.

73 : IRunnerBase()
74 , p_data_(p_data)
78 , position_(position)
80 {}
int degree() const
give the degree of the B-spline curves.
ArrayXX coefficients_
Array of the coefficients.
Regress::KnotsPosition position_
Method used in order to position the knots.
int nbControlPoints_
number of control points of the B-spline curves.
int degree_
degree of the B-splines curves.
int nbKnots_
number of knots of the B-spline curves.
int nbControlPoints() const
give the number of control points of the B-spline curves.
IRunnerBase()
default constructor
Definition STK_IRunner.h:68

◆ AdditiveBSplineCoefficients() [2/3]

template<class Array >
STK::AdditiveBSplineCoefficients< Array >::AdditiveBSplineCoefficients ( Array const data,
int  nbControlPoints,
int  degree = 3,
Regress::KnotsPosition  position = Regress::uniformKnotsPositions_ 
)
inline

Constructor : initialize the data members.

The number of knots is given by the formula nbKnots = nbControlPoints + degree +1.

Parameters
datathe input data values
nbControlPointsnumber of control points
degreedegree of the B-spline curves
positionmethod to use for positioning the knots

Definition at line 88 of file STK_AdditiveBSplineCoefficients.h.

93 : IRunnerBase()
94 , p_data_(&data)
98 , position_(position)
100 {}

◆ AdditiveBSplineCoefficients() [3/3]

template<class Array >
STK::AdditiveBSplineCoefficients< Array >::AdditiveBSplineCoefficients ( AdditiveBSplineCoefficients< Array > const coefs)
inline

Copy constructor.

Parameters
coefsthe coefficients to copy

Definition at line 104 of file STK_AdditiveBSplineCoefficients.h.

105 : IRunnerBase(coefs)
106 , p_data_(coefs.p_data_)
107 , nbKnots_(coefs.nbKnots_)
108 , nbControlPoints_(coefs.nbControlPoints_)
109 , degree_(coefs.degree_)
110 , position_(coefs.position_)
111 , coefficients_(coefs.coefficients_)
112 {}

◆ ~AdditiveBSplineCoefficients()

template<class Array >
virtual STK::AdditiveBSplineCoefficients< Array >::~AdditiveBSplineCoefficients ( )
inlinevirtual

Destructor.

Definition at line 114 of file STK_AdditiveBSplineCoefficients.h.

114{}

Member Function Documentation

◆ clone()

template<class Array >
AdditiveBSplineCoefficients * STK::AdditiveBSplineCoefficients< Array >::clone ( ) const
inline

clone pattern implementation

Definition at line 116 of file STK_AdditiveBSplineCoefficients.h.

116{ return new AdditiveBSplineCoefficients(*this);}
AdditiveBSplineCoefficients(Array const *p_data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
Constructor : initialize the data members.

◆ coefficients()

template<class Array >
ArrayXX const & STK::AdditiveBSplineCoefficients< Array >::coefficients ( ) const
inline

give the computed coefficients of the B-spline curves.

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

Definition at line 141 of file STK_AdditiveBSplineCoefficients.h.

141{ return coefficients_;}

References STK::AdditiveBSplineCoefficients< Array >::coefficients_.

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

◆ degree()

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::degree ( ) const
inline

give the degree of the B-spline curves.

Definition at line 133 of file STK_AdditiveBSplineCoefficients.h.

133{ return degree_;}

References STK::AdditiveBSplineCoefficients< Array >::degree_.

◆ extrapolate()

template<class Array >
ArrayXX STK::AdditiveBSplineCoefficients< Array >::extrapolate ( Array const x) const
Returns
the extrapolated coefficients for the x matrix.
Parameters
xthe values to extrapolate

Definition at line 216 of file STK_AdditiveBSplineCoefficients.h.

217{
218#ifdef STK_REGRESS_VERBOSE
219 stk_cout << _T("in AdditiveBSplineCoefficients::extrapolate()\n");
220#endif
221 if (x.cols() != coefs_.range())
222 { STKRUNTIME_ERROR_NO_ARG(AdditiveBSplineBSplineCoefficients::extrapolate(x),x.cols() != coefs_.range());}
223 // resize the matrix of coefficient
224 ArrayXX coefficients(x.rows(), Range());
225 for (int j= coefs_.begin(); j<coefs_.end(); j++)
226 { coefficients.merge(coefs_[j].extrapolate(x.col(j)));}
227#ifdef STK_REGRESS_VERBOSE
228 stk_cout << _T("AdditiveBSplineCoefficients::run() done\n");
229#endif
230 return coefficients;
231}
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
ArrayXX const & coefficients() const
give the computed coefficients of the B-spline curves.
Array1D< BSplineCoefficients< ColVector > > coefs_
Array with the knots and coefficients in each dimension.
void merge(IArray2D< OtherDerived > const &other)
Append the container other to this without copying the data explicitly.
Array2D< Real > ArrayXX
Specialization of the Array2D class for Real values.
Definition STK_Array2D.h:53
TRange< UnknownSize > Range
Definition STK_Range.h:59

References _T, STK::MultidimRegression< Array, Weight >::coefs_, STK::MultidimRegression< Array, Weight >::extrapolate(), STK::IArray2D< Derived >::merge(), stk_cout, and STKRUNTIME_ERROR_NO_ARG.

◆ nbControlPoints()

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::nbControlPoints ( ) const
inline

give the number of control points of the B-spline curves.

Definition at line 137 of file STK_AdditiveBSplineCoefficients.h.

137{ return nbControlPoints_;}

References STK::AdditiveBSplineCoefficients< Array >::nbControlPoints_.

◆ nbKnots()

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::nbKnots ( ) const
inline

give the number of knots of the B-spline curves.

Definition at line 135 of file STK_AdditiveBSplineCoefficients.h.

135{ return nbKnots_;}

References STK::AdditiveBSplineCoefficients< Array >::nbKnots_.

◆ run()

template<class Array >
bool STK::AdditiveBSplineCoefficients< Array >::run ( )
virtual

run the computations.

Implements STK::IRunnerBase.

Definition at line 166 of file STK_AdditiveBSplineCoefficients.h.

167{
168#ifdef STK_REGRESS_VERBOSE
169 stk_cout << _T("In AdditiveBSplineCoefficients::run()\n");
170#endif
171 // check if there exists data
172 if (!p_data_)
173 {
175 return false;
176 }
177 try
178 {
179 // resize the Array with the marginal coefficients
180 coefs_.clear(); // necesssary as coefficient_ is a reference at second call
181 coefs_.resize(p_data_->cols());
182
183 // resize the matrix of all coefficient
184 coefficients_.resize(p_data_->rows(), Range());
185 // get dimensions
186 for (int i=p_data_->beginCols(); i<p_data_->endCols(); i++)
187 {
188 // create a reference on the ith column of the data
189 ColVector colData(p_data_->col(i), true);
190 // set data to the i-th coefficient
191 // WARNING: colData will be invalidate
193 // run computation for the i-th coefficient
194 if (!coefs_[i].run())
195 {
196 msg_error_ =coefs_[i].error();
197 return false;
198 }
199 // get coefficients
201 }
202 }
203 catch ( Exception const& e)
204 {
205 msg_error_ = e.error();
206 return false;
207 }
208#ifdef STK_REGRESS_VERBOSE
209 stk_cout << _T("AdditiveBSplineCoefficients::run() done\n");
210#endif
211 return true;
212}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
Derived & resize(Range const &I, Range const &J)
resize the array.
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
virtual void setData(YArray_ const &y, XArray_ const &x)
set the data set.

References _T, STK::IArray2D< Derived >::clear(), STK::MultidimRegression< Array, Weight >::coefs_, STK::IRunnerBase::error(), STK::IArray2D< Derived >::merge(), STK::IRunnerBase::msg_error_, STK::IArray2D< Derived >::resize(), STK::AdditiveBSplineCoefficients< Array >::run(), STK::IRegression< Array, Array, Weight >::run(), stk_cout, and STKERROR_NO_ARG.

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

◆ setData()

template<class Array >
void STK::AdditiveBSplineCoefficients< Array >::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.

Parameters
p_datathe input data values
nbControlPointsnumber of control points
degreedegree of the B-spline curves
positionmethod to use for positioning the knots

Definition at line 241 of file STK_AdditiveBSplineCoefficients.h.

246{
247 p_data_ =p_data;
250 degree_ = degree;
251 position_ = position;
252}

Member Data Documentation

◆ coefficients_

template<class Array >
ArrayXX STK::AdditiveBSplineCoefficients< Array >::coefficients_
protected

Array of the coefficients.

Definition at line 161 of file STK_AdditiveBSplineCoefficients.h.

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

◆ coefs_

template<class Array >
Array1D<BSplineCoefficients<ColVector> > STK::AdditiveBSplineCoefficients< Array >::coefs_
protected

Array with the knots and coefficients in each dimension.

Definition at line 159 of file STK_AdditiveBSplineCoefficients.h.

◆ degree_

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::degree_
protected

degree of the B-splines curves.

Definition at line 155 of file STK_AdditiveBSplineCoefficients.h.

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

◆ nbControlPoints_

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::nbControlPoints_
protected

number of control points of the B-spline curves.

Definition at line 153 of file STK_AdditiveBSplineCoefficients.h.

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

◆ nbKnots_

template<class Array >
int STK::AdditiveBSplineCoefficients< Array >::nbKnots_
protected

number of knots of the B-spline curves.

Definition at line 151 of file STK_AdditiveBSplineCoefficients.h.

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

◆ p_data_

template<class Array >
Array const* STK::AdditiveBSplineCoefficients< Array >::p_data_
protected

the input data set

Definition at line 149 of file STK_AdditiveBSplineCoefficients.h.

◆ position_

template<class Array >
Regress::KnotsPosition STK::AdditiveBSplineCoefficients< Array >::position_
protected

Method used in order to position the knots.

Definition at line 157 of file STK_AdditiveBSplineCoefficients.h.


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