36#ifndef STK_BSPLINECOEFFICIENTS_H
37#define STK_BSPLINECOEFFICIENTS_H
44#ifdef STK_REGRESS_VERBOSE
169 template<
class OtherVector>
210 ,
int nbControlPoints
218 , nbKnots_(nbControlPoints + degree + 1)
219 , lastControlPoint_(dim_-1)
220 , knots_(
Range(0, nbKnots_) )
226 ,
int nbControlPoints
234 , nbKnots_(nbControlPoints + degree +1)
235 , lastControlPoint_(dim_-1)
236 , knots_(
Range(0, nbKnots_) )
244 , degree_(coefs.degree_)
245 , position_(coefs.position_)
246 , nbKnots_(coefs.nbKnots_)
247 , lastControlPoint_(coefs.lastControlPoint_)
248 , knots_(coefs.knots_)
258 ,
int nbControlPoints
264 dim_ = nbControlPoints;
267 nbKnots_ = dim_ + degree_ +1;
268 lastControlPoint_ = dim_-1;
277 ,
int nbControlPoints
283 dim_ = nbControlPoints;
286 nbKnots_ = dim_ + degree_ +1;
287 lastControlPoint_ = dim_-1;
288 knots_.resize(
Range(0, nbKnots_) );
298 dim_ = nbControlPoints;
299 nbKnots_ = dim_ + degree_ +1;
300 lastControlPoint_ = dim_-1;
301 knots_.resize(
Range(0, nbKnots_) );
312 nbKnots_ = dim_ + degree_ +1;
313 lastControlPoint_ = dim_-1;
314 knots_.resize(
Range(0, nbKnots_) );
342 if (computeKnots()) { computeCoefficients();}
343 else {
return false;}
353template<
class OtherVector>
362 if (minValue_ == maxValue_)
return coefs;
368 if (value <= minValue_)
373 if (value >= maxValue_)
380 for (k=0,
k1=1; k<lastControlPoint_; k++,
k1++)
382 if (value < knots_[
k1])
break;
386 for (
int d=1; d<=degree_; d++)
391 for (
int i =
k1-d;
i<k;
i++)
398 coefs(
irow, k) *= (value - knots_[k])/(knots_[k+d] - knots_[k]);
409 knots_.resize(
Range(0, nbKnots_) ) = minValue_;
415 computeUniformKnots();
419 computePeriodicKnots();
423 computeDensityKnots(
true);
434 Real range = (maxValue_ - minValue_);
435 for (
int k = 0; k < nbKnots_; k++) knots_[k] = minValue_ + range * knots_[k];
444#ifdef STK_REGRESS_VERBOSE
445 stk_cout <<
_T(
"BSplineCoefficients::computeCoefficients()\n");
449 for (
int i=p_data_->begin();
i< p_data_->end();
i++)
450 { computeCoefficientsRow(
i, (*p_data_)[
i]);}
452#ifdef STK_REGRESS_VERBOSE
453 stk_cout <<
_T(
"BSplineCoefficients::computeCoefficients() done\n");
464 const int first = degree_ + 1;
465 for (
int k = first,
j = 1; k <= lastControlPoint_;
j++, k++) knots_[k] =
j *
step;
467 for (
int k=0,
j = lastControlPoint_+1; k < first;
j++, k++)
480 for (
int k = 0,
j = -degree_; k < nbKnots_;
j++, k++)
481 knots_[k] =
j *
step;
489 Data
xtri(*p_data_,
true);
497 int first =
xtri.begin();
498 for (
int k = degree_ + 1,
kcell =1; k <= lastControlPoint_; k++,
kcell++)
504 for (
int k=0,
j = lastControlPoint_+1; k <= degree_;
j++, k++)
506 knots_[k] =
xtri.front();
507 knots_[
j] =
xtri.back();
518 if (value <= minValue_)
520 coefficients_(
irow, 0) = 1.0;
523 if (value >= maxValue_)
525 coefficients_(
irow, lastControlPoint_) = 1.0;
530 for (k=0,
k1=1; k<lastControlPoint_; k++,
k1++)
532 if (value < knots_[
k1])
break;
535 coefficients_(
irow, k) = 1.0;
536 for (
int d=1; d<=degree_; d++)
539 coefficients_(
irow, k-d) = ( (knots_[
k1] - value)/(knots_[
k1] - knots_[
k1-d]) )
540 * coefficients_(
irow,
k1-d);
542 for (
int i =
k1-d;
i<k;
i++)
546 * coefficients_(
irow,
i)
548 * coefficients_(
irow,
i+1);
551 coefficients_(
irow, k) *= (value - knots_[k])/(knots_[k+d] - knots_[k]);
A Array2DVector is a one dimensional horizontal container.
This file define methods for displaying Arrays and Expressions.
In this file we define an implementation of the heapsort algorithm for IVector containers.
In this file we define the Interface class IBasis for basis functions.
#define STKERROR_NO_ARG(Where, Error)
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Compute the regression B-splines coefficients.
VectorX const & knots() const
void computeDensityKnots(bool isSorted)
compute the position of the density knots
int nbKnots_
number of knots of the B-spline curves.
BSplineCoefficients(Data const &data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_, bool useDataValues=true)
Constructor : initialize the data members.
int degree_
degree of the B-splines curves.
int nbControlPoints() const
void computeCoefficientsRow(int irow, Real const &value)
Compute a row of the coefficients matrix for a given value.
void setDegree(int degree=3)
Set the degree of the BSpline basis.
void setDim(int dim)
Alias for setting the number of control point (the number of BSpline)
void computePeriodicKnots()
compute the position of the periodic knots.
IBasis< Data, ArrayXX > Base
void setData(Data const &data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
[DEPRECATED] Set the whole set of parameters for computing the coefficients
void computeUniformKnots()
compute the position of the uniform knots.
virtual bool run()
run the computations.
void computeCoefficients()
Compute the coefficients of the B-spline curves.
void setPosition(Regress::KnotsPosition position)
Set the kind of position to use for the knots.
bool computeKnots()
compute the position of the knots of the B-spline curves.
BSplineCoefficients(BSplineCoefficients const &coefs)
copy constructor.
void setNbControlPoints(int nbControlPoints)
Set the number of control point (the number of BSpline)
Regress::KnotsPosition position_
Method used in order to position the knots.
virtual ~BSplineCoefficients()
Destructor.
void setParameters(Data const &data, int nbControlPoints, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_)
Set the whole set of parameters for computing the coefficients.
VectorX knots_
Data of the knots.
BSplineCoefficients * clone() const
clone pattern implementation
BSplineCoefficients(Data const *p_data=0, int nbControlPoints=1, int degree=3, Regress::KnotsPosition position=Regress::uniformKnotsPositions_, bool useDataValues=true)
Default constructor : initialize the data members with default values.
int lastControlPoint_
Index of the last control point of the B-spline curves.
ArrayXX extrapolate(OtherVector const &x) const
Interface base class for all basis function.
Data const * p_data_
the input data set
Type minValue_
Minimal value of the data.
Type maxValue_
Maximal value of the data.
int dim_
number of dimension to build
ArrayXX coefficients_
Array2D of the coefficients.
virtual bool run()
run the computations.
virtual bool initializeStep()
perform any computation needed before the call of the regression method.
String msg_error_
String with the last error message.
virtual void update()
update the runner.
bool hasRun_
true if run has been used, false otherwise
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Array const & coefs() const
Index sub-vector region: Specialization when the size is unknown.
KnotsPosition
Method to use for positioning the knots for BSpline basis.
@ uniformKnotsPositions_
uniform knots
@ densityKnotsPositions_
knots using density of the data
@ periodicKnotsPositions_
periodic knots
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range