STK++ 1.0
STK::BSplineCoefficients Class Reference

Compute the regression splines coefficients. More...

#include <STK_BSplineCoefficients.h>

Collaboration diagram for STK::BSplineCoefficients:

List of all members.

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 &degree=3, KnotsPosition const &position=uniform_)
 Constructor : initialize the data members.
 BSplineCoefficients (Vector const &data, Integer const &nbControlPoints, Integer const &degree=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 &degree=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.

Detailed Description

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.


Member Enumeration Documentation

Method to use for positioning the knots.

Enumerator:
uniform_ 

uniform knots

periodic_ 

periodic knots

density_ 

knots using density of the data

unknown_ 

unknown method

Definition at line 57 of file STK_BSplineCoefficients.h.


Constructor & Destructor Documentation

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.

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 73 of file STK_BSplineCoefficients.cpp.

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.

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 93 of file STK_BSplineCoefficients.cpp.

STK::BSplineCoefficients::~BSplineCoefficients ( ) [virtual]

Destructor.

Definition at line 112 of file STK_BSplineCoefficients.cpp.

{}

Member Function Documentation

BSplineCoefficients::KnotsPosition STK::BSplineCoefficients::StringToKnotsPosition ( String const &  type) [static]

convert a String to a TypeGraph.

Parameters:
typethe type of graph in a string
Returns:
the TypeGraph represented by the 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_;
}

Here is the call graph for this function:

String STK::BSplineCoefficients::KnotsPositionToString ( KnotsPosition const &  type) [static]

convert a KnotsPosition to a String.

Parameters:
typethe KnotsPosition we want to convert to a string
Returns:
the string associated to this KnotsPosition

Definition at line 64 of file STK_BSplineCoefficients.cpp.

References _T, density_, periodic_, and uniform_.

{
  if (type == uniform_)  return String(_T("uniform"));
  if (type == periodic_) return String(_T("periodic"));
  if (type == density_) return String(_T("density"));
  return String(_T("unknown"));
}
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().

Here is the call graph for this function:

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.

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 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;
}

Here is the call graph for this function:

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];
}

Here is the call graph for this function:

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().

{
  // compute step
  Real step = 1.0/(nbControlPoints_ - degree_);
  // set knots
  for (Integer k = 0, j = -degree_; k <= lastKnot_; j++, k++)
    knots_[k] = j * step;
;
}
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.;
}

Here is the call graph for this function:

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
}

Here is the call graph for this function:

void STK::BSplineCoefficients::computeCoefficientsRow ( Integer const &  irow) [private]

Compute a row of the coefficients.

Parameters:
irowindex 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]);
  }
}

Member Data Documentation

the input data set

Definition at line 139 of file STK_BSplineCoefficients.h.

Referenced by computeCoefficients(), computeDensityKnots(), computeKnots(), and setData().

number of knots of the B-Spline curves.

Definition at line 141 of file STK_BSplineCoefficients.h.

Referenced by nbKnots().

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().

number of control points of the B-Spline curves.

Definition at line 145 of file STK_BSplineCoefficients.h.

Referenced by computePeriodicKnots(), computeUniformKnots(), and nbControlPoints().

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().

degree of the B-splines curves.

Definition at line 151 of file STK_BSplineCoefficients.h.

Referenced by computeCoefficientsRow(), computePeriodicKnots(), computeUniformKnots(), and degree().

Method used in order to position the knots.

Definition at line 153 of file STK_BSplineCoefficients.h.

Referenced by computeKnots().

Matrix of the coefficients.

Definition at line 157 of file STK_BSplineCoefficients.h.

Referenced by coefficients(), computeCoefficientsRow(), and setData().

Minimal value of the knots.

Definition at line 161 of file STK_BSplineCoefficients.h.

Referenced by computeCoefficientsRow(), and computeKnots().

Maximal value of the knots.

Definition at line 163 of file STK_BSplineCoefficients.h.

Referenced by computeCoefficientsRow(), and computeKnots().


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