STK++ 0.9.13
STK_IClassification.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::Classif
27 * created on: 23 juin 2010
28 * Purpose: Interface base class for classification methods.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 **/
31
36#ifndef STK_ICLASSIFICATION_H
37#define STK_ICLASSIFICATION_H
38
39#include <Sdk.h>
40
41namespace STK
42{
43
102template <class YArray_, class XArray_, class Weights_>
103class IClassification: public IRunnerSupervised<YArray_, XArray_, Weights_>
104{
105 protected:
107 using Base::p_x_;
108 using Base::p_y_;
114 IClassification( YArray_ const* p_y, XArray_ const* p_x);
118 IClassification( YArray_ const& y, XArray_ const& x);
119
120 public:
122 virtual ~IClassification() {}
123
125 inline int nbClass() const { return nbClass_;}
127 inline int nbFreeParameter() const { return nbFreeParameter_;}
128
130 virtual bool run()
131 {
132 if (!p_x_ || !p_y_)
134 return false;
135 }
136 bool flag=true;
137 // perform any initialization step needed before the classification step
138 if (!initializeStep()) { flag = false;}
139 // compute the classification
140 if (!estimationStep()) { flag = false;}
141
142 // perform any post-operation needed after the classification step
143 if (!finalizeStep()) { flag = false;}
144 // Compute the number of parameter of the classification function.
146 // create array of the predicted value and compute prediction
147 if (!predictionStep()) { flag = false;}
148 // return the result of the computations
149 this->hasRun_ = true;
150 return flag;
151 }
155 virtual bool run( Weights_ const& weights)
156 {
157
158 if (!p_x_ || !p_y_)
160 return false;
161 }
162 bool flag=true;
163 // perform any pre-operation needed before the classification step
164 if (!initializeStep()) { flag = false;}
165 // compute weighted classification
166 if (!estimationStep(weights)) { flag = false;}
167
168 // perform any post-operation needed after the classification step
169 if (!finalizeStep()) { flag = false;}
170 // Compute the number of parameter of the classification function.
172 // create array of the predicted value and compute prediction
173 if (!predictionStep()) { flag = false;}
174
175 // return the result of the computations
176 this->hasRun_ = true;
177 return flag;
178 }
179
180 protected:
185
189 virtual bool initializeStep() {return true;}
193 virtual bool predictionStep() {return true;};
197 virtual bool finalizeStep() {return true;}
198
199 private:
201 virtual bool estimationStep() =0;
205 virtual bool estimationStep(Weights_ const& weights) =0;
209 virtual int computeNbFreeParameter() const =0;
210};
211
212/* Default constructor. Initialize the data members. */
213template <class YArray_, class XArray_, class Weights_>
215
216/* Constructor. Initialize the data members.
217 * @param p_y,p_x pointer array with the observed output and output
218 **/
219template <class YArray_, class XArray_, class Weights_>
221 : Base(p_y, p_x)
222 , nbClass_(0)
223 , nbFreeParameter_(0)
224{}
225
226/* Constructor. Initialize the data members.
227 * @param y,x arrays with the observed output and input
228 **/
229template <class YArray_, class XArray_, class Weights_>
231 : Base(y, x)
232 , nbClass_(0)
233 , nbFreeParameter_(0)
234{}
235
236} // namespace STK
237
238#endif /* STK_ICLASSIFICATION_H */
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
This file include all the other header files of the project Sdk.
Interface base class for Regression methods.
IRunnerSupervised< YArray_, XArray_, Weights_ > Base
virtual bool finalizeStep()
perform any computation needed after the call of the classification method.
int nbFreeParameter_
number of parameter of the classification method.
virtual bool predictionStep()
Compute the predicted outputs by the classification function and store the result in the p_predicted_...
virtual int computeNbFreeParameter() const =0
Compute the number of parameter of the classification function.
virtual bool run()
run the computations.
virtual bool estimationStep(Weights_ const &weights)=0
compute the weighted classification function.
virtual bool initializeStep()
perform any computation needed before the call of the classification method.
virtual bool run(Weights_ const &weights)
run the weighted computations.
YArray_ const * p_y_
A pointer on the y data set.
virtual ~IClassification()
virtual destructor.
int nbClass_
number of class
XArray_ const * p_x_
A pointer on the x data set.
virtual bool estimationStep()=0
compute the classification function.
IClassification()
Default constructor.
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
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...
The namespace STK is the main domain space of the Statistical ToolKit project.