STK++ 0.9.13
STK_TrigonometricCoefficients.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_TRIGONOMETRICCOEFFICIENTS_H
36#define STK_TRIGONOMETRICCOEFFICIENTS_H
37
38#include "STK_IBasis.h"
39
40namespace STK
41{
42
46template<class Data, class Coefs = ArrayXX>
47class TrigonometricCoefficients: public IBasis<Data, Coefs>
48{
49 public:
51 typedef typename Data::Type Type;
52
53 using Base::p_data_;
55 using Base::dim_;
56 using Base::minValue_;
57 using Base::maxValue_;
58 using Base::msg_error_;
59 using Base::hasRun_;
60
67 TrigonometricCoefficients( Data const* p_data=0, int dim=1, bool useDataValues = true)
68 : Base(p_data, dim, useDataValues){}
75 TrigonometricCoefficients( Data const& data, int dim, bool useDataValues = true)
76 : Base(data, dim, useDataValues){}
84 inline TrigonometricCoefficients* clone() const { return new TrigonometricCoefficients(*this);}
85
87 virtual bool run();
88};
89
90template<class Data, class Coefs>
92{
93 // check if data exists
94 if (!p_data_)
95 {
97 return false;
98 }
99 if (!this->initializeStep()) return false;
100 if (dim_>1)
101 {
102 coefficients_.col(0) = Type(1);
103 Type period = Type(2)*Const::_PI_/(maxValue_ - minValue_);
104 for(int j=1; j<coefficients_.endCols(); j += 2)
105 {
106 coefficients_.col(j) = (*p_data_ * Type(j)*period).cos();
107 if (j+1 < coefficients_.endCols())
108 coefficients_.col(j+1) = (*p_data_ * Type(j)*period).sin();
109 }
110 }
111 this->hasRun_ = true;
112 return true;
113
114}
115
116} // namespace STK
117
118#endif /* STK_TRIGONOMETRICCOEFFICIENTS_H */
In this file we define the Interface class IBasis for basis functions.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
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...
TrigonometricCoefficients class allows to compute the coefficients of a sampled function using sines ...
TrigonometricCoefficients(Data const *p_data=0, int dim=1, bool useDataValues=true)
default constructor
TrigonometricCoefficients * clone() const
clone pattern implementation
TrigonometricCoefficients(TrigonometricCoefficients const &coefs)
copy constructor.
virtual bool run()
run the computations.
TrigonometricCoefficients(Data const &data, int dim, bool useDataValues=true)
constructor
The namespace STK is the main domain space of the Statistical ToolKit project.