English Français

Documentation / Developer's manual

Available modules

Calibration,  DataServer,  Launcher,  MetaModelOptim,  Modeler,  Optimizer,  ReLauncher,  Reliability,  ReOptimizer,  Sampler,  Sensitivity,  UncertModeler,  XmlProblem,   Uranie / Optimizer: TSumOfSquares.h Source File
Uranie / Optimizer v4.9.0
/* @license-end */
TSumOfSquares.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
35#ifndef TSUMOFSQUARES_H
36#define TSUMOFSQUARES_H
37
38// ROOT
39#include "TH1.h"
40#include "TF1.h"
41#include "TPad.h"
42#include "TRandom3.h"
43#include "TVirtualFitter.h"
44#include "TStyle.h"
45#include "Minuit2/FCNBase.h"
46//fga 2015/01/12 #include "TFitterMinuit.h"
47#include "TSystem.h"
48#include "TMatrixT.h"
49
50#include <vector>
51#include <iostream>
52
53// URANIE
54#include "Optimizer.h"
55#include "TCode.h"
56#include "TDataServer.h"
57#include "TObjective.h"
58
59namespace URANIE
60{
61namespace Optimizer
62{
63class TSumOfSquares: public ROOT::Minuit2::FCNBase
64{
65private:
66 vector<TObjective *> _objectives;
67
68public:
69
71 _objectives(0), _ninput(0), _noutput(0), _tds(NULL), _code(NULL), _sCriteria("")
72 {
73 }
75 TSumOfSquares(URANIE::DataServer::TDataServer *tds,
76 URANIE::Launcher::TCode *code) :
77 _objectives(0), _tds(tds), _code(code), _sCriteria("")
78 {
79 init();
80 }
81
83 {
84 _dinputValue = NULL;
85 delete[] _dinputValue;
86 _doutputValue = NULL;
87 delete[] _doutputValue;
88
89 }
90
91 void init();
92
93 double operator()(const vector<double> & par) const
94 {
95 Int_t niter = _tds->getTuple()->GetEntries();
96 Double_t fval = -0.123456789;
97 _tds->getAttribute(_sCriteria)->getDefaultValue(fval);
98 // cout << " ** fval [ " << fval << "]" << endl;
99
100 Double_t dObjectives = 0.;
101
102 if (_code != NULL)
103 {
104 if (_code->getLog())
105 {
106 cout << endl << " ****** Step[" << niter << "]" << endl;
107 }
108 _dinputValue[0] = 1.0 + niter;
109 // Remark: If we want to save all computations, we need a constant Bool_t _bSave,
110 // and call the the method _code->init() at each new computation.
111 _code->init();
112 // Pretraitment of the data
113 Double_t valcrt = 1.23456789;
114 Int_t ncpt = 0;
115
116 // fga::modif le 2008-10-01 07:49:37
117 // attributes kConstant must be forgotten
118 for (int i = 0; i < _ninput; i++)
119 {
120 // end of fga::modif le 2008-10-01 07:49:37
121 URANIE::DataServer::TAttribute *att = _tds->getAttribute(i);
122 if (_code->getLog())
123 cout << " ** " << i << "/" << _ninput << " name ["
124 << att->GetName() << "]";
125 URANIE::DataServer::TAttribute::EOrigin norigin =
126 att->getOrigin();
127 switch (norigin)
128 {
129 case URANIE::DataServer::TAttribute::kConstant:
130 if (_code->getLog())
131 cout << " Origin[kConstant]";
132 att->getDefaultValue(valcrt);
133 break;
134 case URANIE::DataServer::TAttribute::kAttribute:
135 if (_code->getLog())
136 cout << " Origin[kAttribute]";
137 valcrt = par[ncpt++];
138 break;
139 default:
140 break;
141 }
142 _dinputValue[1 + i] = valcrt;
143 if (_code->getLog())
144 cout << " val[" << _dinputValue[1 + i] << "]" << endl;
145 }
146 int ind = 1;
147 _code->preTraitment(ind, _dinputValue);
148 // Launch the code
149 _code->run();
150 // Post-traitment of the data
151 ind = 0;
152 _code->postTraitment(ind, _doutputValue, "", _listOfDataOutput);
153 if (_code->getLog())
154 {
155 cout << endl << "*************************************" << endl
156 << " *** TSumOfSquares operator () _noutput["
157 << _noutput << "] ind[" << ind << "]" << endl;
158 for (Int_t ii = 0; ii <= _noutput; ii++)
159 cout << " ** ii(" << ii << "/" << _noutput << ") val("
160 << _doutputValue[ii] << ")" << endl;
161 cout << " *** End Of TFCNCode operator ()" << endl
162 << "*************************************" << endl;
163 }
164
165 TMatrixT<double> *lastmat =
166 (TMatrixT<double> *) _listOfDataOutput->Last();
167 if (_code->getLog())
168 lastmat->Print(Form("Matrice de sortie iteration[%d]", niter));
169 Int_t nrows = lastmat->GetNrows();
170 Int_t ncols = lastmat->GetNcols();
171 if (_code->getLog())
172 cout << " ** nrows[" << nrows << "] ncols[" << ncols << "]"
173 << endl;
174 Double_t *allvalues = new Double_t[nrows * ncols];
175 Double_t *dvalues = new Double_t[nrows];
176 allvalues = lastmat->GetMatrixArray();
177 // TMatrixT<double> *matOut = new TMatrixT<double>(nrows, 1);
178 Int_t ncrt = 0;
179 cout
180 << " **********************************************************"
181 << endl;
182 Double_t dweight;
183 Int_t nObjectives = (Int_t)(_objectives.size());
184 for (Int_t indx = 0; indx < nObjectives; indx++)
185 {
186 dweight = _objectives[indx]->getWeight();
187 if (_objectives[indx]->isActive())
188 {
189 if (_code->getLog())
190 _objectives[indx]->printLog();
191 ncrt = indx;
192 for (Int_t indy = 0; indy < nrows; indy++)
193 {
194 dvalues[indy] = allvalues[ncrt];
195 ncrt++;
196 // ncrt += nrows;
197 // cout << " ** indy[" << indy << "] val[" << dvalues[indy] << "]" << endl;
198 }
199 // matOut->Use(nrows, 1, dvalues);
200 Double_t dvalcrt = _objectives[indx]->getObjective(dvalues,
201 nrows);
202 dObjectives += dweight * dvalcrt;
203 cout << " ** Objective [" << indx + 1 << "/" << nObjectives
204 << "] name[" << _objectives[indx]->GetName()
205 << "] dweight[" << dweight << "] val[" << dvalcrt
206 << "] Sum [" << dObjectives << "]" << endl;
207 }
208 }
209 cout
210 << " **********************************************************"
211 << endl;
212 dObjectives /= (Double_t)(nObjectives);
213 cout << " ** Objective [" << dObjectives << "] nObjectives["
214 << nObjectives << "]" << endl;
215 cout
216 << " **********************************************************"
217 << endl;
218
219 fval = dObjectives;
220
221 //Fill the data
222 _dinputValue[_ninput + 1] = fval;
223 _tds->getTuple()->Fill(_dinputValue);
224 if (niter % 10)
225 {
226 _tds->Draw(
227 Form("%s:%s", _sCriteria.Data(),
228 _tds->getIteratorName()), "", "lp");
229 gPad->Modified();
230 gPad->Update();
231 }
232 }
233 return fval;
234 }
235
236 double Up() const
237 {
238 return 1.;
239 }
240
241 void clean();
242
244 {
245 _objectives.push_back(tobj);
246 }
248 {
249 return (Int_t)(_objectives.size());
250 }
251
252private:
254 double * _dinputValue;
257 URANIE::DataServer::TDataServer *_tds;
258 URANIE::Launcher::TCode *_code;
260 TString _sCriteria;
261
262 ClassDef(URANIE::Optimizer::TSumOfSquares, ID_OPTIMIZER)
263 //Classe de
264};
265} // Fin du namespace Optimizer
266} // Fin du namespace URANIE
267#endif
268
Interface of class URANIE::Optimize::TObjective.
Description of the class TObjective. This class computes the ojective (from L2 point of view).
Definition TObjective.h:62
Definition TSumOfSquares.h:64
URANIE::DataServer::TDataServer * _tds
Definition TSumOfSquares.h:257
Int_t getNObjectives()
Definition TSumOfSquares.h:247
TList * _listOfDataOutput
Pointer vers un TCode.
Definition TSumOfSquares.h:259
URANIE::Launcher::TCode * _code
Pointer vers un TDS.
Definition TSumOfSquares.h:258
int _noutput
Definition TSumOfSquares.h:255
TSumOfSquares()
Definition TSumOfSquares.h:70
double * _doutputValue
Definition TSumOfSquares.h:256
TSumOfSquares(URANIE::DataServer::TDataServer *tds, URANIE::Launcher::TCode *code)
Constructor with a dataserver.
Definition TSumOfSquares.h:75
double Up() const
Definition TSumOfSquares.h:236
double operator()(const vector< double > &par) const
Definition TSumOfSquares.h:93
~TSumOfSquares()
Definition TSumOfSquares.h:82
int _ninput
Definition TSumOfSquares.h:253
vector< TObjective * > _objectives
vector of objectives
Definition TSumOfSquares.h:66
void addObjective(TObjective *tobj)
Definition TSumOfSquares.h:243
TString _sCriteria
List of matrix.
Definition TSumOfSquares.h:260
double * _dinputValue
Definition TSumOfSquares.h:254
Rosenbrock's function (n=2) with first and second order derivatives.
Definition TBestEstimate.h:58