STK++ 1.0
STK_AdditiveBSplineCoefficients.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2011  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  stkpp::Regress
00027  * created on: 4 avr. 2011
00028  * Purpose:  cretae the matrix of coefficients for an additive regression model.
00029  * Author:   iovleff, serge.iovleff@stkpp.org
00030  *
00031  **/
00032 
00038 #include "../include/STK_AdditiveBSplineCoefficients.h"
00039 
00040 #ifdef STK_VERBOSE
00041 #include "../../Arrays/include/STK_Display2D.h"
00042 #endif
00043 
00044 namespace STK
00045 {
00046 AdditiveBSplineCoefficients::AdditiveBSplineCoefficients( Matrix const* p_data
00047                                                         , Integer const& nbControlPoints
00048                                                         , Integer const& degree
00049                                                         , BSplineCoefficients::KnotsPosition const& position
00050                                                         )
00051                                                         : IRunnerBase()
00052                                                         , p_data_(p_data)
00053                                                         , nbKnots_(nbControlPoints + degree +1)
00054                                                         , nbControlPoints_(nbControlPoints)
00055                                                         , degree_(degree)
00056                                                         , position_(position)
00057                                                         , coefficients_()
00058 { ; }
00059 
00060 /* Destructor. */
00061 AdditiveBSplineCoefficients::~AdditiveBSplineCoefficients()
00062 { ;}
00063 
00064 /* run the computations. */
00065 bool AdditiveBSplineCoefficients::run()
00066 {
00067 #ifdef STK_VERBOSE
00068   stk_cout << _T("in AdditiveBSplineCoefficients::run()\n");
00069 #endif
00070   // check if there exists data
00071   if (!p_data_)
00072   {
00073     msg_error_ = _T("Error In AdditiveBSplineCoefficients::run()\nWhat: no data\n");
00074     return false;
00075   }
00076   try {
00077     // resize the matrix of coefficient
00078     coefficients_.resize(p_data_->rangeVe(), Range());
00079     // get dimensions
00080     const Integer first = p_data_->firstCol(), last = p_data_->lastCol();
00081     for (Integer i=first; i<=last; i++)
00082     {
00083       // create a reference on the ith column of the data
00084       Vector colData((*p_data_)[i], true);
00085       BSplineCoefficients coefs(colData, nbControlPoints_, degree_, position_);
00086       coefs.run();
00087       // get coefficients
00088       coefficients_.pushBackByTransfer(coefs.coefficients());
00089     }
00090 
00091   } catch (runtime_error e)
00092   {
00093     msg_error_ = e.what();
00094     return false;
00095   }
00096 #ifdef STK_VERBOSE
00097   stk_cout << _T("AdditiveBSplineCoefficients::run() done\n");
00098 #endif
00099   return true;
00100 }
00101 
00102 
00103 /* Compute the coefficients of the B-Spline curve for the given values.
00104  *  @param p_data the input data values
00105  *  @param nbControlPoints number of control points
00106  *  @param degree degree of the B-Spline curves
00107  *  @param position method to use for positioning the knots
00108  **/
00109 void AdditiveBSplineCoefficients::setData( Matrix const* p_data
00110                                          , Integer const& nbControlPoints
00111                                          , Integer const& degree
00112                                          , BSplineCoefficients::KnotsPosition const& position
00113                                          )
00114 {
00115   p_data_ =p_data;
00116   nbKnots_ = nbControlPoints + degree +1;
00117   nbControlPoints_ = nbControlPoints;
00118   degree_ = degree;
00119   position_ = position;
00120 }
00121 
00122 } // namespace STK