Logo ROOT   6.16/01
Reference Guide
OptimizeConfigParameters.cxx
Go to the documentation of this file.
1/**********************************************************************************
2 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
3 * Package: TMVA *
4 * Class : OptimizeConfigParameters *
5 * Web : http://tmva.sourceforge.net *
6 * *
7 * Description: The OptimizeConfigParameters takes care of "scanning/fitting" *
8 * different tuning parameters in order to find the best set of *
9 * tuning paraemters which will be used in the end *
10 * *
11 * Authors (alphabetical): *
12 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
13 * *
14 * Copyright (c) 2005: *
15 * CERN, Switzerland *
16 * MPI-K Heidelberg, Germany *
17 * *
18 * Redistribution and use in source and binary forms, with or without *
19 * modification, are permitted according to the terms listed in LICENSE *
20 * (http://ttmva.sourceforge.net/LICENSE) *
21 **********************************************************************************/
22
23/*! \class TMVA::OptimizeConfigParameters
24\ingroup TMVA
25
26*/
27
29#include "TMVA/Config.h"
30#include "TMVA/DataSet.h"
31#include "TMVA/DataSetInfo.h"
32#include "TMVA/Event.h"
33#include "TMVA/IFitterTarget.h"
34#include "TMVA/FitterBase.h"
35#include "TMVA/GeneticFitter.h"
36#include "TMVA/IMethod.h"
37#include "TMVA/Interval.h"
38#include "TMVA/MethodBase.h"
39#include "TMVA/MethodFDA.h"
40#include "TMVA/MsgLogger.h"
41#include "TMVA/MinuitFitter.h"
42#include "TMVA/PDF.h"
43#include "TMVA/Tools.h"
44#include "TMVA/Types.h"
45
46#include "TDirectory.h"
47#include "TGraph.h"
48#include "TH1.h"
49#include "TH2.h"
50#include "TMath.h"
51
52#include <cstdlib>
53#include <limits>
54
55
57
58////////////////////////////////////////////////////////////////////////////////
59/// Constructor which sets either "Classification or Regression"
60
61TMVA::OptimizeConfigParameters::OptimizeConfigParameters(MethodBase * const method, std::map<TString,TMVA::Interval*> tuneParameters, TString fomType, TString optimizationFitType)
62: fMethod(method),
63 fTuneParameters(tuneParameters),
64 fFOMType(fomType),
65 fOptimizationFitType(optimizationFitType),
66 fMvaSig(NULL),
67 fMvaBkg(NULL),
68 fMvaSigFineBin(NULL),
69 fMvaBkgFineBin(NULL),
70 fNotDoneYet(kFALSE)
71{
72 std::string name = "OptimizeConfigParameters_";
73 name += std::string(GetMethod()->GetName());
74 fLogger = new MsgLogger(name);
75 if (fMethod->DoRegression()){
76 Log() << kFATAL << " ERROR: Sorry, Regression is not yet implement for automatic parameter optimization"
77 << " --> exit" << Endl;
78 }
79
80 Log() << kINFO << "Automatic optimisation of tuning parameters in "
81 << GetMethod()->GetName() << " uses:" << Endl;
82
83 std::map<TString,TMVA::Interval*>::iterator it;
84 for (it=fTuneParameters.begin(); it!=fTuneParameters.end();++it) {
85 Log() << kINFO << it->first
86 << " in range from: " << it->second->GetMin()
87 << " to: " << it->second->GetMax()
88 << " in : " << it->second->GetNbins() << " steps"
89 << Endl;
90 }
91 Log() << kINFO << " using the options: " << fFOMType << " and " << fOptimizationFitType << Endl;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// the destructor (delete the OptimizeConfigParameters, store the graph and .. delete it)
96
98{
99 if(!GetMethod()->IsSilentFile()) GetMethod()->BaseDir()->cd();
100 Int_t n=Int_t(fFOMvsIter.size());
101 Float_t *x = new Float_t[n];
102 Float_t *y = new Float_t[n];
103 Float_t ymin=+999999999;
104 Float_t ymax=-999999999;
105
106 for (Int_t i=0;i<n;i++){
107 x[i] = Float_t(i);
108 y[i] = fFOMvsIter[i];
109 if (ymin>y[i]) ymin=y[i];
110 if (ymax<y[i]) ymax=y[i];
111 }
112
113 TH2D *h=new TH2D(TString(GetMethod()->GetName())+"_FOMvsIterFrame","",2,0,n,2,ymin*0.95,ymax*1.05);
114 h->SetXTitle("#iteration "+fOptimizationFitType);
115 h->SetYTitle(fFOMType);
116 TGraph *gFOMvsIter = new TGraph(n,x,y);
117 gFOMvsIter->SetName((TString(GetMethod()->GetName())+"_FOMvsIter").Data());
118 if(!GetMethod()->IsSilentFile()) gFOMvsIter->Write();
119 if(!GetMethod()->IsSilentFile()) h->Write();
120
121 delete [] x;
122 delete [] y;
123 // delete fFOMvsIter;
124}
125
126////////////////////////////////////////////////////////////////////////////////
127
129{
130 if (fOptimizationFitType == "Scan" ) this->optimizeScan();
131 else if (fOptimizationFitType == "FitGA" || fOptimizationFitType == "Minuit" ) this->optimizeFit();
132 else {
133 Log() << kFATAL << "You have chosen as optimization type " << fOptimizationFitType
134 << " that is not (yet) coded --> exit()" << Endl;
135 }
136
137 Log() << kINFO << "For " << GetMethod()->GetName() << " the optimized Parameters are: " << Endl;
138 std::map<TString,Double_t>::iterator it;
139 for(it=fTunedParameters.begin(); it!= fTunedParameters.end(); ++it){
140 Log() << kINFO << it->first << " = " << it->second << Endl;
141 }
142 return fTunedParameters;
143
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// helper function to scan through the all the combinations in the
148/// parameter space
149
150std::vector< int > TMVA::OptimizeConfigParameters::GetScanIndices( int val, std::vector<int> base){
151 std::vector < int > indices;
152 for (UInt_t i=0; i< base.size(); i++){
153 indices.push_back(val % base[i] );
154 val = int( floor( float(val) / float(base[i]) ) );
155 }
156 return indices;
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// do the actual optimization using a simple scan method,
161/// i.e. calculate the FOM for
162/// different tuning paraemters and remember which one is
163/// gave the best FOM
164
166{
167
168 Double_t bestFOM=-1000000, currentFOM;
169
170 std::map<TString,Double_t> currentParameters;
171 std::map<TString,TMVA::Interval*>::iterator it;
172
173 // for the scan, start at the lower end of the interval and then "move upwards"
174 // initialize all parameters in currentParameter
175 currentParameters.clear();
176 fTunedParameters.clear();
177
178 for (it=fTuneParameters.begin(); it!=fTuneParameters.end(); ++it){
179 currentParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
180 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,it->second->GetMin()));
181 }
182 // now loop over all the parameters and get for each combination the figure of merit
183
184 // in order to loop over all the parameters, I first create an "array" (tune parameters)
185 // of arrays (the different values of the tune parameter)
186
187 std::vector< std::vector <Double_t> > v;
188 for (it=fTuneParameters.begin(); it!=fTuneParameters.end(); ++it){
189 std::vector< Double_t > tmp;
190 for (Int_t k=0; k<it->second->GetNbins(); k++){
191 tmp.push_back(it->second->GetElement(k));
192 }
193 v.push_back(tmp);
194 }
195 Int_t Ntot = 1;
196 std::vector< int > Nindividual;
197 for (UInt_t i=0; i<v.size(); i++) {
198 Ntot *= v[i].size();
199 Nindividual.push_back(v[i].size());
200 }
201 //loop on the total number of different combinations
202
203 for (int i=0; i<Ntot; i++){
204 UInt_t index=0;
205 std::vector<int> indices = GetScanIndices(i, Nindividual );
206 for (it=fTuneParameters.begin(), index=0; index< indices.size(); ++index, ++it){
207 currentParameters[it->first] = v[index][indices[index]];
208 }
209 Log() << kINFO << "--------------------------" << Endl;
210 Log() << kINFO <<"Settings being evaluated:" << Endl;
211 for (std::map<TString,Double_t>::iterator it_print=currentParameters.begin();
212 it_print!=currentParameters.end(); ++it_print){
213 Log() << kINFO << " " << it_print->first << " = " << it_print->second << Endl;
214 }
215
216 GetMethod()->Reset();
217 GetMethod()->SetTuneParameters(currentParameters);
218 // now do the training for the current parameters:
219 if(!GetMethod()->IsSilentFile()) GetMethod()->BaseDir()->cd();
220 if (i==0) GetMethod()->GetTransformationHandler().CalcTransformations(
221 GetMethod()->Data()->GetEventCollection());
223 GetMethod()->Train();
225 currentFOM = GetFOM();
226 Log() << kINFO << "FOM was found : " << currentFOM << "; current best is " << bestFOM << Endl;
227
228 if (currentFOM > bestFOM) {
229 bestFOM = currentFOM;
230 for (std::map<TString,Double_t>::iterator iter=currentParameters.begin();
231 iter != currentParameters.end(); ++iter){
232 fTunedParameters[iter->first]=iter->second;
233 }
234 }
235 }
236
237 GetMethod()->Reset();
238 GetMethod()->SetTuneParameters(fTunedParameters);
239}
240
241////////////////////////////////////////////////////////////////////////////////
242
244{
245 // ranges (intervals) in which the fit varies the parameters
246 std::vector<TMVA::Interval*> ranges; // intervals of the fit ranges
247 std::map<TString, TMVA::Interval*>::iterator it;
248 std::vector<Double_t> pars; // current (starting) fit parameters
249
250 for (it=fTuneParameters.begin(); it != fTuneParameters.end(); ++it){
251 ranges.push_back(new TMVA::Interval(*(it->second)));
252 pars.push_back( (it->second)->GetMean() ); // like this the order is "right". Always keep the
253 // order in the vector "pars" the same as the iterator
254 // iterates through the tuneParameters !!!!
255 }
256
257 // added to allow for transformation on input variables i.e. norm
258 GetMethod()->GetTransformationHandler().CalcTransformations(GetMethod()->Data()->GetEventCollection());
259
260 // create the fitter
261
262 FitterBase* fitter = NULL;
263
264 if ( fOptimizationFitType == "Minuit" ) {
265 TString opt="FitStrategy=0:UseImprove=False:UseMinos=False:Tolerance=100";
266 if (!TMVA::gConfig().IsSilent() ) opt += TString(":PrintLevel=0");
267
268 fitter = new MinuitFitter( *this,
269 "FitterMinuit_BDTOptimize",
270 ranges, opt );
271 }else if ( fOptimizationFitType == "FitGA" ) {
272 TString opt="PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
273 fitter = new GeneticFitter( *this,
274 "FitterGA_BDTOptimize",
275 ranges, opt );
276 } else {
277 Log() << kWARNING << " you did not specify a valid OptimizationFitType "
278 << " will use the default (FitGA) " << Endl;
279 TString opt="PopSize=20:Steps=30:Cycles=3:ConvCrit=0.01:SaveBestCycle=5";
280 fitter = new GeneticFitter( *this,
281 "FitterGA_BDTOptimize",
282 ranges, opt );
283 }
284
285 fitter->CheckForUnusedOptions();
286
287 // perform the fit
288 fitter->Run(pars);
289
290 // clean up
291 for (UInt_t ipar=0; ipar<ranges.size(); ipar++) delete ranges[ipar];
292
293 GetMethod()->Reset();
294
295 fTunedParameters.clear();
296 Int_t jcount=0;
297 for (it=fTuneParameters.begin(); it!=fTuneParameters.end(); ++it){
298 fTunedParameters.insert(std::pair<TString,Double_t>(it->first,pars[jcount++]));
299 }
300
301 GetMethod()->SetTuneParameters(fTunedParameters);
302
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// return the estimator (from current FOM) for the fitting interface
307
309{
310 std::map< std::vector<Double_t> , Double_t>::const_iterator iter;
311 iter = fAlreadyTrainedParCombination.find(pars);
312
313 if (iter != fAlreadyTrainedParCombination.end()) {
314 // std::cout << "I had trained Depth=" <<Int_t(pars[0])
315 // <<" MinEv=" <<Int_t(pars[1])
316 // <<" already --> FOM="<< iter->second <<std::endl;
317 return iter->second;
318 }else{
319 std::map<TString,Double_t> currentParameters;
320 Int_t icount =0; // map "pars" to the map of Tuneparameter, make sure
321 // you never screw up this order!!
322 std::map<TString, TMVA::Interval*>::iterator it;
323 for (it=fTuneParameters.begin(); it!=fTuneParameters.end(); ++it){
324 currentParameters[it->first] = pars[icount++];
325 }
326 GetMethod()->Reset();
327 GetMethod()->SetTuneParameters(currentParameters);
328 if(!GetMethod()->IsSilentFile()) GetMethod()->BaseDir()->cd();
329
330 if (fNotDoneYet){
331 GetMethod()->GetTransformationHandler().
332 CalcTransformations(GetMethod()->Data()->GetEventCollection());
333 fNotDoneYet=kFALSE;
334 }
336 GetMethod()->Train();
338
339
340 Double_t currentFOM = GetFOM();
341
342 fAlreadyTrainedParCombination.insert(std::make_pair(pars,-currentFOM));
343 return -currentFOM;
344 }
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Return the Figure of Merit (FOM) used in the parameter
349/// optimization process
350
352{
353 Double_t fom=0;
354 if (fMethod->DoRegression()){
355 std::cout << " ERROR: Sorry, Regression is not yet implement for automatic parameter optimisation"
356 << " --> exit" << std::endl;
357 std::exit(1);
358 }else{
359 if (fFOMType == "Separation") fom = GetSeparation();
360 else if (fFOMType == "ROCIntegral") fom = GetROCIntegral();
361 else if (fFOMType == "SigEffAtBkgEff01") fom = GetSigEffAtBkgEff(0.1);
362 else if (fFOMType == "SigEffAtBkgEff001") fom = GetSigEffAtBkgEff(0.01);
363 else if (fFOMType == "SigEffAtBkgEff002") fom = GetSigEffAtBkgEff(0.02);
364 else if (fFOMType == "BkgRejAtSigEff05") fom = GetBkgRejAtSigEff(0.5);
365 else if (fFOMType == "BkgEffAtSigEff05") fom = GetBkgEffAtSigEff(0.5);
366 else {
367 Log()<<kFATAL << " ERROR, you've specified as Figure of Merit in the "
368 << " parameter optimisation " << fFOMType << " which has not"
369 << " been implemented yet!! ---> exit " << Endl;
370 }
371 }
372 fFOMvsIter.push_back(fom);
373 // std::cout << "fom="<<fom<<std::endl; // should write that into a debug log (as option)
374 return fom;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// fill the private histograms with the mva distributions for sig/bkg
379
381{
382 if (fMvaSig) fMvaSig->Delete();
383 if (fMvaBkg) fMvaBkg->Delete();
384 if (fMvaSigFineBin) fMvaSigFineBin->Delete();
385 if (fMvaBkgFineBin) fMvaBkgFineBin->Delete();
386
387 // maybe later on this should be done a bit more clever (time consuming) by
388 // first determining proper ranges, removing outliers, as we do in the
389 // MVA output calculation in MethodBase::TestClassifier...
390 // --> then it might be possible also to use the splined PDF's which currently
391 // doesn't seem to work
392
393 fMvaSig = new TH1D("fMvaSig","",100,-1.5,1.5); //used for spline fit
394 fMvaBkg = new TH1D("fMvaBkg","",100,-1.5,1.5); //used for spline fit
395 fMvaSigFineBin = new TH1D("fMvaSigFineBin","",100000,-1.5,1.5);
396 fMvaBkgFineBin = new TH1D("fMvaBkgFineBin","",100000,-1.5,1.5);
397
398 const std::vector< Event*> events=fMethod->Data()->GetEventCollection(Types::kTesting);
399
400 UInt_t signalClassNr = fMethod->DataInfo().GetClassInfo("Signal")->GetNumber();
401
402 // fMethod->GetTransformationHandler().CalcTransformations(fMethod->Data()->GetEventCollection(Types::kTesting));
403
404 for (UInt_t iev=0; iev < events.size() ; iev++){
405 // std::cout << " GetMVADists event " << iev << std::endl;
406 // std::cout << " Class = " << events[iev]->GetClass() << std::endl;
407 // std::cout << " MVA Value = " << fMethod->GetMvaValue(events[iev]) << std::endl;
408 if (events[iev]->GetClass() == signalClassNr) {
409 fMvaSig->Fill(fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
410 fMvaSigFineBin->Fill(fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
411 } else {
412 fMvaBkg->Fill(fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
413 fMvaBkgFineBin->Fill(fMethod->GetMvaValue(events[iev]),events[iev]->GetWeight());
414 }
415 }
416}
417////////////////////////////////////////////////////////////////////////////////
418/// return the separation between the signal and background
419/// MVA ouput distribution
420
422{
423 GetMVADists();
424 if (1){
425 PDF *splS = new PDF( " PDF Sig", fMvaSig, PDF::kSpline2 );
426 PDF *splB = new PDF( " PDF Bkg", fMvaBkg, PDF::kSpline2 );
427 return gTools().GetSeparation(*splS,*splB);
428 }else{
429 std::cout << "Separation calculation via histograms (not PDFs) seems to give still strange results!! Don't do that, check!!"<<std::endl;
430 return gTools().GetSeparation(fMvaSigFineBin,fMvaBkgFineBin); // somehow still gives strange results!!!! Check!!!
431 }
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// calculate the area (integral) under the ROC curve as a
436/// overall quality measure of the classification
437///
438/// making pdfs out of the MVA-output distributions doesn't work
439/// reliably for cases where the MVA-output isn't a smooth distribution.
440/// this happens "frequently" in BDTs for example when the number of
441/// trees is small resulting in only some discrete possible MVA output values.
442/// (I still leave the code here, but use this with care!!! The default
443/// however is to use the distributions!!!
444
446{
447 GetMVADists();
448
449 Double_t integral = 0;
450 if (0){
451 PDF *pdfS = new PDF( " PDF Sig", fMvaSig, PDF::kSpline2 );
452 PDF *pdfB = new PDF( " PDF Bkg", fMvaBkg, PDF::kSpline2 );
453
454 Double_t xmin = TMath::Min(pdfS->GetXmin(), pdfB->GetXmin());
455 Double_t xmax = TMath::Max(pdfS->GetXmax(), pdfB->GetXmax());
456
457 UInt_t nsteps = 1000;
458 Double_t step = (xmax-xmin)/Double_t(nsteps);
459 Double_t cut = xmin;
460 for (UInt_t i=0; i<nsteps; i++){
461 integral += (1-pdfB->GetIntegral(cut,xmax)) * pdfS->GetVal(cut);
462 cut+=step;
463 }
464 integral*=step;
465 }else{
466 // sanity checks
467 if ( (fMvaSigFineBin->GetXaxis()->GetXmin() != fMvaBkgFineBin->GetXaxis()->GetXmin()) ||
468 (fMvaSigFineBin->GetNbinsX() != fMvaBkgFineBin->GetNbinsX()) ){
469 std::cout << " Error in OptimizeConfigParameters GetROCIntegral, unequal histograms for sig and bkg.." << std::endl;
470 std::exit(1);
471 }else{
472
473 Double_t *cumulator = fMvaBkgFineBin->GetIntegral();
474 Int_t nbins = fMvaSigFineBin->GetNbinsX();
475 // get the true signal integral (ComputeIntegral just return 1 as they
476 // automatically normalize. IN ADDITION, they do not account for variable
477 // bin sizes (which you might perhaps use later on for the fMvaSig/Bkg histograms)
478 Double_t sigIntegral = 0;
479 for (Int_t ibin=1; ibin<=nbins; ibin++){
480 sigIntegral += fMvaSigFineBin->GetBinContent(ibin) * fMvaSigFineBin->GetBinWidth(ibin);
481 }
482 //gTools().NormHist( fMvaSigFineBin ); // also doesn't use variable bin width. And calls TH1::Scale, which oddly enough does not change the SumOfWeights !!!
483
484 for (Int_t ibin=1; ibin <= nbins; ibin++){ // don't include under- and overflow bin
485 integral += (cumulator[ibin]) * fMvaSigFineBin->GetBinContent(ibin)/sigIntegral * fMvaSigFineBin->GetBinWidth(ibin) ;
486 }
487 }
488 }
489
490 return integral;
491}
492
493////////////////////////////////////////////////////////////////////////////////
494/// calculate the signal efficiency for a given background efficiency
495
497{
498 GetMVADists();
499 Double_t sigEff=0;
500
501 // sanity checks
502 if ( (fMvaSigFineBin->GetXaxis()->GetXmin() != fMvaBkgFineBin->GetXaxis()->GetXmin()) ||
503 (fMvaSigFineBin->GetNbinsX() != fMvaBkgFineBin->GetNbinsX()) ){
504 std::cout << " Error in OptimizeConfigParameters GetSigEffAt, unequal histograms for sig and bkg.." << std::endl;
505 std::exit(1);
506 }else{
507 Double_t *bkgCumulator = fMvaBkgFineBin->GetIntegral();
508 Double_t *sigCumulator = fMvaSigFineBin->GetIntegral();
509
510 Int_t nbins=fMvaBkgFineBin->GetNbinsX();
511 Int_t ibin=0;
512
513 // std::cout << " bkgIntegral="<<bkgIntegral
514 // << " sigIntegral="<<sigIntegral
515 // << " bkgCumulator[nbins]="<<bkgCumulator[nbins]
516 // << " sigCumulator[nbins]="<<sigCumulator[nbins]
517 // << std::endl;
518
519 while (bkgCumulator[nbins-ibin] > (1-bkgEff)) {
520 sigEff = sigCumulator[nbins]-sigCumulator[nbins-ibin];
521 ibin++;
522 }
523 }
524 return sigEff;
525}
526
527
528////////////////////////////////////////////////////////////////////////////////
529/// calculate the background efficiency for a given signal efficiency
530///
531/// adapted by marc-olivier.bettler@cern.ch
532
534{
535 GetMVADists();
536 Double_t bkgEff=0;
537
538 // sanity checks
539 if ( (fMvaSigFineBin->GetXaxis()->GetXmin() != fMvaBkgFineBin->GetXaxis()->GetXmin()) ||
540 (fMvaSigFineBin->GetNbinsX() != fMvaBkgFineBin->GetNbinsX()) ){
541 std::cout << " Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
542 std::exit(1);
543 }else{
544
545 Double_t *bkgCumulator = fMvaBkgFineBin->GetIntegral();
546 Double_t *sigCumulator = fMvaSigFineBin->GetIntegral();
547
548 Int_t nbins=fMvaBkgFineBin->GetNbinsX();
549 Int_t ibin=0;
550
551 // std::cout << " bkgIntegral="<<bkgIntegral
552 // << " sigIntegral="<<sigIntegral
553 // << " bkgCumulator[nbins]="<<bkgCumulator[nbins]
554 // << " sigCumulator[nbins]="<<sigCumulator[nbins]
555 // << std::endl;
556
557 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
558 bkgEff = bkgCumulator[nbins]-bkgCumulator[nbins-ibin];
559 ibin++;
560 }
561 }
562 return bkgEff;
563}
564
565////////////////////////////////////////////////////////////////////////////////
566/// calculate the background rejection for a given signal efficiency
567///
568/// adapted by marc-olivier.bettler@cern.ch
569
571{
572 GetMVADists();
573 Double_t bkgRej=0;
574
575 // sanity checks
576 if ( (fMvaSigFineBin->GetXaxis()->GetXmin() != fMvaBkgFineBin->GetXaxis()->GetXmin()) ||
577 (fMvaSigFineBin->GetNbinsX() != fMvaBkgFineBin->GetNbinsX()) ){
578 std::cout << " Error in OptimizeConfigParameters GetBkgEffAt, unequal histograms for sig and bkg.." << std::endl;
579 std::exit(1);
580 }else{
581
582 Double_t *bkgCumulator = fMvaBkgFineBin->GetIntegral();
583 Double_t *sigCumulator = fMvaSigFineBin->GetIntegral();
584
585 Int_t nbins=fMvaBkgFineBin->GetNbinsX();
586 Int_t ibin=0;
587
588 // std::cout << " bkgIntegral="<<bkgIntegral
589 // << " sigIntegral="<<sigIntegral
590 // << " bkgCumulator[nbins]="<<bkgCumulator[nbins]
591 // << " sigCumulator[nbins]="<<sigCumulator[nbins]
592 // << std::endl;
593
594 while ( sigCumulator[nbins]-sigCumulator[nbins-ibin] < sigEff) {
595 bkgRej = bkgCumulator[nbins-ibin];
596 ibin++;
597 }
598 }
599 return bkgRej;
600}
SVector< double, 2 > v
Definition: Dict.h:5
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
float xmin
Definition: THbookFile.cxx:93
float ymin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
float ymax
Definition: THbookFile.cxx:93
double floor(double)
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void SetName(const char *name="")
Set graph name.
Definition: TGraph.cxx:2223
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:614
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:291
void CheckForUnusedOptions() const
checks for unused options in option string
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Definition: Event.cxx:392
Base class for TMVA fitters.
Definition: FitterBase.h:51
Double_t Run()
estimator function interface for fitting
Definition: FitterBase.cxx:74
Fitter using a Genetic Algorithm.
Definition: GeneticFitter.h:43
The TMVA::Interval Class.
Definition: Interval.h:61
Virtual base Class for all MVA method.
Definition: MethodBase.h:109
const char * GetName() const
Definition: MethodBase.h:325
Bool_t DoRegression() const
Definition: MethodBase.h:429
/Fitter using MINUIT
Definition: MinuitFitter.h:47
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
std::vector< int > GetScanIndices(int val, std::vector< int > base)
helper function to scan through the all the combinations in the parameter space
Double_t GetBkgRejAtSigEff(Double_t sigEff=0.5)
calculate the background rejection for a given signal efficiency
virtual ~OptimizeConfigParameters()
the destructor (delete the OptimizeConfigParameters, store the graph and .. delete it)
Double_t GetBkgEffAtSigEff(Double_t sigEff=0.5)
calculate the background efficiency for a given signal efficiency
void optimizeScan()
do the actual optimization using a simple scan method, i.e.
OptimizeConfigParameters(MethodBase *const method, std::map< TString, TMVA::Interval * > tuneParameters, TString fomType="Separation", TString optimizationType="GA")
Constructor which sets either "Classification or Regression".
std::map< TString, TMVA::Interval * > fTuneParameters
std::map< TString, Double_t > optimize()
Double_t GetSeparation()
return the separation between the signal and background MVA ouput distribution
Double_t GetFOM()
Return the Figure of Merit (FOM) used in the parameter optimization process.
Double_t GetSigEffAtBkgEff(Double_t bkgEff=0.1)
calculate the signal efficiency for a given background efficiency
Double_t GetROCIntegral()
calculate the area (integral) under the ROC curve as a overall quality measure of the classification
void GetMVADists()
fill the private histograms with the mva distributions for sig/bkg
Double_t EstimatorFunction(std::vector< Double_t > &)
return the estimator (from current FOM) for the fitting interface
PDF wrapper for histograms; uses user-defined spline interpolation.
Definition: PDF.h:63
Double_t GetXmin() const
Definition: PDF.h:104
Double_t GetXmax() const
Definition: PDF.h:105
Double_t GetVal(Double_t x) const
returns value PDF(x)
Definition: PDF.cxx:704
@ kSpline2
Definition: PDF.h:70
Double_t GetIntegral(Double_t xmin, Double_t xmax)
computes PDF integral within given ranges
Definition: PDF.cxx:657
Double_t GetSeparation(TH1 *S, TH1 *B) const
compute "separation" defined as
Definition: Tools.cxx:133
@ kTesting
Definition: Types.h:145
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:785
Basic string class.
Definition: TString.h:131
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:146
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
Definition: Cppyy.cxx:744
TClass * GetClass(T *)
Definition: TClass.h:582
Config & gConfig()
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Double_t Log(Double_t x)
Definition: TMath.h:748
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180