Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MethodBase.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Kai Voss, Eckhard von Toerne, Jan Therhaag
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : MethodBase *
8 * *
9 * *
10 * Description: *
11 * Virtual base class for all MVA method *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
16 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17 * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18 * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
19 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
20 * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
21 * *
22 * Copyright (c) 2005-2011: *
23 * CERN, Switzerland *
24 * U. of Victoria, Canada *
25 * MPI-K Heidelberg, Germany *
26 * U. of Bonn, Germany *
27 * *
28 * Redistribution and use in source and binary forms, with or without *
29 * modification, are permitted according to the terms listed in LICENSE *
30 * (see tmva/doc/LICENSE) *
31 **********************************************************************************/
32
33#ifndef ROOT_TMVA_MethodBase
34#define ROOT_TMVA_MethodBase
35
36//////////////////////////////////////////////////////////////////////////
37// //
38// MethodBase //
39// //
40// Virtual base class for all TMVA method //
41// //
42//////////////////////////////////////////////////////////////////////////
43
44#include <iosfwd>
45#include <vector>
46#include <map>
47#include "assert.h"
48
49#include "TString.h"
50
51#include "TMVA/IMethod.h"
52#include "TMVA/Configurable.h"
53#include "TMVA/Types.h"
54#include "TMVA/DataSet.h"
55#include "TMVA/Event.h"
57#include <TMVA/Results.h>
59
60#include <TFile.h>
61
62class TGraph;
63class TTree;
64class TDirectory;
65class TSpline;
66class TH1F;
67class TH1D;
68
69namespace TMVA {
70
71 class Ranking;
72 class PDF;
73 class TSpline1;
74 class MethodCuts;
75 class MethodBoost;
76 class DataSetInfo;
77 class TrainingHistory;
78
79 class MethodBase : virtual public IMethod, public Configurable {
80
81 friend class CrossValidation;
82 friend class Factory;
83 friend class RootFinder;
84 friend class MethodBoost;
86
87 public:
88
90
91 // default constructor
94 const TString& methodTitle,
96 const TString& theOption = "" );
97
98 // constructor used for Testing + Application of the MVA, only (no training),
99 // using given weight file
102 const TString& weightFile );
103
104 // default destructor
105 virtual ~MethodBase();
106
107 // declaration, processing and checking of configuration options
108 void SetupMethod();
109 void ProcessSetup();
110 virtual void CheckSetup(); // may be overwritten by derived classes
111
112 // ---------- main training and testing methods ------------------------------
113
114 // prepare tree branch with the method's discriminating variable
116
117 // performs classifier training
118 // calls methods Train() implemented by derived classes
119 void TrainMethod();
120
121 // optimize tuning parameters
122 virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA");
123 virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);
124
125 void Train() override = 0;
126
127 // store and retrieve time used for training
129 Double_t GetTrainTime() const { return fTrainTime; }
130
131 // store and retrieve time used for testing
133 Double_t GetTestTime () const { return fTestTime; }
134
135 // performs classifier testing
136 virtual void TestClassification();
138
139 // performs multiclass classifier testing
140 virtual void TestMulticlass();
141
142 // performs regression testing
143 virtual void TestRegression( Double_t& bias, Double_t& biasT,
146 Double_t& mInf, Double_t& mInfT, // mutual information
147 Double_t& corr,
149
150 // options treatment
151 void Init() override = 0;
152 void DeclareOptions() override = 0;
153 void ProcessOptions() override = 0;
154 virtual void DeclareCompatibilityOptions(); // declaration of past options
155
156 // reset the Method --> As if it was not yet trained, just instantiated
157 // virtual void Reset() = 0;
158 //for the moment, I provide a dummy (that would not work) default, just to make
159 // compilation/running w/o parameter optimisation still possible
160 virtual void Reset(){return;}
161
162 // classifier response:
163 // some methods may return a per-event error estimate
164 // error calculation is skipped if err==0
165 Double_t GetMvaValue( Double_t* errLower = nullptr, Double_t* errUpper = nullptr) override = 0;
166
167 // signal/background classification response
168 Double_t GetMvaValue( const TMVA::Event* const ev, Double_t* err = nullptr, Double_t* errUpper = nullptr );
169
170 protected:
171 // helper function to set errors to -1
172 void NoErrorCalc(Double_t* const err, Double_t* const errUpper);
173
174 // signal/background classification response for all current set of data
175 virtual std::vector<Double_t> GetMvaValues(Long64_t firstEvt = 0, Long64_t lastEvt = -1, Bool_t logProgress = false);
176 // same as above but using a provided data set (used by MethodCategory)
177 virtual std::vector<Double_t> GetDataMvaValues(DataSet *data = nullptr, Long64_t firstEvt = 0, Long64_t lastEvt = -1, Bool_t logProgress = false);
178
179 virtual std::vector<Float_t> GetAllRegressionValues();
180 virtual std::vector<Float_t> GetAllMulticlassValues();
181
182 public:
183 // regression response
184 const std::vector<Float_t>& GetRegressionValues(const TMVA::Event* const ev){
185 fTmpEvent = ev;
186 const std::vector<Float_t>* ptr = &GetRegressionValues();
187 fTmpEvent = nullptr;
188 return (*ptr);
189 }
190
191 virtual const std::vector<Float_t>& GetRegressionValues() {
192 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
193 return (*ptr);
194 }
195
196 // multiclass classification response
197 virtual const std::vector<Float_t>& GetMulticlassValues() {
198 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
199 return (*ptr);
200 }
201
202 // Training history
203 virtual const std::vector<Float_t>& GetTrainingHistory(const char* /*name*/ ) {
204 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
205 return (*ptr);
206 }
207
208 // probability of classifier response (mvaval) to be signal (requires "CreateMvaPdf" option set)
209 virtual Double_t GetProba( const Event *ev); // the simple one, automatically calculates the mvaVal and uses the SAME sig/bkg ratio as given in the training sample (typically 50/50 .. (NormMode=EqualNumEvents) but can be different)
211
212 // Rarity of classifier response (signal or background (default) is uniform in [0,1])
214
215 // create ranking
216 const Ranking* CreateRanking() override = 0;
217
218 // make ROOT-independent C++ class
219 void MakeClass( const TString& classFileName = TString("") ) const override;
220
221 // print help message
222 void PrintHelpMessage() const override;
223
224 //
225 // streamer methods for training information (creates "weight" files) --------
226 //
227 public:
228 void WriteStateToFile () const;
229 void ReadStateFromFile ();
230
231 protected:
232 // the actual "weights"
233 virtual void AddWeightsXMLTo ( void* parent ) const = 0;
234 virtual void ReadWeightsFromXML ( void* wghtnode ) = 0;
235 void ReadWeightsFromStream( std::istream& ) override = 0; // backward compatibility
236 virtual void ReadWeightsFromStream( TFile& ) {} // backward compatibility
237
238 private:
239 friend class MethodCategory;
241 void WriteStateToXML ( void* parent ) const;
242 void ReadStateFromXML ( void* parent );
243 void WriteStateToStream ( std::ostream& tf ) const; // needed for MakeClass
244 void WriteVarsToStream ( std::ostream& tf, const TString& prefix = "" ) const; // needed for MakeClass
245
246
247 public: // these two need to be public, they are used to read in-memory weight-files
248 void ReadStateFromStream ( std::istream& tf ); // backward compatibility
249 void ReadStateFromStream ( TFile& rf ); // backward compatibility
250 void ReadStateFromXMLString( const char* xmlstr ); // for reading from memory
251
252 private:
253 // the variable information
254 void AddVarsXMLTo ( void* parent ) const;
255 void AddSpectatorsXMLTo ( void* parent ) const;
256 void AddTargetsXMLTo ( void* parent ) const;
257 void AddClassesXMLTo ( void* parent ) const;
258 void ReadVariablesFromXML ( void* varnode );
259 void ReadSpectatorsFromXML( void* specnode);
260 void ReadTargetsFromXML ( void* tarnode );
261 void ReadClassesFromXML ( void* clsnode );
262 void ReadVarsFromStream ( std::istream& istr ); // backward compatibility
263
264 public:
265 // ---------------------------------------------------------------------------
266
267 // write evaluation histograms into target file
269
270 // write classifier-specific monitoring information to target file
271 void WriteMonitoringHistosToFile() const override;
272
273 // ---------- public evaluation methods --------------------------------------
274
275 // individual initialization for testing of each method
276 // overload this one for individual initialisation of the testing,
277 // it is then called automatically within the global "TestInit"
278
279 // variables (and private member functions) for the Evaluation:
280 // get the efficiency. It fills a histogram for efficiency/vs/bkg
281 // and returns the one value fo the efficiency demanded for
282 // in the TString argument. (Watch the string format)
284 virtual Double_t GetTrainingEfficiency(const TString& );
285 virtual std::vector<Float_t> GetMulticlassEfficiency( std::vector<std::vector<Float_t> >& purity );
286 virtual std::vector<Float_t> GetMulticlassTrainingEfficiency(std::vector<std::vector<Float_t> >& purity );
288 virtual Double_t GetSignificance() const;
289 virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const;
290 virtual Double_t GetROCIntegral(PDF *pdfS=nullptr, PDF *pdfB=nullptr) const;
293 virtual Double_t GetSeparation( TH1*, TH1* ) const;
294 virtual Double_t GetSeparation( PDF* pdfS = nullptr, PDF* pdfB = nullptr ) const;
295
297 // ---------- public accessors -----------------------------------------------
298
299 // classifier naming (a lot of names ... aren't they ;-)
300 const TString& GetJobName () const { return fJobName; }
301 const TString& GetMethodName () const { return fMethodName; }
302 TString GetMethodTypeName() const { return Types::Instance().GetMethodName(fMethodType); }
304 const char* GetName () const override { return fMethodName.Data(); }
305 const TString& GetTestvarName () const { return fTestvar; }
306 const TString GetProbaName () const { return fTestvar + "_Proba"; }
308
309 // build classifier name in Test tree
310 // MVA prefix (e.g., "TMVA_")
311 void SetTestvarName ( const TString & v="" ) { fTestvar = (v=="") ? ("MVA_" + GetMethodName()) : v; }
312
313 // number of input variable used by classifier
314 UInt_t GetNvar() const { return DataInfo().GetNVariables(); }
316 UInt_t GetNTargets() const { return DataInfo().GetNTargets(); };
317
318 // internal names and expressions of input variables
319 const TString& GetInputVar ( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetInternalName(); }
320 const TString& GetInputLabel( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetLabel(); }
321 const char * GetInputTitle( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetTitle(); }
322
323 // normalisation and limit accessors
328
329 // sets the minimum requirement on the MVA output to declare an event signal-like
332
333 // sets the minimum requirement on the MVA output to declare an event signal-like
336
337 // pointers to ROOT directories
338 TDirectory* BaseDir() const;
339 TDirectory* MethodBaseDir() const;
340 TFile* GetFile() const {return fFile;}
341
345 void SetFile(TFile* file){fFile=file;}
346
347 //Silent file
348 void SetSilentFile(Bool_t status) {fSilentFile=status;}
350
351 //Model Persistence
352 void SetModelPersistence(Bool_t status){fModelPersistence=status;}//added support to create/remove dir here if exits or not
354
355 // the TMVA version can be obtained and checked using
356 // if (GetTrainingTMVAVersionCode()>TMVA_VERSION(3,7,2)) {...}
357 // or
358 // if (GetTrainingROOTVersionCode()>ROOT_VERSION(5,15,5)) {...}
363
372
374
375 // ---------- event accessors ------------------------------------------------
376
377 // returns reference to data set
378 // NOTE: this DataSet is the "original" dataset, i.e. the one seen by ALL Classifiers WITHOUT transformation
379 DataSet* Data() const { return (fTmpData) ? fTmpData : DataInfo().GetDataSet(); }
380 DataSetInfo& DataInfo() const { return fDataSetInfo; }
381
382
383 // event reference and update
384 // NOTE: these Event accessors make sure that you get the events transformed according to the
385 // particular classifiers transformation chosen
386 UInt_t GetNEvents () const { return Data()->GetNEvents(); }
387 const Event* GetEvent () const;
388 const Event* GetEvent ( const TMVA::Event* ev ) const;
389 const Event* GetEvent ( Long64_t ievt ) const;
390 const Event* GetEvent ( Long64_t ievt , Types::ETreeType type ) const;
391 const Event* GetTrainingEvent( Long64_t ievt ) const;
392 const Event* GetTestingEvent ( Long64_t ievt ) const;
393 const std::vector<TMVA::Event*>& GetEventCollection( Types::ETreeType type );
394
396 // ---------- public auxiliary methods ---------------------------------------
397
398 // this method is used to decide whether an event is signal- or background-like
399 // the reference cut "xC" is taken to be where
400 // Int_[-oo,xC] { PDF_S(x) dx } = Int_[xC,+oo] { PDF_B(x) dx }
401 virtual Bool_t IsSignalLike();
403
404
405 Bool_t HasMVAPdfs() const { return fHasMVAPdfs; }
410
411 // setter method for suppressing writing to XML and writing of standalone classes
413
414 protected:
415 mutable const Event *fTmpEvent; ///<! temporary event when testing on a different DataSet than the own one
416 DataSet *fTmpData = nullptr; ///<! temporary dataset used when evaluating on a different data (used by MethodCategory::GetMvaValues)
417
418 // ---------- protected accessors -------------------------------------------
419
420 //TDirectory* LocalTDir() const { return Data().LocalRootDir(); }
421
422 // weight file name and directory (given by global config variable)
424
425 const TString& GetWeightFileDir() const { return fFileDir; }
427
428 // are input variables normalised ?
429 Bool_t IsNormalised() const { return fNormalise; }
431
432 // set number of input variables (only used by MethodCuts, could perhaps be removed)
433 // void SetNvar( Int_t n ) { fNvar = n; }
434
435 // verbose and help flags
436 Bool_t Verbose() const { return fVerbose; }
437 Bool_t Help () const { return fHelp; }
438
439 // ---------- protected event and tree accessors -----------------------------
440
441 // names of input variables (if the original names are expressions, they are
442 // transformed into regexps)
443 const TString& GetInternalVarName( Int_t ivar ) const { return (*fInputVars)[ivar]; }
445
446 Bool_t HasTrainingTree() const { return Data()->GetNTrainingEvents() != 0; }
447
448 // ---------- protected auxiliary methods ------------------------------------
449
450 protected:
451
452 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
453 void MakeClassSpecific( std::ostream&, const TString& = "" ) const override {}
454
455 // header and auxiliary classes
456 virtual void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const {}
457
458 // static pointer to this object - required for ROOT finder (to be solved differently)(solved by Omar)
459 //static MethodBase* GetThisBase();
460
461 // some basic statistical analysis
465
466 // if TRUE, write weights only to text files
467 Bool_t TxtWeightsOnly() const { return kTRUE; }
468
469 protected:
470
471 // access to event information that needs method-specific information
472
474
475 private:
476
477 // ---------- private definitions --------------------------------------------
478 // Initialisation
479 void InitBase();
480 void DeclareBaseOptions();
481 void ProcessBaseOptions();
482
483 // used in efficiency computation
486
487 // ---------- private accessors ---------------------------------------------
488
489 // reset required for RootFinder
491
492 // ---------- private auxiliary methods --------------------------------------
493
494 // PDFs for classifier response (required to compute signal probability and Rarity)
495 void CreateMVAPdfs();
496
497 // for root finder
498 //virtual method to find ROOT
499 virtual Double_t GetValueForRoot ( Double_t ); // implementation
500
501 // used for file parsing
502 Bool_t GetLine( std::istream& fin, char * buf );
503
504 // fill test tree with classification or regression results
509
510 private:
511
512 void AddInfoItem( void* gi, const TString& name,
513 const TString& value) const;
514
515 // ========== class members ==================================================
516
517 protected:
518
519 // direct accessors
520 Ranking* fRanking; // pointer to ranking object (created by derived classifiers)
521 std::vector<TString>* fInputVars; // vector of input variables used in MVA
522
523 // histogram binning
524 Int_t fNbins; // number of bins in input variable histograms
525 Int_t fNbinsMVAoutput; // number of bins in MVA output histograms
526 Int_t fNbinsH; // number of bins in evaluation histograms
527
528 Types::EAnalysisType fAnalysisType; // method-mode : true --> regression, false --> classification
529
530 std::vector<Float_t>* fRegressionReturnVal; // holds the return-values for the regression
531 std::vector<Float_t>* fMulticlassReturnVal; // holds the return-values for the multiclass classification
532
533 private:
534
535 // MethodCuts redefines some of the evaluation variables and histograms -> must access private members
536 friend class MethodCuts;
537
538
539 // data sets
540 DataSetInfo& fDataSetInfo; ///<! the data set information (sometimes needed)
541
542 Double_t fSignalReferenceCut; // minimum requirement on the MVA output to declare an event signal-like
543 Double_t fSignalReferenceCutOrientation; // minimum requirement on the MVA output to declare an event signal-like
544 Types::ESBType fVariableTransformType; // this is the event type (sig or bgd) assumed for variable transform
545
546 // naming and versioning
547 TString fJobName; // name of job -> user defined, appears in weight files
548 TString fMethodName; // name of the method (set in derived class)
549 Types::EMVA fMethodType; // type of method (set in derived class)
550 TString fTestvar; // variable used in evaluation, etc (mostly the MVA)
551 UInt_t fTMVATrainingVersion; // TMVA version used for training
552 UInt_t fROOTTrainingVersion; // ROOT version used for training
553 Bool_t fConstructedFromWeightFile; // is it obtained from weight file?
554
555 // Directory structure: dataloader/fMethodBaseDir/fBaseDir
556 // where the first directory name is defined by the method type
557 // and the second is user supplied (the title given in Factory::BookMethod())
558 TDirectory* fBaseDir; // base directory for the instance, needed to know where to jump back from localDir
559 mutable TDirectory* fMethodBaseDir; // base directory for the method
560 //this will be the next way to save results
562
563 //SilentFile
565 //Model Persistence
567
568 TString fParentDir; ///< method parent name, like booster name
569
570 TString fFileDir; ///< unix sub-directory for weight files (default: DataLoader's Name + "weights")
571 TString fWeightFile; ///< weight file name
572
573 private:
574
575 TH1* fEffS; ///< efficiency histogram for rootfinder
576
577 PDF* fDefaultPDF; ///< default PDF definitions
578 PDF* fMVAPdfS; ///< signal MVA PDF
579 PDF* fMVAPdfB; ///< background MVA PDF
580
581 // TH1D* fmvaS; ///< PDFs of MVA distribution (signal)
582 // TH1D* fmvaB; ///< PDFs of MVA distribution (background)
583 PDF* fSplS; ///< PDFs of MVA distribution (signal)
584 PDF* fSplB; ///< PDFs of MVA distribution (background)
585 TSpline* fSpleffBvsS; ///< splines for signal eff. versus background eff.
586
587 PDF* fSplTrainS; ///< PDFs of training MVA distribution (signal)
588 PDF* fSplTrainB; ///< PDFs of training MVA distribution (background)
589 TSpline* fSplTrainEffBvsS; ///< splines for training signal eff. versus background eff.
590
591 private:
592
593 // basic statistics quantities of MVA
594 Double_t fMeanS; ///< mean (signal)
595 Double_t fMeanB; ///< mean (background)
596 Double_t fRmsS; ///< RMS (signal)
597 Double_t fRmsB; ///< RMS (background)
598 Double_t fXmin; ///< minimum (signal and background)
599 Double_t fXmax; ///< maximum (signal and background)
600
601 // variable preprocessing
602 TString fVarTransformString; ///< labels variable transform method
603
604 TransformationHandler* fTransformationPointer; ///< pointer to the rest of transformations
605 TransformationHandler fTransformation; ///< the list of transformations
606
607
608 // help and verbosity
609 Bool_t fVerbose; ///< verbose flag
610 TString fVerbosityLevelString; ///< verbosity level (user input string)
611 EMsgType fVerbosityLevel; ///< verbosity level
612 Bool_t fHelp; ///< help flag
613 Bool_t fHasMVAPdfs; ///< MVA Pdfs are created for this classifier
614
615 Bool_t fIgnoreNegWeightsInTraining; ///< If true, events with negative weights are not used in training
616
617 protected:
618
620
621 // for signal/background
622 UInt_t fSignalClass; // index of the Signal-class
623 UInt_t fBackgroundClass; // index of the Background-class
624
625 private:
626
627 // timing variables
628 Double_t fTrainTime; // for timing measurements
629 Double_t fTestTime; // for timing measurements
630
631 // orientation of cut: depends on signal and background mean values
632 ECutOrientation fCutOrientation; // +1 if Sig>Bkg, -1 otherwise
633
634 // for root finder
635 TSpline1* fSplRefS; // helper splines for RootFinder (signal)
636 TSpline1* fSplRefB; // helper splines for RootFinder (background)
637
638 TSpline1* fSplTrainRefS; // helper splines for RootFinder (signal)
639 TSpline1* fSplTrainRefB; // helper splines for RootFinder (background)
640
641 mutable std::vector<const std::vector<TMVA::Event*>*> fEventCollections; // if the method needs the complete event-collection, the transformed event coll. ist stored here.
642
643 public:
644 Bool_t fSetupCompleted; // is method setup
645
646 private:
647
648 // This is a workaround for OSx where static thread_local data members are
649 // not supported. The C++ solution would indeed be the following:
650// static MethodBase*& GetThisBaseThreadLocal() {TTHREAD_TLS(MethodBase*) fgThisBase(nullptr); return fgThisBase; };
651
652 // ===== depreciated options, kept for backward compatibility =====
653 private:
654
655 Bool_t fNormalise; // normalise input variables
656 Bool_t fUseDecorr; // synonymous for decorrelation
657 TString fVariableTransformTypeString; // labels variable transform type
658 Bool_t fTxtWeightsOnly; // if TRUE, write weights only to text files
659 Int_t fNbinsMVAPdf; // number of bins used in histogram that creates PDF
660 Int_t fNsmoothMVAPdf; // number of times a histogram is smoothed before creating the PDF
661
662 protected:
664 ClassDefOverride(MethodBase,0); // Virtual base class for all TMVA method
665
666 };
667} // namespace TMVA
668
669
670
671
672
673
674
675// ========== INLINE FUNCTIONS =========================================================
676
677
678//_______________________________________________________________________
680{
682}
683
685{
686 if(fTmpEvent)
687 return GetTransformationHandler().Transform(fTmpEvent);
688 else
689 return GetTransformationHandler().Transform(Data()->GetEvent());
690}
691
693{
694 assert(fTmpEvent==nullptr);
695 return GetTransformationHandler().Transform(Data()->GetEvent(ievt));
696}
697
699{
700 assert(fTmpEvent==nullptr);
701 return GetTransformationHandler().Transform(Data()->GetEvent(ievt, type));
702}
703
705{
706 assert(fTmpEvent==nullptr);
707 return GetEvent(ievt, Types::kTraining);
708}
709
711{
712 assert(fTmpEvent==nullptr);
713 return GetEvent(ievt, Types::kTesting);
714}
715
716#endif
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:52
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
Describe directory structure in memory.
Definition TDirectory.h:45
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:926
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
Class to perform cross validation, splitting the dataloader into folds.
Class that contains all the data information.
Definition DataSetInfo.h:62
UInt_t GetNVariables() const
UInt_t GetNTargets() const
DataSet * GetDataSet() const
returns data set
VariableInfo & GetVariableInfo(Int_t i)
Class that contains all the data information.
Definition DataSet.h:58
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
Definition DataSet.h:206
Long64_t GetNTrainingEvents() const
Definition DataSet.h:68
This is the main MVA steering class.
Definition Factory.h:80
Interface for all concrete MVA method implementations.
Definition IMethod.h:53
Virtual base Class for all MVA method.
Definition MethodBase.h:79
TransformationHandler * fTransformationPointer
pointer to the rest of transformations
Definition MethodBase.h:604
void ProcessOptions() override=0
virtual void MakeClassSpecificHeader(std::ostream &, const TString &="") const
Definition MethodBase.h:456
TString fVerbosityLevelString
verbosity level (user input string)
Definition MethodBase.h:610
TDirectory * MethodBaseDir() const
returns the ROOT directory where all instances of the corresponding MVA method are stored
virtual const std::vector< Float_t > & GetRegressionValues()
Definition MethodBase.h:191
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
Definition MethodBase.h:184
PDF * fSplB
PDFs of MVA distribution (background)
Definition MethodBase.h:584
Bool_t fVerbose
verbose flag
Definition MethodBase.h:609
virtual Double_t GetKSTrainingVsTest(Char_t SorB, TString opt="X")
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
TString fMethodName
Definition MethodBase.h:548
TFile * GetFile() const
Definition MethodBase.h:340
void PrintHelpMessage() const override
prints out method-specific help method
virtual std::vector< Float_t > GetAllMulticlassValues()
Get all multi-class values.
virtual Double_t GetSeparation(TH1 *, TH1 *) const
compute "separation" defined as
TString fFileDir
unix sub-directory for weight files (default: DataLoader's Name + "weights")
Definition MethodBase.h:570
DataSet * fTmpData
! temporary dataset used when evaluating on a different data (used by MethodCategory::GetMvaValues)
Definition MethodBase.h:416
Bool_t HasTrainingTree() const
Definition MethodBase.h:446
const char * GetName() const override
Definition MethodBase.h:304
void SetSilentFile(Bool_t status)
Definition MethodBase.h:348
void ReadClassesFromXML(void *clsnode)
read number of classes from XML
void SetWeightFileDir(TString fileDir)
set directory of weight file
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables,...
void DeclareBaseOptions()
define the options (their key words) that can be set in the option string here the options valid for ...
Double_t fRmsB
RMS (background)
Definition MethodBase.h:597
Double_t GetXmin(Int_t ivar) const
Definition MethodBase.h:326
Bool_t Verbose() const
Definition MethodBase.h:436
virtual void TestRegression(Double_t &bias, Double_t &biasT, Double_t &dev, Double_t &devT, Double_t &rms, Double_t &rmsT, Double_t &mInf, Double_t &mInfT, Double_t &corr, Types::ETreeType type)
calculate <sum-of-deviation-squared> of regression output versus "true" value from test sample
Double_t GetMean(Int_t ivar) const
Definition MethodBase.h:324
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
PDF * fSplTrainB
PDFs of training MVA distribution (background)
Definition MethodBase.h:588
TString GetMethodTypeName() const
Definition MethodBase.h:302
Bool_t DoMulticlass() const
Definition MethodBase.h:409
virtual Double_t GetSignificance() const
compute significance of mean difference
void DisableWriting(Bool_t setter)
Definition MethodBase.h:412
Bool_t fTxtWeightsOnly
Definition MethodBase.h:658
virtual void ReadWeightsFromXML(void *wghtnode)=0
virtual Double_t GetProba(const Event *ev)
TH1 * fEffS
efficiency histogram for rootfinder
Definition MethodBase.h:575
TString fParentDir
method parent name, like booster name
Definition MethodBase.h:568
virtual const std::vector< Float_t > & GetMulticlassValues()
Definition MethodBase.h:197
TSpline * fSplTrainEffBvsS
splines for training signal eff. versus background eff.
Definition MethodBase.h:589
Types::EAnalysisType GetAnalysisType() const
Definition MethodBase.h:407
virtual TMatrixD GetMulticlassConfusionMatrix(Double_t effB, Types::ETreeType type)
Construct a confusion matrix for a multiclass classifier.
UInt_t GetTrainingTMVAVersionCode() const
Definition MethodBase.h:359
UInt_t fTMVATrainingVersion
Definition MethodBase.h:551
Bool_t IsModelPersistence() const
Definition MethodBase.h:353
Double_t fXmax
maximum (signal and background)
Definition MethodBase.h:599
Double_t fMeanS
mean (signal)
Definition MethodBase.h:594
Types::ESBType fVariableTransformType
Definition MethodBase.h:544
const TString & GetInputVar(Int_t i) const
Definition MethodBase.h:319
PDF * fSplTrainS
PDFs of training MVA distribution (signal)
Definition MethodBase.h:587
void SetMethodDir(TDirectory *methodDir)
Definition MethodBase.h:342
const TString & GetJobName() const
Definition MethodBase.h:300
Bool_t IgnoreEventsWithNegWeightsInTraining() const
Definition MethodBase.h:619
Double_t fTrainTime
Definition MethodBase.h:628
virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype)
writes all MVA evaluation histograms to file
virtual void TestMulticlass()
test multiclass classification
Bool_t fModelPersistence
Definition MethodBase.h:566
const TString & GetTestvarName() const
Definition MethodBase.h:305
const std::vector< TMVA::Event * > & GetEventCollection(Types::ETreeType type)
returns the event collection (i.e.
virtual std::vector< Double_t > GetDataMvaValues(DataSet *data=nullptr, Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false)
get all the MVA values for the events of the given Data type
void SetupMethod()
setup of methods
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
const Event * GetTestingEvent(Long64_t ievt) const
Definition MethodBase.h:710
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
UInt_t GetNTargets() const
Definition MethodBase.h:316
EMsgType fVerbosityLevel
verbosity level
Definition MethodBase.h:611
const TString GetProbaName() const
Definition MethodBase.h:306
TransformationHandler fTransformation
the list of transformations
Definition MethodBase.h:605
void AddInfoItem(void *gi, const TString &name, const TString &value) const
xml writing
TDirectory * fMethodBaseDir
Definition MethodBase.h:559
virtual void AddClassifierOutputProb(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
PDF * fSplS
PDFs of MVA distribution (signal)
Definition MethodBase.h:583
Double_t fSignalReferenceCutOrientation
Definition MethodBase.h:543
virtual Double_t GetEfficiency(const TString &, Types::ETreeType, Double_t &err)
fill background efficiency (resp.
TString GetTrainingTMVAVersionString() const
calculates the TMVA version string from the training version code on the fly
TSpline * fSpleffBvsS
splines for signal eff. versus background eff.
Definition MethodBase.h:585
TString fVariableTransformTypeString
Definition MethodBase.h:657
TSpline1 * fSplTrainRefB
Definition MethodBase.h:639
const TString & GetWeightFileDir() const
Definition MethodBase.h:425
virtual void SetAnalysisType(Types::EAnalysisType type)
Definition MethodBase.h:406
const TString & GetMethodName() const
Definition MethodBase.h:301
Bool_t TxtWeightsOnly() const
Definition MethodBase.h:467
void Statistics(Types::ETreeType treeType, const TString &theVarName, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &)
calculates rms,mean, xmin, xmax of the event variable this can be either done for the variables as th...
virtual void ReadWeightsFromStream(TFile &)
Definition MethodBase.h:236
UInt_t GetNEvents() const
Definition MethodBase.h:386
Bool_t DoRegression() const
Definition MethodBase.h:408
std::vector< Float_t > * fRegressionReturnVal
Definition MethodBase.h:530
std::vector< Float_t > * fMulticlassReturnVal
Definition MethodBase.h:531
Double_t fRmsS
RMS (signal)
Definition MethodBase.h:596
Bool_t GetLine(std::istream &fin, char *buf)
reads one line from the input stream checks for certain keywords and interprets the line if keywords ...
const Event * GetEvent() const
Definition MethodBase.h:684
TString fVarTransformString
labels variable transform method
Definition MethodBase.h:602
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
virtual std::vector< Double_t > GetMvaValues(Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false)
get all the MVA values for the events of the current Data type
virtual Bool_t IsSignalLike()
uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation) for...
void Init() override=0
void RerouteTransformationHandler(TransformationHandler *fTargetTransformation)
Definition MethodBase.h:373
virtual ~MethodBase()
destructor
Bool_t HasMVAPdfs() const
Definition MethodBase.h:405
PDF * fMVAPdfS
signal MVA PDF
Definition MethodBase.h:578
void WriteMonitoringHistosToFile() const override
write special monitoring histograms to file dummy implementation here --------------—
const Ranking * CreateRanking() override=0
UInt_t fBackgroundClass
Definition MethodBase.h:623
Double_t fTestTime
Definition MethodBase.h:629
virtual Double_t GetMaximumSignificance(Double_t SignalEvents, Double_t BackgroundEvents, Double_t &optimal_significance_value) const
plot significance, , curve for given number of signal and background events; returns cut for maximum ...
virtual Double_t GetTrainingEfficiency(const TString &)
void SetWeightFileName(TString)
set the weight file name (depreciated)
DataSetInfo & DataInfo() const
Definition MethodBase.h:380
TString GetWeightFileName() const
retrieve weight file name
void SetTestTime(Double_t testTime)
Definition MethodBase.h:132
Types::EMVA fMethodType
Definition MethodBase.h:549
virtual void TestClassification()
initialization
void AddOutput(Types::ETreeType type, Types::EAnalysisType analysisType)
UInt_t GetNVariables() const
Definition MethodBase.h:315
Types::EAnalysisType fAnalysisType
Definition MethodBase.h:528
virtual void AddRegressionOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
void InitBase()
default initialization called by all constructors
std::vector< const std::vector< TMVA::Event * > * > fEventCollections
Definition MethodBase.h:641
virtual void GetRegressionDeviation(UInt_t tgtNum, Types::ETreeType type, Double_t &stddev, Double_t &stddev90Percent) const
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
Bool_t fSetupCompleted
Definition MethodBase.h:644
void MakeClass(const TString &classFileName=TString("")) const override
create reader class for method (classification only at present)
void CreateMVAPdfs()
Create PDFs of the MVA output variables.
TString GetTrainingROOTVersionString() const
calculates the ROOT version string from the training version code on the fly
virtual Double_t GetValueForRoot(Double_t)
returns efficiency as function of cut
UInt_t GetTrainingROOTVersionCode() const
Definition MethodBase.h:360
void ReadStateFromFile()
Function to write options and weights to file.
void WriteVarsToStream(std::ostream &tf, const TString &prefix="") const
write the list of variables (name, min, max) for a given data transformation method to the stream
void ReadVarsFromStream(std::istream &istr)
Read the variables (name, min, max) for a given data transformation method from the stream.
virtual void AddWeightsXMLTo(void *parent) const =0
void ReadSpectatorsFromXML(void *specnode)
read spectator info from XML
virtual const std::vector< Float_t > & GetTrainingHistory(const char *)
Definition MethodBase.h:203
const Event * fTmpEvent
! temporary event when testing on a different DataSet than the own one
Definition MethodBase.h:415
void SetNormalised(Bool_t norm)
Definition MethodBase.h:430
void SetTestvarName(const TString &v="")
Definition MethodBase.h:311
void ReadVariablesFromXML(void *varnode)
read variable info from XML
Bool_t fConstructedFromWeightFile
Definition MethodBase.h:553
Bool_t fHelp
help flag
Definition MethodBase.h:612
UInt_t GetNvar() const
Definition MethodBase.h:314
virtual std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA")
call the Optimizer with the set of parameters and ranges that are meant to be tuned.
void SetTrainTime(Double_t trainTime)
Definition MethodBase.h:128
Double_t GetXmax(Int_t ivar) const
Definition MethodBase.h:327
virtual std::vector< Float_t > GetMulticlassTrainingEfficiency(std::vector< std::vector< Float_t > > &purity)
DataSetInfo & fDataSetInfo
! the data set information (sometimes needed)
Definition MethodBase.h:540
Bool_t fHasMVAPdfs
MVA Pdfs are created for this classifier.
Definition MethodBase.h:613
void WriteStateToStream(std::ostream &tf) const
general method used in writing the header of the weight files where the used variables,...
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity:
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
set the tuning parameters according to the argument This is just a dummy .
Double_t GetTrainTime() const
Definition MethodBase.h:129
void SetBaseDir(TDirectory *methodDir)
Definition MethodBase.h:343
void ReadStateFromStream(std::istream &tf)
read the header from the weight files of the different MVA methods
void AddVarsXMLTo(void *parent) const
write variable info to XML
void Train() override=0
Bool_t Help() const
Definition MethodBase.h:437
TSpline1 * fSplRefB
Definition MethodBase.h:636
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
Definition MethodBase.h:364
Double_t GetMvaValue(Double_t *errLower=nullptr, Double_t *errUpper=nullptr) override=0
Bool_t IsSilentFile() const
Definition MethodBase.h:349
Types::EMVA GetMethodType() const
Definition MethodBase.h:303
void AddTargetsXMLTo(void *parent) const
write target info to XML
Results * fResults
Definition MethodBase.h:663
void MakeClassSpecific(std::ostream &, const TString &="") const override
Definition MethodBase.h:453
Double_t fXmin
minimum (signal and background)
Definition MethodBase.h:598
PDF * fDefaultPDF
default PDF definitions
Definition MethodBase.h:577
void ReadTargetsFromXML(void *tarnode)
read target info from XML
void SetFile(TFile *file)
Definition MethodBase.h:345
void ProcessBaseOptions()
the option string is decoded, for available options see "DeclareOptions"
virtual void Reset()
Definition MethodBase.h:160
UInt_t fROOTTrainingVersion
Definition MethodBase.h:552
void ReadWeightsFromStream(std::istream &) override=0
void ReadStateFromXML(void *parent)
Double_t GetSignalReferenceCutOrientation() const
Definition MethodBase.h:331
void SetSignalReferenceCut(Double_t cut)
Definition MethodBase.h:334
virtual std::vector< Float_t > GetAllRegressionValues()
Get al regression values in one call.
std::vector< TString > * fInputVars
Definition MethodBase.h:521
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
Double_t fSignalReferenceCut
Definition MethodBase.h:542
Double_t GetTestTime() const
Definition MethodBase.h:133
Double_t fMeanB
mean (background)
Definition MethodBase.h:595
const TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true) const
Definition MethodBase.h:368
void SetSignalReferenceCutOrientation(Double_t cutOrientation)
Definition MethodBase.h:335
TDirectory * fBaseDir
Definition MethodBase.h:558
Bool_t fIgnoreNegWeightsInTraining
If true, events with negative weights are not used in training.
Definition MethodBase.h:615
void WriteStateToFile() const
write options and weights to file note that each one text file for the main configuration information...
void DeclareOptions() override=0
void AddClassesXMLTo(void *parent) const
write class info to XML
const TString & GetInputLabel(Int_t i) const
Definition MethodBase.h:320
ECutOrientation GetCutOrientation() const
Definition MethodBase.h:485
Ranking * fRanking
Definition MethodBase.h:520
TrainingHistory fTrainHistory
Definition MethodBase.h:395
void SetMethodBaseDir(TDirectory *methodDir)
Definition MethodBase.h:344
virtual void AddClassifierOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
PDF * fMVAPdfB
background MVA PDF
Definition MethodBase.h:579
DataSet * Data() const
Definition MethodBase.h:379
void AddSpectatorsXMLTo(void *parent) const
write spectator info to XML
void SetModelPersistence(Bool_t status)
Definition MethodBase.h:352
TString fWeightFile
weight file name
Definition MethodBase.h:571
Bool_t IsNormalised() const
Definition MethodBase.h:429
const TString & GetInternalVarName(Int_t ivar) const
Definition MethodBase.h:443
const Event * GetTrainingEvent(Long64_t ievt) const
Definition MethodBase.h:704
Double_t GetSignalReferenceCut() const
Definition MethodBase.h:330
TSpline1 * fSplTrainRefS
Definition MethodBase.h:638
TSpline1 * fSplRefS
Definition MethodBase.h:635
virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const
calculate the area (integral) under the ROC curve as a overall quality measure of the classification
ECutOrientation fCutOrientation
Definition MethodBase.h:632
Double_t GetRMS(Int_t ivar) const
Definition MethodBase.h:325
const char * GetInputTitle(Int_t i) const
Definition MethodBase.h:321
const TString & GetOriginalVarName(Int_t ivar) const
Definition MethodBase.h:444
virtual void AddMulticlassOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Bool_t IsConstructedFromWeightFile() const
Definition MethodBase.h:473
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
Class for boosting a TMVA method.
Definition MethodBoost.h:55
Class for categorizing the phase space.
Virtual base class for combining several TMVA method.
Multivariate optimisation of signal efficiency for given background efficiency, applying rectangular ...
Definition MethodCuts.h:61
PDF wrapper for histograms; uses user-defined spline interpolation.
Definition PDF.h:63
Ranking for variables in method (implementation)
Definition Ranking.h:48
Class that is the base-class for a vector of result.
Definition Results.h:57
Root finding using Brents algorithm (translated from CERNLIB function RZERO)
Definition RootFinder.h:48
Linear interpolation of TGraph.
Definition TSpline1.h:43
Tracking data from training.
Class that contains all the data information.
const Event * Transform(const Event *) const
the transformation
Double_t GetRMS(Int_t ivar, Int_t cls=-1) const
Double_t GetMean(Int_t ivar, Int_t cls=-1) const
Double_t GetMin(Int_t ivar, Int_t cls=-1) const
Double_t GetMax(Int_t ivar, Int_t cls=-1) const
static Types & Instance()
The single instance of "Types" if existing already, or create it (Singleton)
Definition Types.cxx:70
@ kBackground
Definition Types.h:136
@ kMulticlass
Definition Types.h:129
@ kRegression
Definition Types.h:128
@ kTraining
Definition Types.h:143
const TString & GetLabel() const
const TString & GetExpression() const
const TString & GetInternalName() const
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Base class for spline implementation containing the Draw/Paint methods.
Definition TSpline.h:31
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
A TTree represents a columnar dataset.
Definition TTree.h:89
create variable transformations