STK++ 0.9.13
STK_IBasis.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/* Project: stkpp::Regress
26 * created on: Nov 28, 2017
27 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
28 **/
29
34#ifndef STK_IBASIS_H
35#define STK_IBASIS_H
36
37#include "STK_Regress_Util.h"
38
40
41namespace STK
42{
43
47template<class Data, class Coefs = ArrayXX>
48class IBasis: public IRunnerBase
49{
50 public:
51 typedef typename Data::Type Type;
60 IBasis(Data const* p_data, int dim, bool useDataValues = true);
67 IBasis(Data const& data, int dim, bool useDataValues = true);
73 virtual ~IBasis() {}
74
75 // getters
77 inline int dim() const { return dim_;}
79 inline Coefs const& coefficients() const { return coefficients_;}
81 inline Type minValue() const { return minValue_;}
83 inline Type maxValue() const { return maxValue_;}
84
85 // setters
89 inline void setData( Data const& data)
90 {
91 p_data_ = &data;
92 update();
93 }
95 inline void setDim( int dim) { dim_ = dim; update();}
97 inline void setMinValue( Type const& minValue) { minValue_ = minValue;}
99 inline void setMaxValue( Type const& maxValue) { maxValue_ = maxValue;}
100
103
104 protected:
108 virtual void update();
110 Data const* p_data_;
112 int dim_;
119
122};
123
124template<class Data, class Coefs>
126 , p_data_(0)
127 , dim_()
128 , useDataValues_(true)
129 , minValue_( Arithmetic<Type>::max())
130 , maxValue_(-Arithmetic<Type>::max())
131 , coefficients_()
132{}
133
134template<class Data, class Coefs>
135IBasis<Data, Coefs>::IBasis( Data const* p_data, int dim, bool useDataValues)
136 : IRunnerBase()
137 , p_data_(p_data)
138 , dim_(dim)
139 , useDataValues_(useDataValues)
140 , minValue_( Arithmetic<Type>::max())
141 , maxValue_(-Arithmetic<Type>::max())
142 , coefficients_()
143{}
144template<class Data, class Coefs>
145IBasis<Data, Coefs>::IBasis( Data const& data, int dim, bool useDataValues)
146 : IRunnerBase()
147 , p_data_(&data)
148 , dim_(dim)
149 , useDataValues_(useDataValues)
150 , minValue_( Arithmetic<Type>::max())
151 , maxValue_(-Arithmetic<Type>::max())
152 , coefficients_()
153{}
154
155template<class Data, class Coefs>
158 , p_data_(basis.p_data_)
159 , dim_(basis.dim_)
160 , useDataValues_(basis.useDataValues_)
161 , minValue_(basis.minValue_)
162 , maxValue_(basis.maxValue_)
163 , coefficients_(basis.coefficients_)
164{}
165
166/* update IBasis
167 * if a parameter or a new data set is set, update the values of this runner.
168 **/
169template<class Data, class Coefs>
171{
172 if (useDataValues_)
173 {
174 minValue_ = Arithmetic<Type>::max();
175 maxValue_ = -Arithmetic<Type>::max();
176 }
177 hasRun_ = false;
178}
179/* Initialize the parameters */
180template<class Data, class Coefs>
182{
183 // resize and initialize coeficients
184 coefficients_.resize(p_data_->range(), Range(0, dim_)) =0;
185 // compute min and max value
186 if (useDataValues_)
187 {
188 minValue_ = Arithmetic<Type>::max();
189 maxValue_ = -Arithmetic<Type>::max();
190 for (int i=p_data_->begin(); i< p_data_->end(); i++)
191 {
192 minValue_ = std::min(minValue_, (*p_data_)[i]);
193 maxValue_ = std::max(maxValue_, (*p_data_)[i]);
194 }
195 }
196 // if all value are equals
197 if (minValue_ == maxValue_)
198 {
200 return false;
201 }
202 // if values are incorrect
203 if (minValue_ > maxValue_)
204 {
206 return false;
207 }
208 return true;
209}
210
211
212} // namespace STK
213
214#endif /* STK_IBASIS_H_ */
In this file, we define the final class Array2D.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
In this file we declare the utilities enumerations and methods for the Regress project.
Interface base class for all basis function.
Definition STK_IBasis.h:49
bool initializeStep()
Initialize the parameters minValue_ and maxValue_ using data set.
Definition STK_IBasis.h:181
virtual ~IBasis()
destructor
Definition STK_IBasis.h:73
void setMaxValue(Type const &maxValue)
Definition STK_IBasis.h:99
Data const * p_data_
the input data set
Definition STK_IBasis.h:110
Data::Type Type
Definition STK_IBasis.h:51
virtual void update()
update IBasis if a parameter or a new data set is set, update the state of this runner.
Definition STK_IBasis.h:170
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
void setData(Data const &data)
Set the data set.
Definition STK_IBasis.h:89
void setDim(int dim)
Definition STK_IBasis.h:95
IBasis(Data const *p_data, int dim, bool useDataValues=true)
constructor
Definition STK_IBasis.h:135
bool useDataValues_
Definition STK_IBasis.h:114
IBasis(Data const &data, int dim, bool useDataValues=true)
constructor
Definition STK_IBasis.h:145
int dim_
number of dimension to build
Definition STK_IBasis.h:112
Type minValue() const
Definition STK_IBasis.h:81
IBasis(IBasis const &basis)
copy constructor.
Definition STK_IBasis.h:156
IBasis()
default constructor
Definition STK_IBasis.h:125
Type maxValue() const
Definition STK_IBasis.h:83
void setMinValue(Type const &minValue)
Definition STK_IBasis.h:97
Coefs coefficients_
Array2D of the coefficients.
Definition STK_IBasis.h:121
Coefs const & coefficients() const
Definition STK_IBasis.h:79
Abstract base class for all classes having a.
Definition STK_IRunner.h:65
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...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
hidden::SliceVisitorSelector< Derived, hidden::MaxVisitor, Arrays::by_col_ >::type_result max(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.