English Français

Documentation / Manuel développeur

Modules disponibles

Calibration,  DataServer,  Launcher,  MetaModelOptim,  Modeler,  Optimizer,  ReLauncher,  Reliability,  ReOptimizer,  Sampler,  Sensitivity,  UncertModeler,  XmlProblem,   Uranie / Calibration: TDistanceFunction.h Source File
Uranie / Calibration  v4.10.0
/* @license-end */
TDistanceFunction.h
Go to the documentation of this file.
1 // 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 
48 #ifndef TDISTANCEFUNCTION_H
49 #define TDISTANCEFUNCTION_H
50 
51 // Root
52 #include "TMatrixD.h"
53 #include "TRandom3.h"
54 
56 #include "Calibration.h"
57 #include "TStandardEval.h"
58 #include "TRun.h"
59 #include "TCode.h"
60 #include "TLauncher.h"
61 
62 namespace URANIE
63 {
64 namespace Calibration
65 {
66 
67 class TDistanceFunction: public URANIE::Relauncher::TDoubleEval
68 {
69 
70 
71 public:
72 
73  URANIE::DataServer::TDataServer *_tdsEval;
74  URANIE::DataServer::TDataServer *_tdsObs;
75  URANIE::DataServer::TDSNtupleD *_allData;
76 
77 protected:
78  //Name of the variables
79  vector<string> _vrefName;
80  vector<string> _voutName;
81  vector<string> _vparName;
82 
83  //Storing data
84  vector<vector<double> > _yObs;
85  vector<vector<double> > _yExp;
86  TMatrixD _mObsCovMat;
87  TMatrixD _myObs;
88  TMatrixD _myExp;
89  unsigned int _nObs;
90  unsigned int _nVar;
91  unsigned int _nPar;
92  vector<double> _vParValues;
93 
94  //Weights for events and variables
95  vector<double> _varWeights;
96  vector<vector<double> > _obsWeights;
97 
98  URANIE::Relauncher::TRun *_run;
99  TString _tlcType;
101  URANIE::Launcher::TCode *_code;
102  TString _funcName;
103  void (*_pFunction)(double *, double *);
104  TString _varexpinput;
105  TString _varexpoutput;
106 
107  // Options
109  bool _bsaveAll;
110  bool _buseMatrix;
111  bool _blog;
112  bool _dumpAllTds;
115 
116  // Iterators
117  int _icalc;
118  unsigned int _ivar, _iobs;
119 
120  // Attribute
122 
123  //Random noise
124  TRandom3 *_rand;
125  int _nSeed;
126  TMatrixD _mSigma;
127  bool _boolNoise;
128 
129 public:
130 
140  //---------------------------------------------
144 
149  TDistanceFunction(URANIE::DataServer::TDataServer *tdsEval, URANIE::DataServer::TDataServer *tdsObs, const char *reference, const char *output, const char *weight="");
150 
152  virtual ~TDistanceFunction();
154 
155 
156  //---------------------------------------------
160 
162  void fillInOutAtt(URANIE::DataServer::TDataServer *tdsPar);
163  void initParameters(URANIE::DataServer::TDataServer *tdsPar, URANIE::Relauncher::TRun *run);
164  void initParameters(URANIE::DataServer::TDataServer *tdsPar, const char* funcName, const char *varexpinput, const char *varexpoutput);
165  void initParameters(URANIE::DataServer::TDataServer *tdsPar, void (*fcn)(Double_t*,Double_t*), const char *varexpinput, const char *varexpoutput);
166  void initParameters(URANIE::DataServer::TDataServer *tdsPar, URANIE::Launcher::TCode *Code);
167 
174  Int_t eval(Double_t* theta, Double_t* res, int=0);
175 
180  void runConfiguration(double *theta);
181 
183 
184 
185  //---------------------------------------------
189 
191  vector<vector<double> > getObservationVector() {
192  try{
193  if( _buseMatrix == true )
194  throw URANIE::Exceptions::UErrorExceptions(__FILE__, __LINE__,
195  "TDistanceFunction::getObservationVector. This distancefunction is using matrix. Please call getObservationMatrix() instead");
196 
197  } catch (URANIE::Exceptions::UErrorExceptions& ue)
198  {
199  ue.printMessage();
200  throw ue;
201  }
202  return _yObs;
203  }
204 
206  TMatrixD getObservationMatrix() {
207  try{
208  if( _buseMatrix == false )
209  throw URANIE::Exceptions::UErrorExceptions(__FILE__, __LINE__,
210  "TDistanceFunction::getObservationMatrix. This distancefunction is using vectors. Please call getObservationVector() instead");
211 
212  } catch (URANIE::Exceptions::UErrorExceptions& ue)
213  {
214  ue.printMessage();
215  throw ue;
216  }
217  return _myObs;
218  }
219 
221  void setSaveAllEvaluations(bool value)
222  {
223  _bsaveAll = value;
224  }
225 
227  void changeLauncher(TString tlcName);
228 
230  void changeCodeLauncherOpt(TString opt){
231  _codeLauncherOpt=opt;
232  }
233 
235  _dumpAllTds=true;
236  }
237 
239  _keepParValue=true;
240  }
241 
242  void dumpDetails(){
243  _bdumpDetails=true;
244  }
245 
247  void addCodeLauncherOpt(TString opt){
248  _codeLauncherOpt+=","+opt;
249  }
250 
252  void setUseMatrix(bool value)
253  {
254  _buseMatrix = value;
255  getData(true);
256  }
257 
259  void setVarWeights( int nwei, double *wei);
261  void setVarWeights(vector<double> wei);
262 
264  void setObservationCovarianceMatrix(TMatrixD &mat);
265 
268  return _bsaveAll;
269  }
270 
272  bool getUseMatrix() {
273  return _buseMatrix;
274  }
275 
277  void setGaussianRandomNoise(const char *stdname);
278 
280  void setSeed(UInt_t nval)
281  {
282  _nSeed = nval;
283  }
284 
285 
287 
288 
289  //---------------------------------------------
293  void setLog()
294  {
295  _blog = kTRUE;
296  }
297  void unsetLog()
298  {
299  _blog = kFALSE;
300  }
301  void changeLog()
302  {
303  _blog = !_blog;
304  }
305  Bool_t getLog()
306  {
307  return _blog;
308  }
309  virtual void printLog(Option_t *option = "");
311 
312 
313 protected:
314  //---------------------------------------------
318 
323  void getData(bool reference=false);
324 
329  virtual Int_t localeval(Double_t* res)=0;
330 
332 
333 
334  ClassDef(URANIE::Calibration::TDistanceFunction, ID_CALIBRATION)
335 };
336 
337 } // Fin du namespace Calibration
338 } // Fin du namespace URANIE
339 #endif
Definition: TABC.cxx:45
void addCodeLauncherOpt(TString opt)
add options to the already of the code launcher
Definition: TDistanceFunction.h:247
unsigned int _nVar
Number of variables;.
Definition: TDistanceFunction.h:90
URANIE::DataServer::TDataServer * _tdsObs
pointer toward the reference dataserver
Definition: TDistanceFunction.h:74
TDistanceFunction(URANIE::DataServer::TDataServer *tdsEval, URANIE::DataServer::TDataServer *tdsObs, const char *reference, const char *output, const char *weight="")
Standard constructor.
vector< vector< double > > getObservationVector()
Return the observation vector of vector.
Definition: TDistanceFunction.h:191
bool _buseMatrix
Use matrix instead of vectors.
Definition: TDistanceFunction.h:110
vector< vector< double > > _yExp
Vector of tested values (size: _nVar <_nObs>)
Definition: TDistanceFunction.h:85
URANIE::Relauncher::TRun * _run
Definition: TDistanceFunction.h:98
vector< string > _vparName
Vector of parameters name.
Definition: TDistanceFunction.h:81
vector< vector< double > > _obsWeights
Vector of observation weights outputs (size: _nObs)
Definition: TDistanceFunction.h:96
void dumpAllDataservers()
Definition: TDistanceFunction.h:234
void dumpDetails()
Definition: TDistanceFunction.h:242
vector< string > _vrefName
Vector of reference name.
Definition: TDistanceFunction.h:79
void(* _pFunction)(double *, double *)
Function pointer.
Definition: TDistanceFunction.h:103
bool _bsaveAll
Whether all evaluations should be saved, not only a priori and a posteriori.
Definition: TDistanceFunction.h:109
void setUseMatrix(bool value)
Choose whether vector of vector or matrix should be used in the distance function localeval method...
Definition: TDistanceFunction.h:252
TString _varexpinput
Definition: TDistanceFunction.h:104
TMatrixD getObservationMatrix()
Return the observation matrix.
Definition: TDistanceFunction.h:206
void keepParametersValue()
Definition: TDistanceFunction.h:238
TString _tlcType
Definition: TDistanceFunction.h:99
vector< double > _vParValues
Definition: TDistanceFunction.h:92
virtual void printLog(Option_t *option="")
unsigned int _iobs
Definition: TDistanceFunction.h:118
Description of the class TDistanceFunction.
Definition: TDistanceFunction.h:67
unsigned int _ivar
Definition: TDistanceFunction.h:118
vector< double > _varWeights
Vector of variable weights (size: _nVar)
Definition: TDistanceFunction.h:95
void setVarWeights(int nwei, double *wei)
Set a weight to ponderate variable when _nVar >1.
bool _dumpAllTds
dump all tested dataserver;
Definition: TDistanceFunction.h:112
TMatrixD _mObsCovMat
Observation Covariance matrix.
Definition: TDistanceFunction.h:86
void initParameters(URANIE::DataServer::TDataServer *tdsPar, URANIE::Relauncher::TRun *run)
TMatrixD _myObs
Vector of observations outputs (size: _nVar < _nObs >)
Definition: TDistanceFunction.h:87
TString _funcName
Definition: TDistanceFunction.h:102
URANIE::DataServer::TDSNtupleD * _allData
pointer toward the reference dataserver
Definition: TDistanceFunction.h:75
bool _keepParValue
Keep the parameters values in runner case.
Definition: TDistanceFunction.h:113
virtual ~TDistanceFunction()
Default destructor.
void fillInOutAtt(URANIE::DataServer::TDataServer *tdsPar)
Internal initialisation method.
void setGaussianRandomNoise(const char *stdname)
Set Normal random noise for an output variable.
virtual Int_t localeval(Double_t *res)=0
Use the reference and the newly obtained estimations to compute a distance.
URANIE::DataServer::TDataServer * _tdsEval
pointer toward the evaluation dataserver
Definition: TDistanceFunction.h:73
void setObservationCovarianceMatrix(TMatrixD &mat)
set the observatiton covariance matrix
TList * _listOfParameters
list of parameters
Definition: TDistanceFunction.h:121
void changeLog()
Definition: TDistanceFunction.h:301
TMatrixD _myExp
Vector of tested values (size: _nVar <_nObs>)
Definition: TDistanceFunction.h:88
vector< string > _voutName
Vector of output name.
Definition: TDistanceFunction.h:80
bool _blog
Boolean to decide if the log information is shown or not.
Definition: TDistanceFunction.h:111
TRandom3 * _rand
The random generator.
Definition: TDistanceFunction.h:124
void runConfiguration(double *theta)
Runs the code provided on the reference input to get estimations.
void setSaveAllEvaluations(bool value)
Choose whether every evaluations should be kept (might slown down the process)
Definition: TDistanceFunction.h:221
int _icalc
Calcul iterator;.
Definition: TDistanceFunction.h:117
void setSeed(UInt_t nval)
Set the seed of the random generator if one is used.
Definition: TDistanceFunction.h:280
TString _varexpoutput
Definition: TDistanceFunction.h:105
unsigned int _nObs
Number of observations.
Definition: TDistanceFunction.h:89
TString _codeLauncherOpt
Option for code launcher.
Definition: TDistanceFunction.h:100
URANIE::Launcher::TCode * _code
Definition: TDistanceFunction.h:101
Bool_t getLog()
Definition: TDistanceFunction.h:305
void changeLauncher(TString tlcName)
Change the code launcher.
void changeCodeLauncherOpt(TString opt)
Change the option of the code launcher.
Definition: TDistanceFunction.h:230
bool _baprioriSet
Whether apriori is set to evaluator.
Definition: TDistanceFunction.h:108
void unsetLog()
Definition: TDistanceFunction.h:297
vector< vector< double > > _yObs
Vector of observations outputs (size: _nVar < _nObs >)
Definition: TDistanceFunction.h:84
Int_t eval(Double_t *theta, Double_t *res, int=0)
Official method inherited from TSimpleEval, it is the main method of a DF It calls three methods in a...
bool _bdumpDetails
Dump the details in Distance Computation.
Definition: TDistanceFunction.h:114
TMatrixD _mSigma
Vector of variance of errors.
Definition: TDistanceFunction.h:126
bool getSaveAllEvaluation()
Check the value of the saveAll option.
Definition: TDistanceFunction.h:267
bool _boolNoise
Whether noise is add to the output.
Definition: TDistanceFunction.h:127
int _nSeed
The seed of the random generator.
Definition: TDistanceFunction.h:125
bool getUseMatrix()
Check the value of the useMatrix option.
Definition: TDistanceFunction.h:272
void getData(bool reference=false)
Get the data either the reference one, or the estimated one for a given parameter configuration...
void setLog()
Definition: TDistanceFunction.h:293
unsigned int _nPar
Number of Parameters;.
Definition: TDistanceFunction.h:91