English Français

Documentation / Manuel développeur

Modules disponibles

Calibration,  DataServer,  Launcher,  MetaModelOptim,  Modeler,  Optimizer,  ReLauncher,  Reliability,  ReOptimizer,  Sampler,  Sensitivity,  UncertModeler,  XmlProblem,   Uranie / Modeler: TANNModeler.h Source File
Uranie / Modeler v4.9.0
/* @license-end */
TANNModeler.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2024 CEA/DES
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 published
6// by the Free Software Foundation, either version 3 of the License, or any
7// 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 License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
18// $Id$
19// $Author$
20// $Date$
21// $Revision$
22// $State$
24
32#ifndef TANNMODELER_H
33#define TANNMODELER_H
34
35// Newmat
36#include "newmat.h"
37using namespace NEWMAT;
38
39#include <iostream>
40
41//ROOT
42#include "Rtypes.h"
43#include "TNamed.h"
44
45//Uranie
46#include "Modeler.h"
47#include "TModeler.h"
48#include "TDataServer.h"
49#include "TPatternsEventList.h"
50#include "UMLP.h"
51
52// GPU training of ANN
53#if defined(WITH_GPUANN) && !defined(__CINT__)
54#include "nn_headers.h"
55namespace NNLM = NeuralNetworkLevenbergMarquardt;
56#endif
57
58
59namespace URANIE
60{
61namespace Modeler
62{
63
64class TempSolution;
65
66class TANNModeler: public TModeler
67{
68public:
72
77 // Attributes
78protected:
79 Int_t _nSeed;
80
81private:
82 Int_t _nInput;
83 Int_t _nHidden;
85 Int_t _nOutput;
86 Int_t _nNeurons;
87
88 Int_t _nApp;
89 Int_t _nTest;
90 Double_t _dLearn;
91 Double_t _dTest;
92 Double_t _dWeightDecay;
93 URANIE::DataServer::TPatternsEventList * _elAll;
94 Bool_t _bMix;
95
96 TString _sArchi;
97 TString _sInput;
98 TString _sHidden;
99 TString _sOutput;
100
101 Int_t _nWeight;
102
113 ColumnVector _vecWeights;
114 TempSolution * _tmpSolution;
115
116
117 ColumnVector _vecMinValues;
118 ColumnVector _vecMaxValues;
119
120
122 //---------------------------------------------
126 Double_t _dFcnTol;
129
131 Double_t * _dval; // size: _nInput+1 (a full training vector = input + (a single) output)
132
134 static const int OPTIM_MAX_ITER = 10000; //<! Maximal number of iterations in the optimization algorithms
135 static const int OPTIM_MAX_FEVAL = 50000; //<! Maximal number of evaluations in the optimization algorithms
136public:
137 Bool_t _blog;
138 URANIE::DataServer::TDataServer *_tds;
139 UMLP *_UMLP;
140public:
141 //---------------------------------------------
145
146 TANNModeler(URANIE::DataServer::TDataServer *tds, TString architecture,
147 Double_t dratio = 0.80, Option_t *option = "");
148#ifdef WITH_LIBXML2
150 TANNModeler (URANIE::DataServer::TDataServer *tds, const char* pmmlfile, const char* ANNname, Double_t dratio = 0.80, Option_t *option ="");
151#endif
153 virtual ~TANNModeler();
155 //---------------------------------------------
159
160 Int_t getNInput()
161 {
162 return _nInput;
163 }
166 {
167 return _nHidden;
168 }
171 {
172 return _nOutput;
173 }
175 Int_t getNAPP()
176 {
177 return _nApp;
178 }
180 Int_t getNTest()
181 {
182 return _nTest;
183 }
184
186 void setWeights(ColumnVector weights)
187 {
188 _vecWeights = weights;
189 }
190 ColumnVector getWeights()
191 {
192 return _vecWeights;
193 }
194
196
199 Double_t getWeight(Int_t ind)
200 {
201 return _vecWeights(ind + 1);
202 }
203
204 Double_t getMinValue(Int_t ind)
205 {
206 return _vecMinValues(ind);
207 }
208 Double_t getMaxValue(Int_t ind)
209 {
210 return _vecMaxValues(ind);
211 }
212 Double_t * getdval()
213 {
214 return _dval;
215 }
216
217 void setValue(Int_t ind, Int_t &ncrt, Double_t *xy, Bool_t normalize=true);
218
219 void setDataSet(URANIE::DataServer::TPatternsEventList* tel)
220 {
221 _elAll = tel;
222 }
223
224 void setMix(Bool_t bmix = kTRUE)
225 {
226 _bMix = bmix;
227 }
228 void setFcnTol(Double_t dprec)
229 {
230 _dFcnTol = dprec;
231 }
232 Double_t getFcnTol()
233 {
234 return _dFcnTol;
235 }
236
241 {
242 return _nNormType;
243 }
244
248
253 void setSeed(Int_t ind = 0);
255 Int_t getSeed()
256 {
257 return _nSeed;
258 }
260 const char * getInputName(Int_t i)
261 {
262 URANIE::DataServer::TAttribute *att;
263 att = (URANIE::DataServer::TAttribute *) _listOfAttributes->At(i);
264 return att->GetName();
265 }
267 const char * getOutputName()
268 {
269 return _sOutput.Data();
270 }
272
273 //---------------------------------------------
277 // Init the ANN
278 void init();
286#ifdef WITH_GPUANN
287 void train(Int_t niter = 10, Int_t nInit = 10, Option_t* option = "text", Bool_t useGPU = true);
288#else
289 void train(Int_t niter = 10, Int_t nInit = 10, Option_t* option = "text", Bool_t useGPU = false);
290#endif
292
295 Double_t getEQM(Option_t* option = "");
297 Double_t getWeightDecay()
298 {
299 return _dWeightDecay;
300 }
301
303 void saveIfBetter(const ColumnVector & weights, Double_t eqm_app, Double_t eqm_tst);
304
306
307 //---------------------------------------------
327
337// void exportFunction(const char* lang, const char* file = "",
338// const char* name = "", Option_t *option = "");
340 void exportModelCplusplus(const char* file = "", const char* name = "",
341 Option_t *option = "") const;
342// /*!
343// \todo Write this method as a TModeler method
344// */
345 void exportModelCplusplus(std::ofstream * sourcefile) const;
346// {
347// cerr
348// << " --- Method TANNModeler::exportModelCplusplus(ofstream * sourcefile) not yet implemented"
349// << endl;
350// cerr
351// << " --- Then using the method TANNModeler::exportModelCplusplus(file, name, option)"
352// << endl;
353// }
354// ;
355
357 void exportModelPMML(const char* file = "", const char* name = "", Option_t *option = "") const;
359 void exportModelFortran(const char* file, const char* name, Option_t *option = "") ;
363 void exportModelFortran(std::ofstream * sourcefile) const;
364// {
365// std::cerr
366// << " --- Method TANNModeler::exportModelFortran(ofstream * sourcefile) not yet implemented"
367// << endl;
368// std::cerr
369// << " --- Then using the method TANNModeler::exportModelFortran(file, name, option)"
370// << endl;
371// }
372// ;
373
374
376
380 void exportModelPython(std::ofstream * sourcefile) const
381 {
382 UNUSED(sourcefile);
383 std::cerr
384 << " --- Method TANNModeler::exportModelPython(ofstream * sourcefile) not yet implemented"
385 << endl;
386 };
388
389 //---------------------------------------------
393 virtual void printLog(Option_t *option = "");
395 ClassDef(URANIE::Modeler::TANNModeler, ID_MODELER)
396 //Classe def
397
398private:
399 void train_cpu(Int_t niter, Int_t nInit, Bool_t randomizeweights);
400
401#if defined(WITH_GPUANN)
402 void train_gpu(NNLM::NeuronType T, Int_t niter, Int_t nInit, Bool_t randomizeweights);
403#endif
404
405};
406} // Fin du namespace Modeler
407} // Fin du namespace URANIE
408
410
411#endif
R__EXTERN URANIE::Modeler::TANNModeler * gUranieANNModeler
Definition TANNModeler.h:409
Interface of the class URANIE::Optimize::TModeler.
Definition TANNModeler.h:67
void setValue(Int_t ind, Int_t &ncrt, Double_t *xy, Bool_t normalize=true)
EProblem getProblem()
Get the problem type.
Definition TANNModeler.h:246
ENorm _nNormType
! The function tolerance for the trust region algorithm
Definition TANNModeler.h:127
Int_t _nInput
! Seed for the random weight initialization
Definition TANNModeler.h:82
TList * _listOfAttributes
! Max values, used for normalization
Definition TANNModeler.h:121
void randomizeWeights()
randomize the weights
Double_t _dFcnTol
Definition TANNModeler.h:126
EProblem _nProlemType
! The normalized for input and output
Definition TANNModeler.h:128
Double_t getWeight(Int_t ind)
Returns the weight givent by the index.
Definition TANNModeler.h:199
ColumnVector getWeights()
Definition TANNModeler.h:190
void setDataSet(URANIE::DataServer::TPatternsEventList *tel)
Definition TANNModeler.h:219
Double_t * _dval
! The type of problem (Regression, Classification)
Definition TANNModeler.h:131
ColumnVector _vecMaxValues
! Min values, used for normalization
Definition TANNModeler.h:118
void setWeights(ColumnVector weights)
Sets the weigts.
Definition TANNModeler.h:186
void exportModelCplusplus(const char *file="", const char *name="", Option_t *option="") const
The only user interface method.
void saveIfBetter(const ColumnVector &weights, Double_t eqm_app, Double_t eqm_tst)
Save a vector of weight if the RMS on the test database is better than what we currently have.
Int_t getSeed()
Returns the seed value.
Definition TANNModeler.h:255
Int_t _nApp
! The number of neurons
Definition TANNModeler.h:88
ColumnVector _vecWeights
! The number of weights
Definition TANNModeler.h:113
ENorm
Definition TANNModeler.h:74
@ kMinusOneOne
Definition TANNModeler.h:75
@ kZeroOne
Definition TANNModeler.h:75
@ kCR
Definition TANNModeler.h:75
void setNormalization(ENorm n)
Sets the normalisation.
Int_t _nWeight
Definition TANNModeler.h:101
Bool_t _blog
Boolean for edit the log.
Definition TANNModeler.h:137
Double_t getMinValue(Int_t ind)
Definition TANNModeler.h:204
const char * getOutputName()
Get the attribute name of the output.
Definition TANNModeler.h:267
TANNModeler(URANIE::DataServer::TDataServer *tds, TString architecture, Double_t dratio=0.80, Option_t *option="")
Constructor with a dataserver.
void exportModelPython(std::ofstream *sourcefile) const
Export the model in Python langage in a file (not yet implemented)
Definition TANNModeler.h:380
Double_t * getdval()
Definition TANNModeler.h:212
Int_t getNHidden()
Gets the number of hidden neurons.
Definition TANNModeler.h:165
Double_t _dLearn
! Number of samples in the training set dedicated to validation
Definition TANNModeler.h:90
UMLP * _UMLP
Pointeur vers un TDS.
Definition TANNModeler.h:139
Double_t getWeightDecay()
Get the weight decay parameter.
Definition TANNModeler.h:297
TempSolution * _tmpSolution
Definition TANNModeler.h:114
Int_t getNInput()
Gets the number of input.
Definition TANNModeler.h:160
TString _sInput
! The architecture, e.g. "x:y:z,3,yhat" specifying inputs, number of hidden neurons,...
Definition TANNModeler.h:97
ENorm getNormalization()
Get the normalisation.
Definition TANNModeler.h:240
ColumnVector _vecMinValues
Definition TANNModeler.h:117
Double_t getFcnTol()
Definition TANNModeler.h:232
Int_t getNOutput()
Gets the number of output.
Definition TANNModeler.h:170
void exportModelFortran(std::ofstream *sourcefile) const
virtual ~TANNModeler()
Default destructor.
const char * getInputName(Int_t i)
Return the name of input attributes indexed by i.
Definition TANNModeler.h:260
Int_t _nHidden
! The number of inputs
Definition TANNModeler.h:83
void setMix(Bool_t bmix=kTRUE)
Definition TANNModeler.h:224
static const int OPTIM_MAX_FEVAL
Definition TANNModeler.h:135
Double_t getMaxValue(Int_t ind)
Definition TANNModeler.h:208
void setSeed(Int_t ind=0)
Init the seed.
Double_t _dTest
! The learning quality
Definition TANNModeler.h:91
TString _sArchi
! True if data set must be mixed
Definition TANNModeler.h:96
TString _sOutput
Definition TANNModeler.h:99
Bool_t _bMix
! The mix list of patterns
Definition TANNModeler.h:94
Int_t _nSeed
Definition TANNModeler.h:79
Double_t _dWeightDecay
! The test quality
Definition TANNModeler.h:92
Int_t _nHiddenLayer
! The number of hidden neurons
Definition TANNModeler.h:84
TString _sHidden
Definition TANNModeler.h:98
URANIE::DataServer::TDataServer * _tds
Definition TANNModeler.h:138
URANIE::DataServer::TPatternsEventList * _elAll
! The weight decay parameter - when used, favorize a smoother ANN
Definition TANNModeler.h:93
Int_t _nTest
! Number of samples in the training set dedicated to back-propagation
Definition TANNModeler.h:89
Int_t getNAPP()
Gets the number of pure training patterns ("APPrentissage")
Definition TANNModeler.h:175
Double_t getEQM(Option_t *option="")
Gets the EQM.
void train(Int_t niter=10, Int_t nInit=10, Option_t *option="text", Bool_t useGPU=false)
Int_t _nOutput
! the number of hidden layer
Definition TANNModeler.h:85
void setFcnTol(Double_t dprec)
Definition TANNModeler.h:228
virtual void printLog(Option_t *option="")
static const int OPTIM_MAX_ITER
Definition TANNModeler.h:134
Int_t getNTest()
Gets the number of pure training patterns ("APPrentissage")
Definition TANNModeler.h:180
Int_t _nNeurons
! The number of outputs
Definition TANNModeler.h:86
EProblem
Definition TANNModeler.h:69
@ kClassification
Definition TANNModeler.h:70
@ kRegression
Definition TANNModeler.h:70
Definition TModeler.h:63
virtual void exportModelPMML(const char *file="", const char *name="", Option_t *option="") const =0
Export the model in a PMML file.
ROOT.
Definition TAnisp.h:164