STK++ 0.9.13
STK_IRegression.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 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: 23 juin 2010
28 * Purpose: Interface base class for regression methods.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 **/
31
36#ifndef STK_IREGRESSION_H
37#define STK_IREGRESSION_H
38
39#include <STKernel.h>
40
41namespace STK
42{
43
106template <class YArray, class XArray, class Weights>
107class IRegression: public IRunnerSupervised<YArray, XArray, Weights>
108{
109 protected:
111 using Base::p_x_;
112 using Base::p_y_;
119 : Base((p_y == 0) ? 0 : p_y->asPtrDerived(), (p_x == 0) ? 0 : p_x->asPtrDerived())
120 , predicted_()
121 , residuals_()
123 {}
128 : Base(y.asDerived(), x.asDerived())
129 , predicted_()
130 , residuals_()
132 {}
133
134 public:
136 virtual ~IRegression() {}
137
139 inline YArray const& predicted() const { return predicted_;}
141 inline YArray const& residuals() const { return residuals_;}
142
144 inline YArray* p_predicted() { return &predicted_;}
146 inline YArray* p_residuals() { return &residuals_;}
147
149 inline int nbFreeParameter() const { return nbFreeParameter_;}
150
152 virtual bool run();
156 virtual bool run( Weights const& weights);
162 virtual YArray extrapolate(XArray const& x) const =0;
163
164 protected:
168 virtual bool initializeStep() { return true;}
172 virtual bool finalizeStep() { return true;}
177 inline bool residualsStep()
178 {
180 return true;
181 }
182
187
188 private:
192 virtual bool regressionStep() =0;
196 virtual bool regressionStep(Weights const& weights) =0;
199 virtual bool predictionStep() =0;
203 virtual int computeNbFreeParameter() const =0;
204};
205
207template <class YArray, class XArray, class Weights>
209{
210 // perform any initialization step needed before the regression step
211 if (!initializeStep()) { return false;}
212 // compute the regression
213 if (!regressionStep()) { return false;}
214 // Compute the number of parameter of the regression function.
216 // compute predictions
218 // compute residuals
220 // perform any post-operation needed before the regression step
221 finalizeStep();
222 // return the result of the computations
223 this->hasRun_ = true;
224 return true;
225}
226
228template <class YArray, class XArray, class Weights>
230{
231 // perform any pre-operation needed before the regression step
232 if (!initializeStep()) { return false;}
233 // compute weighted regression
234 if (!regressionStep(weights)) { return false;}
235 // Compute the number of parameter of the regression function.
237 // create array of the predicted value and compute prediction
239 // create array of the residuals and compute them
241 // perform any post-operation needed before the regression step
242 finalizeStep();
243 // return the result of the computations
244 this->hasRun_ = true;
245 return true;
246}
247
248} // namespace STK
249
250#endif /* STK_IREGRESSION_H */
This file include all the header files of the project STKernel.
Interface base class for Regression methods.
virtual bool run()
run the computations.
virtual ~IRegression()
virtual destructor.
bool residualsStep()
Compute the residuals of the model.
virtual bool regressionStep()=0
compute the regression function.
virtual bool finalizeStep()
perform any computation needed after the call of the regression method.
int nbFreeParameter_
number of parameter of the regression method.
YArray residuals_
Container of the residuals.
YArray predicted_
Container of the predicted output.
YArray const & residuals() const
virtual bool initializeStep()
perform any computation needed before the call of the regression method.
int nbFreeParameter() const
IRunnerSupervised< YArray, XArray, Weights > Base
virtual bool predictionStep()=0
Compute the predicted outputs by the regression function and store the result in the p_predicted_ arr...
IRegression(ArrayBase< YArray > const *p_y, ArrayBase< XArray > const *p_x)
constructor
virtual bool regressionStep(Weights const &weights)=0
compute the weighted regression function.
virtual bool run(Weights const &weights)
run the weighted computations.
IRegression()
Default constructor.
YArray const & predicted() const
IRegression(ArrayBase< YArray > const &y, ArrayBase< XArray > const &x)
Constructor.
virtual int computeNbFreeParameter() const =0
Compute the number of parameter of the regression function.
virtual YArray extrapolate(XArray const &x) const =0
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
Abstract class for all classes making supervised learning.
YArray const * p_y_
A pointer on the y data set.
XArray const * p_x_
A pointer on the x data set.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
virtual bool predictionStep()
Compute the predicted outputs by the regression function.
virtual int computeNbFreeParameter() const
Compute the number of parameter of the regression function.
virtual bool regressionStep()
compute the regression function.
The namespace STK is the main domain space of the Statistical ToolKit project.