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 namespace Experimental {
78 class Classification;
79 }
80 class TrainingHistory;
81
82 class MethodBase : virtual public IMethod, public Configurable {
83
84 friend class CrossValidation;
85 friend class Factory;
86 friend class RootFinder;
87 friend class MethodBoost;
90
91 public:
92
94
95 // default constructor
98 const TString& methodTitle,
100 const TString& theOption = "" );
101
102 // constructor used for Testing + Application of the MVA, only (no training),
103 // using given weight file
106 const TString& weightFile );
107
108 // default destructor
109 virtual ~MethodBase();
110
111 // declaration, processing and checking of configuration options
112 void SetupMethod();
113 void ProcessSetup();
114 virtual void CheckSetup(); // may be overwritten by derived classes
115
116 // ---------- main training and testing methods ------------------------------
117
118 // prepare tree branch with the method's discriminating variable
120
121 // performs classifier training
122 // calls methods Train() implemented by derived classes
123 void TrainMethod();
124
125 // optimize tuning parameters
126 virtual std::map<TString,Double_t> OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA");
127 virtual void SetTuneParameters(std::map<TString,Double_t> tuneParameters);
128
129 void Train() override = 0;
130
131 // store and retrieve time used for training
133 Double_t GetTrainTime() const { return fTrainTime; }
134
135 // store and retrieve time used for testing
137 Double_t GetTestTime () const { return fTestTime; }
138
139 // performs classifier testing
140 virtual void TestClassification();
142
143 // performs multiclass classifier testing
144 virtual void TestMulticlass();
145
146 // performs regression testing
147 virtual void TestRegression( Double_t& bias, Double_t& biasT,
150 Double_t& mInf, Double_t& mInfT, // mutual information
151 Double_t& corr,
153
154 // options treatment
155 void Init() override = 0;
156 void DeclareOptions() override = 0;
157 void ProcessOptions() override = 0;
158 virtual void DeclareCompatibilityOptions(); // declaration of past options
159
160 // reset the Method --> As if it was not yet trained, just instantiated
161 // virtual void Reset() = 0;
162 //for the moment, I provide a dummy (that would not work) default, just to make
163 // compilation/running w/o parameter optimisation still possible
164 virtual void Reset(){return;}
165
166 // classifier response:
167 // some methods may return a per-event error estimate
168 // error calculation is skipped if err==0
169 Double_t GetMvaValue( Double_t* errLower = nullptr, Double_t* errUpper = nullptr) override = 0;
170
171 // signal/background classification response
172 Double_t GetMvaValue( const TMVA::Event* const ev, Double_t* err = nullptr, Double_t* errUpper = nullptr );
173
174 protected:
175 // helper function to set errors to -1
176 void NoErrorCalc(Double_t* const err, Double_t* const errUpper);
177
178 // signal/background classification response for all current set of data
179 virtual std::vector<Double_t> GetMvaValues(Long64_t firstEvt = 0, Long64_t lastEvt = -1, Bool_t logProgress = false);
180 // same as above but using a provided data set (used by MethodCategory)
181 virtual std::vector<Double_t> GetDataMvaValues(DataSet *data = nullptr, Long64_t firstEvt = 0, Long64_t lastEvt = -1, Bool_t logProgress = false);
182
183 virtual std::vector<Float_t> GetAllRegressionValues();
184 virtual std::vector<Float_t> GetAllMulticlassValues();
185
186 public:
187 // regression response
188 const std::vector<Float_t>& GetRegressionValues(const TMVA::Event* const ev){
189 fTmpEvent = ev;
190 const std::vector<Float_t>* ptr = &GetRegressionValues();
191 fTmpEvent = nullptr;
192 return (*ptr);
193 }
194
195 virtual const std::vector<Float_t>& GetRegressionValues() {
196 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
197 return (*ptr);
198 }
199
200 // multiclass classification response
201 virtual const std::vector<Float_t>& GetMulticlassValues() {
202 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
203 return (*ptr);
204 }
205
206 // Training history
207 virtual const std::vector<Float_t>& GetTrainingHistory(const char* /*name*/ ) {
208 std::vector<Float_t>* ptr = new std::vector<Float_t>(0);
209 return (*ptr);
210 }
211
212 // probability of classifier response (mvaval) to be signal (requires "CreateMvaPdf" option set)
213 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)
215
216 // Rarity of classifier response (signal or background (default) is uniform in [0,1])
218
219 // create ranking
220 const Ranking* CreateRanking() override = 0;
221
222 // make ROOT-independent C++ class
223 void MakeClass( const TString& classFileName = TString("") ) const override;
224
225 // print help message
226 void PrintHelpMessage() const override;
227
228 //
229 // streamer methods for training information (creates "weight" files) --------
230 //
231 public:
232 void WriteStateToFile () const;
233 void ReadStateFromFile ();
234
235 protected:
236 // the actual "weights"
237 virtual void AddWeightsXMLTo ( void* parent ) const = 0;
238 virtual void ReadWeightsFromXML ( void* wghtnode ) = 0;
239 void ReadWeightsFromStream( std::istream& ) override = 0; // backward compatibility
240 virtual void ReadWeightsFromStream( TFile& ) {} // backward compatibility
241
242 private:
243 friend class MethodCategory;
245 void WriteStateToXML ( void* parent ) const;
246 void ReadStateFromXML ( void* parent );
247 void WriteStateToStream ( std::ostream& tf ) const; // needed for MakeClass
248 void WriteVarsToStream ( std::ostream& tf, const TString& prefix = "" ) const; // needed for MakeClass
249
250
251 public: // these two need to be public, they are used to read in-memory weight-files
252 void ReadStateFromStream ( std::istream& tf ); // backward compatibility
253 void ReadStateFromStream ( TFile& rf ); // backward compatibility
254 void ReadStateFromXMLString( const char* xmlstr ); // for reading from memory
255
256 private:
257 // the variable information
258 void AddVarsXMLTo ( void* parent ) const;
259 void AddSpectatorsXMLTo ( void* parent ) const;
260 void AddTargetsXMLTo ( void* parent ) const;
261 void AddClassesXMLTo ( void* parent ) const;
262 void ReadVariablesFromXML ( void* varnode );
263 void ReadSpectatorsFromXML( void* specnode);
264 void ReadTargetsFromXML ( void* tarnode );
265 void ReadClassesFromXML ( void* clsnode );
266 void ReadVarsFromStream ( std::istream& istr ); // backward compatibility
267
268 public:
269 // ---------------------------------------------------------------------------
270
271 // write evaluation histograms into target file
273
274 // write classifier-specific monitoring information to target file
275 void WriteMonitoringHistosToFile() const override;
276
277 // ---------- public evaluation methods --------------------------------------
278
279 // individual initialization for testing of each method
280 // overload this one for individual initialisation of the testing,
281 // it is then called automatically within the global "TestInit"
282
283 // variables (and private member functions) for the Evaluation:
284 // get the efficiency. It fills a histogram for efficiency/vs/bkg
285 // and returns the one value fo the efficiency demanded for
286 // in the TString argument. (Watch the string format)
287 virtual Double_t GetEfficiency( const TString&, Types::ETreeType, Double_t& err );
288 virtual Double_t GetTrainingEfficiency(const TString& );
289 virtual std::vector<Float_t> GetMulticlassEfficiency( std::vector<std::vector<Float_t> >& purity );
290 virtual std::vector<Float_t> GetMulticlassTrainingEfficiency(std::vector<std::vector<Float_t> >& purity );
292 virtual Double_t GetSignificance() const;
293 virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const;
294 virtual Double_t GetROCIntegral(PDF *pdfS=nullptr, PDF *pdfB=nullptr) const;
297 virtual Double_t GetSeparation( TH1*, TH1* ) const;
298 virtual Double_t GetSeparation( PDF* pdfS = nullptr, PDF* pdfB = nullptr ) const;
299
301 // ---------- public accessors -----------------------------------------------
302
303 // classifier naming (a lot of names ... aren't they ;-)
304 const TString& GetJobName () const { return fJobName; }
305 const TString& GetMethodName () const { return fMethodName; }
306 TString GetMethodTypeName() const { return Types::Instance().GetMethodName(fMethodType); }
308 const char* GetName () const override { return fMethodName.Data(); }
309 const TString& GetTestvarName () const { return fTestvar; }
310 const TString GetProbaName () const { return fTestvar + "_Proba"; }
312
313 // build classifier name in Test tree
314 // MVA prefix (e.g., "TMVA_")
315 void SetTestvarName ( const TString & v="" ) { fTestvar = (v=="") ? ("MVA_" + GetMethodName()) : v; }
316
317 // number of input variable used by classifier
318 UInt_t GetNvar() const { return DataInfo().GetNVariables(); }
320 UInt_t GetNTargets() const { return DataInfo().GetNTargets(); };
321
322 // internal names and expressions of input variables
323 const TString& GetInputVar ( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetInternalName(); }
324 const TString& GetInputLabel( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetLabel(); }
325 const char * GetInputTitle( Int_t i ) const { return DataInfo().GetVariableInfo(i).GetTitle(); }
326
327 // normalisation and limit accessors
332
333 // sets the minimum requirement on the MVA output to declare an event signal-like
336
337 // sets the minimum requirement on the MVA output to declare an event signal-like
340
341 // pointers to ROOT directories
342 TDirectory* BaseDir() const;
343 TDirectory* MethodBaseDir() const;
344 TFile* GetFile() const {return fFile;}
345
349 void SetFile(TFile* file){fFile=file;}
350
351 //Silent file
352 void SetSilentFile(Bool_t status) {fSilentFile=status;}
354
355 //Model Persistence
356 void SetModelPersistence(Bool_t status){fModelPersistence=status;}//added support to create/remove dir here if exits or not
358
359 // the TMVA version can be obtained and checked using
360 // if (GetTrainingTMVAVersionCode()>TMVA_VERSION(3,7,2)) {...}
361 // or
362 // if (GetTrainingROOTVersionCode()>ROOT_VERSION(5,15,5)) {...}
367
376
378
379 // ---------- event accessors ------------------------------------------------
380
381 // returns reference to data set
382 // NOTE: this DataSet is the "original" dataset, i.e. the one seen by ALL Classifiers WITHOUT transformation
383 DataSet* Data() const { return (fTmpData) ? fTmpData : DataInfo().GetDataSet(); }
384 DataSetInfo& DataInfo() const { return fDataSetInfo; }
385
386
387 // event reference and update
388 // NOTE: these Event accessors make sure that you get the events transformed according to the
389 // particular classifiers transformation chosen
390 UInt_t GetNEvents () const { return Data()->GetNEvents(); }
391 const Event* GetEvent () const;
392 const Event* GetEvent ( const TMVA::Event* ev ) const;
393 const Event* GetEvent ( Long64_t ievt ) const;
394 const Event* GetEvent ( Long64_t ievt , Types::ETreeType type ) const;
395 const Event* GetTrainingEvent( Long64_t ievt ) const;
396 const Event* GetTestingEvent ( Long64_t ievt ) const;
397 const std::vector<TMVA::Event*>& GetEventCollection( Types::ETreeType type );
398
400 // ---------- public auxiliary methods ---------------------------------------
401
402 // this method is used to decide whether an event is signal- or background-like
403 // the reference cut "xC" is taken to be where
404 // Int_[-oo,xC] { PDF_S(x) dx } = Int_[xC,+oo] { PDF_B(x) dx }
405 virtual Bool_t IsSignalLike();
407
408
409 Bool_t HasMVAPdfs() const { return fHasMVAPdfs; }
414
415 // setter method for suppressing writing to XML and writing of standalone classes
417
418 protected:
419 mutable const Event *fTmpEvent; ///<! temporary event when testing on a different DataSet than the own one
420 DataSet *fTmpData = nullptr; ///<! temporary dataset used when evaluating on a different data (used by MethodCategory::GetMvaValues)
421
422 // ---------- protected accessors -------------------------------------------
423
424 //TDirectory* LocalTDir() const { return Data().LocalRootDir(); }
425
426 // weight file name and directory (given by global config variable)
428
429 const TString& GetWeightFileDir() const { return fFileDir; }
431
432 // are input variables normalised ?
433 Bool_t IsNormalised() const { return fNormalise; }
435
436 // set number of input variables (only used by MethodCuts, could perhaps be removed)
437 // void SetNvar( Int_t n ) { fNvar = n; }
438
439 // verbose and help flags
440 Bool_t Verbose() const { return fVerbose; }
441 Bool_t Help () const { return fHelp; }
442
443 // ---------- protected event and tree accessors -----------------------------
444
445 // names of input variables (if the original names are expressions, they are
446 // transformed into regexps)
447 const TString& GetInternalVarName( Int_t ivar ) const { return (*fInputVars)[ivar]; }
449
450 Bool_t HasTrainingTree() const { return Data()->GetNTrainingEvents() != 0; }
451
452 // ---------- protected auxiliary methods ------------------------------------
453
454 protected:
455
456 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
457 void MakeClassSpecific( std::ostream&, const TString& = "" ) const override {}
458
459 // header and auxiliary classes
460 virtual void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const {}
461
462 // static pointer to this object - required for ROOT finder (to be solved differently)(solved by Omar)
463 //static MethodBase* GetThisBase();
464
465 // some basic statistical analysis
469
470 // if TRUE, write weights only to text files
471 Bool_t TxtWeightsOnly() const { return kTRUE; }
472
473 protected:
474
475 // access to event information that needs method-specific information
476
478
479 private:
480
481 // ---------- private definitions --------------------------------------------
482 // Initialisation
483 void InitBase();
484 void DeclareBaseOptions();
485 void ProcessBaseOptions();
486
487 // used in efficiency computation
490
491 // ---------- private accessors ---------------------------------------------
492
493 // reset required for RootFinder
495
496 // ---------- private auxiliary methods --------------------------------------
497
498 // PDFs for classifier response (required to compute signal probability and Rarity)
499 void CreateMVAPdfs();
500
501 // for root finder
502 //virtual method to find ROOT
503 virtual Double_t GetValueForRoot ( Double_t ); // implementation
504
505 // used for file parsing
506 Bool_t GetLine( std::istream& fin, char * buf );
507
508 // fill test tree with classification or regression results
513
514 private:
515
516 void AddInfoItem( void* gi, const TString& name,
517 const TString& value) const;
518
519 // ========== class members ==================================================
520
521 protected:
522
523 // direct accessors
524 Ranking* fRanking; // pointer to ranking object (created by derived classifiers)
525 std::vector<TString>* fInputVars; // vector of input variables used in MVA
526
527 // histogram binning
528 Int_t fNbins; // number of bins in input variable histograms
529 Int_t fNbinsMVAoutput; // number of bins in MVA output histograms
530 Int_t fNbinsH; // number of bins in evaluation histograms
531
532 Types::EAnalysisType fAnalysisType; // method-mode : true --> regression, false --> classification
533
534 std::vector<Float_t>* fRegressionReturnVal; // holds the return-values for the regression
535 std::vector<Float_t>* fMulticlassReturnVal; // holds the return-values for the multiclass classification
536
537 private:
538
539 // MethodCuts redefines some of the evaluation variables and histograms -> must access private members
540 friend class MethodCuts;
541
542
543 // data sets
544 DataSetInfo& fDataSetInfo; ///<! the data set information (sometimes needed)
545
546 Double_t fSignalReferenceCut; // minimum requirement on the MVA output to declare an event signal-like
547 Double_t fSignalReferenceCutOrientation; // minimum requirement on the MVA output to declare an event signal-like
548 Types::ESBType fVariableTransformType; // this is the event type (sig or bgd) assumed for variable transform
549
550 // naming and versioning
551 TString fJobName; // name of job -> user defined, appears in weight files
552 TString fMethodName; // name of the method (set in derived class)
553 Types::EMVA fMethodType; // type of method (set in derived class)
554 TString fTestvar; // variable used in evaluation, etc (mostly the MVA)
555 UInt_t fTMVATrainingVersion; // TMVA version used for training
556 UInt_t fROOTTrainingVersion; // ROOT version used for training
557 Bool_t fConstructedFromWeightFile; // is it obtained from weight file?
558
559 // Directory structure: dataloader/fMethodBaseDir/fBaseDir
560 // where the first directory name is defined by the method type
561 // and the second is user supplied (the title given in Factory::BookMethod())
562 TDirectory* fBaseDir; // base directory for the instance, needed to know where to jump back from localDir
563 mutable TDirectory* fMethodBaseDir; // base directory for the method
564 //this will be the next way to save results
566
567 //SilentFile
569 //Model Persistence
571
572 TString fParentDir; ///< method parent name, like booster name
573
574 TString fFileDir; ///< unix sub-directory for weight files (default: DataLoader's Name + "weights")
575 TString fWeightFile; ///< weight file name
576
577 private:
578
579 TH1* fEffS; ///< efficiency histogram for rootfinder
580
581 PDF* fDefaultPDF; ///< default PDF definitions
582 PDF* fMVAPdfS; ///< signal MVA PDF
583 PDF* fMVAPdfB; ///< background MVA PDF
584
585 // TH1D* fmvaS; ///< PDFs of MVA distribution (signal)
586 // TH1D* fmvaB; ///< PDFs of MVA distribution (background)
587 PDF* fSplS; ///< PDFs of MVA distribution (signal)
588 PDF* fSplB; ///< PDFs of MVA distribution (background)
589 TSpline* fSpleffBvsS; ///< splines for signal eff. versus background eff.
590
591 PDF* fSplTrainS; ///< PDFs of training MVA distribution (signal)
592 PDF* fSplTrainB; ///< PDFs of training MVA distribution (background)
593 TSpline* fSplTrainEffBvsS; ///< splines for training signal eff. versus background eff.
594
595 private:
596
597 // basic statistics quantities of MVA
598 Double_t fMeanS; ///< mean (signal)
599 Double_t fMeanB; ///< mean (background)
600 Double_t fRmsS; ///< RMS (signal)
601 Double_t fRmsB; ///< RMS (background)
602 Double_t fXmin; ///< minimum (signal and background)
603 Double_t fXmax; ///< maximum (signal and background)
604
605 // variable preprocessing
606 TString fVarTransformString; ///< labels variable transform method
607
608 TransformationHandler* fTransformationPointer; ///< pointer to the rest of transformations
609 TransformationHandler fTransformation; ///< the list of transformations
610
611
612 // help and verbosity
613 Bool_t fVerbose; ///< verbose flag
614 TString fVerbosityLevelString; ///< verbosity level (user input string)
615 EMsgType fVerbosityLevel; ///< verbosity level
616 Bool_t fHelp; ///< help flag
617 Bool_t fHasMVAPdfs; ///< MVA Pdfs are created for this classifier
618
619 Bool_t fIgnoreNegWeightsInTraining; ///< If true, events with negative weights are not used in training
620
621 protected:
622
624
625 // for signal/background
626 UInt_t fSignalClass; // index of the Signal-class
627 UInt_t fBackgroundClass; // index of the Background-class
628
629 private:
630
631 // timing variables
632 Double_t fTrainTime; // for timing measurements
633 Double_t fTestTime; // for timing measurements
634
635 // orientation of cut: depends on signal and background mean values
636 ECutOrientation fCutOrientation; // +1 if Sig>Bkg, -1 otherwise
637
638 // for root finder
639 TSpline1* fSplRefS; // helper splines for RootFinder (signal)
640 TSpline1* fSplRefB; // helper splines for RootFinder (background)
641
642 TSpline1* fSplTrainRefS; // helper splines for RootFinder (signal)
643 TSpline1* fSplTrainRefB; // helper splines for RootFinder (background)
644
645 mutable std::vector<const std::vector<TMVA::Event*>*> fEventCollections; // if the method needs the complete event-collection, the transformed event coll. ist stored here.
646
647 public:
648 Bool_t fSetupCompleted; // is method setup
649
650 private:
651
652 // This is a workaround for OSx where static thread_local data members are
653 // not supported. The C++ solution would indeed be the following:
654// static MethodBase*& GetThisBaseThreadLocal() {TTHREAD_TLS(MethodBase*) fgThisBase(nullptr); return fgThisBase; };
655
656 // ===== depreciated options, kept for backward compatibility =====
657 private:
658
659 Bool_t fNormalise; // normalise input variables
660 Bool_t fUseDecorr; // synonymous for decorrelation
661 TString fVariableTransformTypeString; // labels variable transform type
662 Bool_t fTxtWeightsOnly; // if TRUE, write weights only to text files
663 Int_t fNbinsMVAPdf; // number of bins used in histogram that creates PDF
664 Int_t fNsmoothMVAPdf; // number of times a histogram is smoothed before creating the PDF
665
666 protected:
668 ClassDefOverride(MethodBase,0); // Virtual base class for all TMVA method
669
670 };
671} // namespace TMVA
672
673
674
675
676
677
678
679// ========== INLINE FUNCTIONS =========================================================
680
681
682//_______________________________________________________________________
684{
686}
687
689{
690 if(fTmpEvent)
691 return GetTransformationHandler().Transform(fTmpEvent);
692 else
693 return GetTransformationHandler().Transform(Data()->GetEvent());
694}
695
697{
698 assert(fTmpEvent==nullptr);
699 return GetTransformationHandler().Transform(Data()->GetEvent(ievt));
700}
701
703{
704 assert(fTmpEvent==nullptr);
705 return GetTransformationHandler().Transform(Data()->GetEvent(ievt, type));
706}
707
709{
710 assert(fTmpEvent==nullptr);
711 return GetEvent(ievt, Types::kTraining);
712}
713
715{
716 assert(fTmpEvent==nullptr);
717 return GetEvent(ievt, Types::kTesting);
718}
719
720#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:348
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:148
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 two class classification.
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:82
TransformationHandler * fTransformationPointer
pointer to the rest of transformations
Definition MethodBase.h:608
void ProcessOptions() override=0
virtual void MakeClassSpecificHeader(std::ostream &, const TString &="") const
Definition MethodBase.h:460
TString fVerbosityLevelString
verbosity level (user input string)
Definition MethodBase.h:614
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:195
const std::vector< Float_t > & GetRegressionValues(const TMVA::Event *const ev)
Definition MethodBase.h:188
PDF * fSplB
PDFs of MVA distribution (background)
Definition MethodBase.h:588
Bool_t fVerbose
verbose flag
Definition MethodBase.h:613
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:552
TFile * GetFile() const
Definition MethodBase.h:344
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:574
DataSet * fTmpData
! temporary dataset used when evaluating on a different data (used by MethodCategory::GetMvaValues)
Definition MethodBase.h:420
Bool_t HasTrainingTree() const
Definition MethodBase.h:450
const char * GetName() const override
Definition MethodBase.h:308
void SetSilentFile(Bool_t status)
Definition MethodBase.h:352
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:601
Double_t GetXmin(Int_t ivar) const
Definition MethodBase.h:330
Bool_t Verbose() const
Definition MethodBase.h:440
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:328
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:592
TString GetMethodTypeName() const
Definition MethodBase.h:306
Bool_t DoMulticlass() const
Definition MethodBase.h:413
virtual Double_t GetSignificance() const
compute significance of mean difference
void DisableWriting(Bool_t setter)
Definition MethodBase.h:416
Bool_t fTxtWeightsOnly
Definition MethodBase.h:662
virtual void ReadWeightsFromXML(void *wghtnode)=0
virtual Double_t GetProba(const Event *ev)
TH1 * fEffS
efficiency histogram for rootfinder
Definition MethodBase.h:579
TString fParentDir
method parent name, like booster name
Definition MethodBase.h:572
virtual const std::vector< Float_t > & GetMulticlassValues()
Definition MethodBase.h:201
TSpline * fSplTrainEffBvsS
splines for training signal eff. versus background eff.
Definition MethodBase.h:593
Types::EAnalysisType GetAnalysisType() const
Definition MethodBase.h:411
virtual TMatrixD GetMulticlassConfusionMatrix(Double_t effB, Types::ETreeType type)
Construct a confusion matrix for a multiclass classifier.
UInt_t GetTrainingTMVAVersionCode() const
Definition MethodBase.h:363
UInt_t fTMVATrainingVersion
Definition MethodBase.h:555
Bool_t IsModelPersistence() const
Definition MethodBase.h:357
Double_t fXmax
maximum (signal and background)
Definition MethodBase.h:603
Double_t fMeanS
mean (signal)
Definition MethodBase.h:598
Types::ESBType fVariableTransformType
Definition MethodBase.h:548
const TString & GetInputVar(Int_t i) const
Definition MethodBase.h:323
PDF * fSplTrainS
PDFs of training MVA distribution (signal)
Definition MethodBase.h:591
void SetMethodDir(TDirectory *methodDir)
Definition MethodBase.h:346
const TString & GetJobName() const
Definition MethodBase.h:304
Bool_t IgnoreEventsWithNegWeightsInTraining() const
Definition MethodBase.h:623
Double_t fTrainTime
Definition MethodBase.h:632
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:570
const TString & GetTestvarName() const
Definition MethodBase.h:309
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:714
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
UInt_t GetNTargets() const
Definition MethodBase.h:320
EMsgType fVerbosityLevel
verbosity level
Definition MethodBase.h:615
const TString GetProbaName() const
Definition MethodBase.h:310
TransformationHandler fTransformation
the list of transformations
Definition MethodBase.h:609
void AddInfoItem(void *gi, const TString &name, const TString &value) const
xml writing
TDirectory * fMethodBaseDir
Definition MethodBase.h:563
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:587
Double_t fSignalReferenceCutOrientation
Definition MethodBase.h:547
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:589
TString fVariableTransformTypeString
Definition MethodBase.h:661
TSpline1 * fSplTrainRefB
Definition MethodBase.h:643
const TString & GetWeightFileDir() const
Definition MethodBase.h:429
virtual void SetAnalysisType(Types::EAnalysisType type)
Definition MethodBase.h:410
const TString & GetMethodName() const
Definition MethodBase.h:305
Bool_t TxtWeightsOnly() const
Definition MethodBase.h:471
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:240
UInt_t GetNEvents() const
Definition MethodBase.h:390
Bool_t DoRegression() const
Definition MethodBase.h:412
std::vector< Float_t > * fRegressionReturnVal
Definition MethodBase.h:534
std::vector< Float_t > * fMulticlassReturnVal
Definition MethodBase.h:535
Double_t fRmsS
RMS (signal)
Definition MethodBase.h:600
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:688
TString fVarTransformString
labels variable transform method
Definition MethodBase.h:606
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:377
virtual ~MethodBase()
destructor
Bool_t HasMVAPdfs() const
Definition MethodBase.h:409
PDF * fMVAPdfS
signal MVA PDF
Definition MethodBase.h:582
void WriteMonitoringHistosToFile() const override
write special monitoring histograms to file dummy implementation here --------------—
const Ranking * CreateRanking() override=0
UInt_t fBackgroundClass
Definition MethodBase.h:627
Double_t fTestTime
Definition MethodBase.h:633
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:384
TString GetWeightFileName() const
retrieve weight file name
void SetTestTime(Double_t testTime)
Definition MethodBase.h:136
Types::EMVA fMethodType
Definition MethodBase.h:553
virtual void TestClassification()
initialization
void AddOutput(Types::ETreeType type, Types::EAnalysisType analysisType)
UInt_t GetNVariables() const
Definition MethodBase.h:319
Types::EAnalysisType fAnalysisType
Definition MethodBase.h:532
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:645
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:648
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:364
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:207
const Event * fTmpEvent
! temporary event when testing on a different DataSet than the own one
Definition MethodBase.h:419
void SetNormalised(Bool_t norm)
Definition MethodBase.h:434
void SetTestvarName(const TString &v="")
Definition MethodBase.h:315
void ReadVariablesFromXML(void *varnode)
read variable info from XML
Bool_t fConstructedFromWeightFile
Definition MethodBase.h:557
Bool_t fHelp
help flag
Definition MethodBase.h:616
UInt_t GetNvar() const
Definition MethodBase.h:318
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:132
Double_t GetXmax(Int_t ivar) const
Definition MethodBase.h:331
virtual std::vector< Float_t > GetMulticlassTrainingEfficiency(std::vector< std::vector< Float_t > > &purity)
DataSetInfo & fDataSetInfo
! the data set information (sometimes needed)
Definition MethodBase.h:544
Bool_t fHasMVAPdfs
MVA Pdfs are created for this classifier.
Definition MethodBase.h:617
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:133
void SetBaseDir(TDirectory *methodDir)
Definition MethodBase.h:347
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:441
TSpline1 * fSplRefB
Definition MethodBase.h:640
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
Definition MethodBase.h:368
Double_t GetMvaValue(Double_t *errLower=nullptr, Double_t *errUpper=nullptr) override=0
Bool_t IsSilentFile() const
Definition MethodBase.h:353
Types::EMVA GetMethodType() const
Definition MethodBase.h:307
void AddTargetsXMLTo(void *parent) const
write target info to XML
Results * fResults
Definition MethodBase.h:667
void MakeClassSpecific(std::ostream &, const TString &="") const override
Definition MethodBase.h:457
Double_t fXmin
minimum (signal and background)
Definition MethodBase.h:602
PDF * fDefaultPDF
default PDF definitions
Definition MethodBase.h:581
void ReadTargetsFromXML(void *tarnode)
read target info from XML
void SetFile(TFile *file)
Definition MethodBase.h:349
void ProcessBaseOptions()
the option string is decoded, for available options see "DeclareOptions"
virtual void Reset()
Definition MethodBase.h:164
UInt_t fROOTTrainingVersion
Definition MethodBase.h:556
void ReadWeightsFromStream(std::istream &) override=0
void ReadStateFromXML(void *parent)
Double_t GetSignalReferenceCutOrientation() const
Definition MethodBase.h:335
void SetSignalReferenceCut(Double_t cut)
Definition MethodBase.h:338
virtual std::vector< Float_t > GetAllRegressionValues()
Get al regression values in one call.
std::vector< TString > * fInputVars
Definition MethodBase.h:525
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
Double_t fSignalReferenceCut
Definition MethodBase.h:546
Double_t GetTestTime() const
Definition MethodBase.h:137
Double_t fMeanB
mean (background)
Definition MethodBase.h:599
const TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true) const
Definition MethodBase.h:372
void SetSignalReferenceCutOrientation(Double_t cutOrientation)
Definition MethodBase.h:339
TDirectory * fBaseDir
Definition MethodBase.h:562
Bool_t fIgnoreNegWeightsInTraining
If true, events with negative weights are not used in training.
Definition MethodBase.h:619
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:324
ECutOrientation GetCutOrientation() const
Definition MethodBase.h:489
Ranking * fRanking
Definition MethodBase.h:524
TrainingHistory fTrainHistory
Definition MethodBase.h:399
void SetMethodBaseDir(TDirectory *methodDir)
Definition MethodBase.h:348
virtual void AddClassifierOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
PDF * fMVAPdfB
background MVA PDF
Definition MethodBase.h:583
DataSet * Data() const
Definition MethodBase.h:383
void AddSpectatorsXMLTo(void *parent) const
write spectator info to XML
void SetModelPersistence(Bool_t status)
Definition MethodBase.h:356
TString fWeightFile
weight file name
Definition MethodBase.h:575
Bool_t IsNormalised() const
Definition MethodBase.h:433
const TString & GetInternalVarName(Int_t ivar) const
Definition MethodBase.h:447
const Event * GetTrainingEvent(Long64_t ievt) const
Definition MethodBase.h:708
Double_t GetSignalReferenceCut() const
Definition MethodBase.h:334
TSpline1 * fSplTrainRefS
Definition MethodBase.h:642
TSpline1 * fSplRefS
Definition MethodBase.h:639
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:636
Double_t GetRMS(Int_t ivar) const
Definition MethodBase.h:329
const char * GetInputTitle(Int_t i) const
Definition MethodBase.h:325
const TString & GetOriginalVarName(Int_t ivar) const
Definition MethodBase.h:448
virtual void AddMulticlassOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Bool_t IsConstructedFromWeightFile() const
Definition MethodBase.h:477
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:58
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:138
const char * Data() const
Definition TString.h:386
A TTree represents a columnar dataset.
Definition TTree.h:89
create variable transformations