|
STK++ 1.0
|
Compute the regression splines coefficients. More...
#include <STK_BSplineCoefficients.h>

Public Types | |
| enum | KnotsPosition { uniform_, periodic_, density_, unknown_ } |
| Method to use for positioning the knots. More... | |
Public Member Functions | |
| BSplineCoefficients (Vector const *p_data, Integer const &nbControlPoints, Integer const °ree=3, KnotsPosition const &position=uniform_) | |
| Constructor : initialize the data members. | |
| BSplineCoefficients (Vector const &data, Integer const &nbControlPoints, Integer const °ree=3, KnotsPosition const &position=uniform_) | |
| Constructor : initialize the data members. | |
| virtual | ~BSplineCoefficients () |
| Destructor. | |
| void | run () |
| run the computations. | |
| void | setData (Vector const *p_data, Integer const &nbControlPoints, Integer const °ree=3, KnotsPosition const &position=uniform_) |
| Compute the coefficients of the B-Spline curve for the given values. | |
| Integer const & | degree () const |
| give the degree of the B-Spline curves. | |
| Integer const & | nbKnots () const |
| give the number of knots of the B-Spline curves. | |
| Integer const & | nbControlPoints () const |
| give the number of control points of the B-Spline curves. | |
| Vector const & | knots () const |
| give the knots of the B-Spline curves. | |
| Matrix const & | coefficients () const |
| The computed coefficients of the B-Spline curves. | |
Static Public Member Functions | |
| static KnotsPosition | StringToKnotsPosition (String const &type) |
| convert a String to a TypeGraph. | |
| static String | KnotsPositionToString (KnotsPosition const &type) |
| convert a KnotsPosition to a String. | |
Protected Attributes | |
| Vector const * | p_data_ |
| the input data set | |
| Integer | nbKnots_ |
| number of knots of the B-Spline curves. | |
| Integer | lastKnot_ |
| Index of the last knots of the B-Spline curves. | |
| Integer | nbControlPoints_ |
| number of control points of the B-Spline curves. | |
| Integer | lastControlPoint_ |
| Index of the last control point of the B-Spline curves. | |
| Integer | degree_ |
| degree of the B-splines curves. | |
| KnotsPosition | position_ |
| Method used in order to position the knots. | |
| Vector | knots_ |
| Vector of the knots. | |
| Matrix | coefficients_ |
| Matrix of the coefficients. | |
Private Member Functions | |
| void | computeKnots () |
| compute the position of the knots of the B-Spline curves. | |
| void | computeUniformKnots () |
| compute the position of the uniform knots. | |
| void | computePeriodicKnots () |
| compute the position of the periodic knots. | |
| void | computeDensityKnots () |
| compute the position of the density knots. | |
| void | computeCoefficients () |
| Compute the coefficients of the B-Spline curves. | |
| void | computeCoefficientsRow (Integer const &irow) |
| Compute a row of the coefficients. | |
Private Attributes | |
| Real | minValue_ |
| Minimal value of the knots. | |
| Real | maxValue_ |
| Maximal value of the knots. | |
Compute the regression splines coefficients.
The BSplineCoefficients class compute the coefficients of a B-Spline curve using the de Boor's algorithm. The knots can be uniform (the default) or periodic.
The input data set is a vector of size n and the output matrix of the coefficients Coefficients() is a matrix of size (n, nbControlPoints).
Definition at line 53 of file STK_BSplineCoefficients.h.
| STK::BSplineCoefficients::BSplineCoefficients | ( | Vector const * | p_data, |
| Integer const & | nbControlPoints, | ||
| Integer const & | degree = 3, |
||
| KnotsPosition const & | position = uniform_ |
||
| ) |
Constructor : initialize the data members.
The number of knots is given by the formula nbKnots = nbControlPoints + degree +1.
| p_data | the input data values |
| nbControlPoints | number of control points |
| degree | degree of the B-Spline curves |
| position | method to use for positioning the knots |
Definition at line 73 of file STK_BSplineCoefficients.cpp.
: p_data_(p_data) , nbKnots_(nbControlPoints + degree +1) , lastKnot_(nbKnots_-1) , nbControlPoints_(nbControlPoints) , lastControlPoint_(nbControlPoints_-1) , degree_(degree) , position_(position) , knots_(Range(0,lastKnot_)) , coefficients_(p_data->range(), Range(0,lastControlPoint_), 0.0) , minValue_( Arithmetic<Real>::max()) , maxValue_(-Arithmetic<Real>::max()) { }
| STK::BSplineCoefficients::BSplineCoefficients | ( | Vector const & | data, |
| Integer const & | nbControlPoints, | ||
| Integer const & | degree = 3, |
||
| KnotsPosition const & | position = uniform_ |
||
| ) |
Constructor : initialize the data members.
The number of knots is given by the formula nbKnots = nbControlPoints + degree +1.
| data | the input data values |
| nbControlPoints | number of control points |
| degree | degree of the B-Spline curves |
| position | method to use for positioning the knots |
Definition at line 93 of file STK_BSplineCoefficients.cpp.
: p_data_(&data) , nbKnots_(nbControlPoints + degree +1) , lastKnot_(nbKnots_-1) , nbControlPoints_(nbControlPoints) , lastControlPoint_(nbControlPoints_-1) , degree_(degree) , position_(position) , knots_(Range(0,lastKnot_)) , coefficients_(p_data_->range(), Range(0,lastControlPoint_), 0.0) , minValue_( Arithmetic<Real>::max()) , maxValue_(-Arithmetic<Real>::max()) {}
| STK::BSplineCoefficients::~BSplineCoefficients | ( | ) | [virtual] |
| BSplineCoefficients::KnotsPosition STK::BSplineCoefficients::StringToKnotsPosition | ( | String const & | type | ) | [static] |
convert a String to a TypeGraph.
| type | the type of graph in a string |
type. If the string does not match any known name, the unknown_ type is returned. Definition at line 52 of file STK_BSplineCoefficients.cpp.
References _T, density_, periodic_, STK::toUpperString(), uniform_, and unknown_.
Referenced by STK::AdditiveBSplineRegressionPage::validate().
{
if (toUpperString(type) == toUpperString(_T("uniform"))) return uniform_;
if (toUpperString(type) == toUpperString(_T("periodic"))) return periodic_;
if (toUpperString(type) == toUpperString(_T("density"))) return density_;
return unknown_;
}

| String STK::BSplineCoefficients::KnotsPositionToString | ( | KnotsPosition const & | type | ) | [static] |
convert a KnotsPosition to a String.
| type | the KnotsPosition we want to convert to a string |
Definition at line 64 of file STK_BSplineCoefficients.cpp.
| void STK::BSplineCoefficients::run | ( | ) |
run the computations.
Definition at line 115 of file STK_BSplineCoefficients.cpp.
References computeCoefficients(), and computeKnots().
Referenced by STK::BSplineRegression::preRun(), and STK::AdditiveBSplineCoefficients::run().
{
computeKnots();
computeCoefficients();
}

| void STK::BSplineCoefficients::setData | ( | Vector const * | p_data, |
| Integer const & | nbControlPoints, | ||
| Integer const & | degree = 3, |
||
| KnotsPosition const & | position = uniform_ |
||
| ) |
Compute the coefficients of the B-Spline curve for the given values.
| p_data | the input data values |
| nbControlPoints | number of control points |
| degree | degree of the B-Spline curves |
| position | method to use for positioning the knots |
Definition at line 126 of file STK_BSplineCoefficients.cpp.
References coefficients_, lastControlPoint_, p_data_, STK::ITContainer1D< TYPE, TContainer1D >::range(), and STK::IContainer2D::resize().
{
// set data
p_data_ = p_data;
// resize coeficients
coefficients_.resize(p_data->range(), Range(0, lastControlPoint_));
// initialize array of coefficient
coefficients_ = 0.0;
}

| Integer const& STK::BSplineCoefficients::degree | ( | ) | const [inline] |
give the degree of the B-Spline curves.
Definition at line 125 of file STK_BSplineCoefficients.h.
References degree_.
{ return degree_;}
| Integer const& STK::BSplineCoefficients::nbKnots | ( | ) | const [inline] |
give the number of knots of the B-Spline curves.
Definition at line 127 of file STK_BSplineCoefficients.h.
References nbKnots_.
{ return nbKnots_;}
| Integer const& STK::BSplineCoefficients::nbControlPoints | ( | ) | const [inline] |
give the number of control points of the B-Spline curves.
Definition at line 129 of file STK_BSplineCoefficients.h.
References nbControlPoints_.
{ return nbControlPoints_;}
| Vector const& STK::BSplineCoefficients::knots | ( | ) | const [inline] |
give the knots of the B-Spline curves.
Definition at line 131 of file STK_BSplineCoefficients.h.
References knots_.
Referenced by STK::BSplineRegression::knots().
{ return knots_;}
| Matrix const& STK::BSplineCoefficients::coefficients | ( | ) | const [inline] |
The computed coefficients of the B-Spline curves.
This is a matrix of size (p_data_->range(), 0:lastControlPoints).
Definition at line 135 of file STK_BSplineCoefficients.h.
References coefficients_.
Referenced by STK::BSplineRegression::coefficients(), STK::BSplineRegression::prediction(), STK::BSplineRegression::regression(), and STK::AdditiveBSplineCoefficients::run().
{ return coefficients_;}
| void STK::BSplineCoefficients::computeKnots | ( | ) | [private] |
compute the position of the knots of the B-Spline curves.
Definition at line 141 of file STK_BSplineCoefficients.cpp.
References computeDensityKnots(), computePeriodicKnots(), computeUniformKnots(), density_, STK::ITContainer1D< TYPE, TContainer1D >::first(), knots_, STK::ITContainer1D< TYPE, TContainer1D >::last(), lastKnot_, STK::max(), maxValue_, STK::min(), minValue_, p_data_, periodic_, position_, uniform_, and unknown_.
Referenced by run().
{
// get dimensions
Integer first = p_data_->first(), last = p_data_->last();
// compute min value
for (Integer i=first; i<= last; i++)
{
minValue_ = min(minValue_, (*p_data_)[i]);
maxValue_ = max(maxValue_, (*p_data_)[i]);
}
// if all value are equals, all the knots are equals to this value
if (minValue_ == maxValue_)
{
knots_ = minValue_;
return;
}
// set knots values
switch (position_)
{
// uniform position
case uniform_:
computeUniformKnots();
break;
// periodic position
case periodic_:
computePeriodicKnots();
break;
// density position
case density_:
computeDensityKnots();
break;
// periodic position
case unknown_:
// check if there exists data
throw runtime_error("Error In BSplineCoefficients::computeKnots():"
" unknowns positions");
break;
}
// shift knots
Real range = (maxValue_ - minValue_);
for (Integer k = 0; k <= lastKnot_; k++)
knots_[k] = minValue_ + range * knots_[k];
}

| void STK::BSplineCoefficients::computeUniformKnots | ( | ) | [private] |
compute the position of the uniform knots.
Definition at line 186 of file STK_BSplineCoefficients.cpp.
References degree_, knots_, lastControlPoint_, and nbControlPoints_.
Referenced by computeKnots().
{
// compute step
Real step = 1.0/(nbControlPoints_ - degree_);
// set internal knots
const Integer first = degree_ + 1, last = lastControlPoint_;
for (Integer k = first, j = 1; k <= last; j++, k++)
knots_[k] = j * step;
// set external knots
for ( Integer k=0, j = last+1; k < first; j++, k++)
{
knots_[k] = 0;
knots_[j] = 1;
}
}
| void STK::BSplineCoefficients::computePeriodicKnots | ( | ) | [private] |
compute the position of the periodic knots.
Definition at line 202 of file STK_BSplineCoefficients.cpp.
References degree_, knots_, lastKnot_, and nbControlPoints_.
Referenced by computeKnots().
| void STK::BSplineCoefficients::computeDensityKnots | ( | ) | [private] |
compute the position of the density knots.
Definition at line 212 of file STK_BSplineCoefficients.cpp.
References STK::ITContainer1D< TYPE, TContainer1D >::first(), knots_, STK::ITContainer1D< TYPE, TContainer1D >::last(), lastKnot_, p_data_, and STK::ITContainer1D< TYPE, TContainer1D >::size().
Referenced by computeKnots().
{
// sorted data
Vector xtri;
// sort the data
heapSort<Real, Vector>(*p_data_, xtri);
// compute step
Real step = xtri.size()/(Real)lastKnot_;
Integer first = xtri.first(), last = xtri.last();
// set knots
for (Integer k = 0; k < lastKnot_; k++)
{
Integer cell = first + Integer(k* step);
knots_[k] = (xtri[cell] + xtri[cell+1])/2.;
}
// set last knots
knots_[lastKnot_] = (xtri[last-1] + xtri[last])/2.;
}

| void STK::BSplineCoefficients::computeCoefficients | ( | ) | [private] |
Compute the coefficients of the B-Spline curves.
Definition at line 233 of file STK_BSplineCoefficients.cpp.
References _T, computeCoefficientsRow(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), p_data_, and stk_cout.
Referenced by run().
{
#ifdef STK_VERBOSE
stk_cout << _T("BSplineCoefficients::computeCoefficients()\n");
#endif
// get dimensions
Integer first = p_data_->first(), last = p_data_->last();
// compute the coefficients
for (Integer i=first; i<= last; i++)
{
computeCoefficientsRow(i);
}
#ifdef STK_VERBOSE
stk_cout << _T("BSplineCoefficients::computeCoefficients() done\n");
#endif
}

| void STK::BSplineCoefficients::computeCoefficientsRow | ( | Integer const & | irow | ) | [private] |
Compute a row of the coefficients.
| irow | index of the row |
Definition at line 253 of file STK_BSplineCoefficients.cpp.
References coefficients_, degree_, knots_, lastControlPoint_, maxValue_, and minValue_.
Referenced by computeCoefficients().
{
// get current value
const Real value = (*p_data_)[irow];
// value outside the range of the knots case
if (value <= minValue_)
{
coefficients_(irow, 0) = 1.0;
return;
}
if (value >= maxValue_)
{
coefficients_(irow, lastControlPoint_) = 1.0;
return;
}
// find interval
Integer k, k1;
for (k=0, k1=1; k<lastControlPoint_; k++, k1++)
{
if (value < knots_[k1]) break;
}
// begin recursion
coefficients_(irow, k) = 1.0;
for (Integer d=1; d<=degree_; d++)
{
// right (south-west corner) term only
coefficients_(irow, k-d) = ( (knots_[k1] - value)/(knots_[k1] - knots_[k1-d]) )
* coefficients_(irow, k1-d);
// compute internal terms
for (Integer i = k1-d; i<k; i++)
{
const Real knots_i = knots_[i], knots_id1 = knots_[i+d+1];
coefficients_(irow, i) = ( (value - knots_i)/(knots_[i+d] - knots_i) )
* coefficients_(irow, i)
+ ( (knots_id1 - value)/(knots_id1 - knots_[i+1]) )
* coefficients_(irow, i+1);
}
// left (north-west corner) term only
coefficients_(irow, k) *= (value - knots_[k])/(knots_[k+d] - knots_[k]);
}
}
Vector const* STK::BSplineCoefficients::p_data_ [protected] |
the input data set
Definition at line 139 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficients(), computeDensityKnots(), computeKnots(), and setData().
Integer STK::BSplineCoefficients::nbKnots_ [protected] |
number of knots of the B-Spline curves.
Definition at line 141 of file STK_BSplineCoefficients.h.
Referenced by nbKnots().
Integer STK::BSplineCoefficients::lastKnot_ [protected] |
Index of the last knots of the B-Spline curves.
This is nbKnots_ - 1.
Definition at line 143 of file STK_BSplineCoefficients.h.
Referenced by computeDensityKnots(), computeKnots(), and computePeriodicKnots().
Integer STK::BSplineCoefficients::nbControlPoints_ [protected] |
number of control points of the B-Spline curves.
Definition at line 145 of file STK_BSplineCoefficients.h.
Referenced by computePeriodicKnots(), computeUniformKnots(), and nbControlPoints().
Integer STK::BSplineCoefficients::lastControlPoint_ [protected] |
Index of the last control point of the B-Spline curves.
This is nbControlPoints_ - 1.
Definition at line 149 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficientsRow(), computeUniformKnots(), and setData().
Integer STK::BSplineCoefficients::degree_ [protected] |
degree of the B-splines curves.
Definition at line 151 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficientsRow(), computePeriodicKnots(), computeUniformKnots(), and degree().
KnotsPosition STK::BSplineCoefficients::position_ [protected] |
Method used in order to position the knots.
Definition at line 153 of file STK_BSplineCoefficients.h.
Referenced by computeKnots().
Vector STK::BSplineCoefficients::knots_ [protected] |
Vector of the knots.
Definition at line 155 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficientsRow(), computeDensityKnots(), computeKnots(), computePeriodicKnots(), computeUniformKnots(), and knots().
Matrix STK::BSplineCoefficients::coefficients_ [protected] |
Matrix of the coefficients.
Definition at line 157 of file STK_BSplineCoefficients.h.
Referenced by coefficients(), computeCoefficientsRow(), and setData().
Real STK::BSplineCoefficients::minValue_ [private] |
Minimal value of the knots.
Definition at line 161 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficientsRow(), and computeKnots().
Real STK::BSplineCoefficients::maxValue_ [private] |
Maximal value of the knots.
Definition at line 163 of file STK_BSplineCoefficients.h.
Referenced by computeCoefficientsRow(), and computeKnots().