STK++ 0.9.13
STK_ChebyshevCoefficients.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2017 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23 */
24
25/*
26 * Project: stkpp::Regress
27 * created on: Oct 26, 2017
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_CHEBYSHEVCOEFFICIENTS_H
36#define STK_CHEBYSHEVCOEFFICIENTS_H
37
38#include "STK_IBasis.h"
39
40namespace STK
41{
42
50template<class Data, class Coefs = ArrayXX>
51class ChebyshevCoefficients: public IBasis<Data, Coefs>
52{
53 public:
55 typedef typename Data::Type Type;
56
57 using Base::p_data_;
59 using Base::dim_;
60 using Base::minValue_;
61 using Base::maxValue_;
62 using Base::msg_error_;
63 using Base::hasRun_;
64
71 ChebyshevCoefficients( Data const* p_data =0, int dim =1, bool useDataValues = true)
72 : Base(p_data, dim, useDataValues){}
79 ChebyshevCoefficients( Data const& data, int dim, bool useDataValues = true)
80 : Base(data, dim, useDataValues){}
88 inline ChebyshevCoefficients* clone() const { return new ChebyshevCoefficients(*this);}
89
91 virtual bool run();
92};
93
94template<class Data, class Coefs>
96{
97 // check if data exists
98 if (!p_data_)
99 {
101 return false;
102 }
103 if (!this->initializeStep()) return false;
104 Data x = ( Type(2)* (*p_data_)-(minValue_+maxValue_))/(maxValue_-minValue_);
105 // resize and initialize coefficients
106 coefficients_.resize(p_data_->range(), Range(0, dim_)) =0;
107 if (dim_>1)
108 {
109 coefficients_.col(0) = Type(1);
110 if (dim_>2)
111 {
112 coefficients_.col(1) = x;
113 }
114 // compute T_{n+1}(x) = 2xT_n(x) - T_{n-1}(x)
115 for(int j=2; j<coefficients_.endCols(); ++j)
116 {
117 coefficients_.col(j) = 2. * x *coefficients_.col(j-1) - coefficients_.col(j-2); ;
118 }
119 }
120 // rescale
121 for(int d=1; d<coefficients_.endCols(); ++d)
122 {
123 coefficients_.col(d) = (coefficients_.col(d) * (maxValue_-minValue_) + (minValue_+maxValue_))/Type(2);
124 }
125 this->hasRun_ = true;
126 return true;
127
128}
129
130} // namespace STK
131
132#endif /* STK_CHEBYSHEVCOEFFICIENTS_H */
In this file we define the Interface class IBasis for basis functions.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
ChebyshevCoefficients class allows to compute the coefficients of a sampled function using Chebyshev ...
ChebyshevCoefficients(Data const *p_data=0, int dim=1, bool useDataValues=true)
default constructor
virtual ~ChebyshevCoefficients()
Destructor.
virtual bool run()
run the computations.
ChebyshevCoefficients(Data const &data, int dim, bool useDataValues=true)
constructor
ChebyshevCoefficients * clone() const
clone pattern implementation
ChebyshevCoefficients(ChebyshevCoefficients const &coefs)
copy constructor.
Interface base class for all basis function.
Definition STK_IBasis.h:49
Data const * p_data_
the input data set
Definition STK_IBasis.h:110
Type minValue_
Minimal value of the data.
Definition STK_IBasis.h:116
int dim() const
Definition STK_IBasis.h:77
Type maxValue_
Maximal value of the data.
Definition STK_IBasis.h:118
int dim_
number of dimension to build
Definition STK_IBasis.h:112
Coefs coefficients_
Array2D of the coefficients.
Definition STK_IBasis.h:121
virtual bool initializeStep()
perform any computation needed before the call of the regression method.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
virtual bool run()
run the computations.
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Definition STK_Range.h:59