Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Factory.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// Updated by: Omar Zapata, Lorenzo Moneta, Sergei Gleyzer
4
5/**********************************************************************************
6 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
7 * Package: TMVA *
8 * Class : Factory *
9 * *
10 * *
11 * Description: *
12 * This is the main MVA steering class: it creates (books) all MVA methods, *
13 * and guides them through the training, testing and evaluation phases. *
14 * *
15 * Authors (alphabetical): *
16 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
17 * Joerg Stelzer <stelzer@cern.ch> - DESY, Germany *
18 * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
19 * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
20 * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
21 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
22 * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
23 * Omar Zapata <Omar.Zapata@cern.ch> - UdeA/ITM Colombia *
24 * Lorenzo Moneta <Lorenzo.Moneta@cern.ch> - CERN, Switzerland *
25 * Sergei Gleyzer <Sergei.Gleyzer@cern.ch> - U of Florida & CERN *
26 * *
27 * Copyright (c) 2005-2011: *
28 * CERN, Switzerland *
29 * U. of Victoria, Canada *
30 * MPI-K Heidelberg, Germany *
31 * U. of Bonn, Germany *
32 * UdeA/ITM, Colombia *
33 * U. of Florida, USA *
34 * *
35 * Redistribution and use in source and binary forms, with or without *
36 * modification, are permitted according to the terms listed in LICENSE *
37 * (see tmva/doc/LICENSE) *
38 **********************************************************************************/
39
40#ifndef ROOT_TMVA_Factory
41#define ROOT_TMVA_Factory
42
43//////////////////////////////////////////////////////////////////////////
44// //
45// Factory //
46// //
47// This is the main MVA steering class: it creates all MVA methods, //
48// and guides them through the training, testing and evaluation //
49// phases //
50// //
51//////////////////////////////////////////////////////////////////////////
52
53#include <vector>
54#include <map>
55#include "TCut.h"
56
57#include "TMVA/Configurable.h"
58#include "TMVA/Types.h"
59#include "TMVA/DataSet.h"
60
61class TCanvas;
62class TDirectory;
63class TFile;
64class TGraph;
65class TH1F;
66class TMultiGraph;
67class TTree;
68namespace TMVA {
69
70 class IMethod;
71 class MethodBase;
72 class DataInputHandler;
73 class DataSetInfo;
74 class DataSetManager;
75 class DataLoader;
76 class ROCCurve;
77 class VariableTransformBase;
78
79
80 class Factory : public Configurable {
81 friend class CrossValidation;
82 public:
83
84 typedef std::vector<IMethod*> MVector;
85 std::map<TString,MVector*> fMethodsMap;//all methods for every dataset with the same name
86
87 // no default constructor
88 Factory( TString theJobName, TFile* theTargetFile, TString theOption = "" );
89
90 // constructor to work without file
91 Factory( TString theJobName, TString theOption = "" );
92
93 // default destructor
94 virtual ~Factory();
95
96 // use TName::GetName and define correct name in constructor
97 //virtual const char* GetName() const { return "Factory"; }
98
99
100 MethodBase* BookMethod( DataLoader *loader, TString theMethodName, TString methodTitle, TString theOption = "" );
101 MethodBase* BookMethod( DataLoader *loader, Types::EMVA theMethod, TString methodTitle, TString theOption = "" );
103 TString /*methodTitle*/,
104 TString /*methodOption*/,
105 TMVA::Types::EMVA /*theComposite*/,
106 TString /*compositeOption = ""*/ ) { return nullptr; }
107
108 // optimize all booked methods (well, if desired by the method)
109 std::map<TString,Double_t> OptimizeAllMethods (TString fomType="ROCIntegral", TString fitType="FitGA");
110 void OptimizeAllMethodsForClassification(TString fomType="ROCIntegral", TString fitType="FitGA") { OptimizeAllMethods(fomType,fitType); }
111 void OptimizeAllMethodsForRegression (TString fomType="ROCIntegral", TString fitType="FitGA") { OptimizeAllMethods(fomType,fitType); }
112
113 // training for all booked methods
114 void TrainAllMethods ();
117
118 // testing
119 void TestAllMethods();
120
121 // performance evaluation
122 void EvaluateAllMethods( void );
123 void EvaluateAllVariables(DataLoader *loader, TString options = "" );
124
125 TH1F* EvaluateImportance( DataLoader *loader,VIType vitype, Types::EMVA theMethod, TString methodTitle, const char *theOption = "" );
126
127 // delete all methods and reset the method vector
128 void DeleteAllMethods( void );
129
130 // accessors
131 IMethod* GetMethod( const TString& datasetname, const TString& title ) const;
132 Bool_t HasMethod( const TString& datasetname, const TString& title ) const;
133
134 Bool_t Verbose( void ) const { return fVerbose; }
135 void SetVerbose( Bool_t v=kTRUE );
136
137 // make ROOT-independent C++ class for classifier response
138 // (classifier-specific implementation)
139 // If no classifier name is given, help messages for all booked
140 // classifiers are printed
141 virtual void MakeClass(const TString& datasetname , const TString& methodTitle = "" ) const;
142
143 // prints classifier-specific help messages, dedicated to
144 // help with the optimisation and configuration options tuning.
145 // If no classifier name is given, help messages for all booked
146 // classifiers are printed
147 void PrintHelpMessage(const TString& datasetname , const TString& methodTitle = "" ) const;
148
150
151 Bool_t IsSilentFile() const { return fSilentFile;}
153
154 Double_t GetROCIntegral(DataLoader *loader, TString theMethodName, UInt_t iClass = 0,
156 Double_t GetROCIntegral(TString datasetname, TString theMethodName, UInt_t iClass = 0,
158
159 // Methods to get a TGraph for an indicated method in dataset.
160 // Optional title and axis added with fLegend=kTRUE.
161 // Argument iClass used in multiclass settings, otherwise ignored.
162 TGraph *GetROCCurve(DataLoader *loader, TString theMethodName, Bool_t setTitles = kTRUE, UInt_t iClass = 0,
164 TGraph *GetROCCurve(TString datasetname, TString theMethodName, Bool_t setTitles = kTRUE, UInt_t iClass = 0,
166
167 // Methods to get a TMultiGraph for a given class and all methods in dataset.
170
171 // Draw all ROC curves of a given class for all methods in the dataset.
174
175 private:
176
177 // the beautiful greeting message
178 void Greetings();
179
180 //evaluate the simple case that is removing 1 variable at time
181 TH1F* EvaluateImportanceShort( DataLoader *loader,Types::EMVA theMethod, TString methodTitle, const char *theOption = "" );
182 //evaluate all variables combinations
183 TH1F* EvaluateImportanceAll( DataLoader *loader,Types::EMVA theMethod, TString methodTitle, const char *theOption = "" );
184 //evaluate randomly given a number of seeds
185 TH1F* EvaluateImportanceRandom( DataLoader *loader,UInt_t nseeds, Types::EMVA theMethod, TString methodTitle, const char *theOption = "" );
186
187 TH1F* GetImportance(const int nbits,std::vector<Double_t> importances,std::vector<TString> varNames);
188
189 // Helpers for public facing ROC methods
190 ROCCurve *GetROC(DataLoader *loader, TString theMethodName, UInt_t iClass = 0,
192 ROCCurve *GetROC(TString datasetname, TString theMethodName, UInt_t iClass = 0,
194
195 void WriteDataInformation(DataSetInfo& fDataSetInfo);
196
198
199 MethodBase* BookMethodWeightfile(DataLoader *dataloader, TMVA::Types::EMVA methodType, const TString &weightfile);
200
201 private:
202
203 // data members
204
205 TFile* fgTargetFile; ///<! ROOT output file
206
207
208 std::vector<TMVA::VariableTransformBase*> fDefaultTrfs; ///<! list of transformations on default DataSet
209
210 // cd to local directory
211 TString fOptions; ///<! option string given by construction (presently only "V")
212 TString fTransformations; ///<! list of transformations to test
213 Bool_t fVerbose; ///<! verbose mode
214 TString fVerboseLevel; ///<! verbosity level, controls granularity of logging
215 Bool_t fCorrelations; ///<! enable to calculate correlations
216 Bool_t fROC; ///<! enable to calculate ROC values
217 Bool_t fSilentFile; ///<! used in constructor without file
218
219 TString fJobName; ///<! jobname, used as extension in weight file names
220
221 Types::EAnalysisType fAnalysisType; ///<! the training type
222 Bool_t fModelPersistence;///<! option to save the trained model in xml file or using serialization
223
224
225 protected:
226
227 ClassDef(Factory,0); // The factory creates all MVA methods, and performs their training and testing
228 };
229
230} // namespace TMVA
231
232#endif
bool Bool_t
Definition RtypesCore.h:63
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassDef(name, id)
Definition Rtypes.h:342
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
The Canvas class.
Definition TCanvas.h:23
Describe directory structure in memory.
Definition TDirectory.h:45
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
Class to perform cross validation, splitting the dataloader into folds.
Class that contains all the data information.
Definition DataSetInfo.h:62
This is the main MVA steering class.
Definition Factory.h:80
void PrintHelpMessage(const TString &datasetname, const TString &methodTitle="") const
Print predefined help message of classifier.
Definition Factory.cxx:1333
Bool_t fSilentFile
! used in constructor without file
Definition Factory.h:217
Bool_t fCorrelations
! enable to calculate correlations
Definition Factory.h:215
Bool_t IsModelPersistence() const
Definition Factory.h:152
TString fOptions
! option string given by construction (presently only "V")
Definition Factory.h:211
std::vector< IMethod * > MVector
Definition Factory.h:84
void TrainAllMethods()
Iterates through all booked methods and calls training.
Definition Factory.cxx:1114
Bool_t Verbose(void) const
Definition Factory.h:134
void WriteDataInformation(DataSetInfo &fDataSetInfo)
Definition Factory.cxx:602
MethodBase * BookMethod(DataLoader *loader, TString theMethodName, TString methodTitle, TString theOption="")
Book a classifier or regression method.
Definition Factory.cxx:352
void TestAllMethods()
Evaluates all booked methods on the testing data and adds the output to the Results in the corresponi...
Definition Factory.cxx:1271
void TrainAllMethodsForClassification(void)
Definition Factory.h:115
Bool_t fVerbose
! verbose mode
Definition Factory.h:213
void EvaluateAllMethods(void)
Iterates over all MVAs that have been booked, and calls their evaluation methods.
Definition Factory.cxx:1376
TH1F * EvaluateImportanceRandom(DataLoader *loader, UInt_t nseeds, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition Factory.cxx:2473
TH1F * GetImportance(const int nbits, std::vector< Double_t > importances, std::vector< TString > varNames)
Definition Factory.cxx:2591
Bool_t fROC
! enable to calculate ROC values
Definition Factory.h:216
void EvaluateAllVariables(DataLoader *loader, TString options="")
Iterates over all MVA input variables and evaluates them.
Definition Factory.cxx:1360
TDirectory * RootBaseDir()
Definition Factory.h:149
TString fVerboseLevel
! verbosity level, controls granularity of logging
Definition Factory.h:214
TMultiGraph * GetROCCurveAsMultiGraph(DataLoader *loader, UInt_t iClass, Types::ETreeType type=Types::kTesting)
Generate a collection of graphs, for all methods for a given class.
Definition Factory.cxx:988
TH1F * EvaluateImportance(DataLoader *loader, VIType vitype, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Evaluate Variable Importance.
Definition Factory.cxx:2217
void OptimizeAllMethodsForRegression(TString fomType="ROCIntegral", TString fitType="FitGA")
Definition Factory.h:111
Double_t GetROCIntegral(DataLoader *loader, TString theMethodName, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Calculate the integral of the ROC curve, also known as the area under curve (AUC),...
Definition Factory.cxx:849
std::map< TString, MVector * > fMethodsMap
Definition Factory.h:85
void SetInputTreesFromEventAssignTrees()
virtual ~Factory()
Destructor.
Definition Factory.cxx:306
virtual void MakeClass(const TString &datasetname, const TString &methodTitle="") const
Definition Factory.cxx:1305
MethodBase * BookMethodWeightfile(DataLoader *dataloader, TMVA::Types::EMVA methodType, const TString &weightfile)
Adds an already constructed method to be managed by this factory.
Definition Factory.cxx:501
Bool_t fModelPersistence
! option to save the trained model in xml file or using serialization
Definition Factory.h:222
std::map< TString, Double_t > OptimizeAllMethods(TString fomType="ROCIntegral", TString fitType="FitGA")
Iterates through all booked methods and sees if they use parameter tuning and if so does just that,...
Definition Factory.cxx:701
void OptimizeAllMethodsForClassification(TString fomType="ROCIntegral", TString fitType="FitGA")
Definition Factory.h:110
ROCCurve * GetROC(DataLoader *loader, TString theMethodName, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Private method to generate a ROCCurve instance for a given method.
Definition Factory.cxx:749
Bool_t IsSilentFile() const
Definition Factory.h:151
TH1F * EvaluateImportanceShort(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition Factory.cxx:2358
Types::EAnalysisType fAnalysisType
! the training type
Definition Factory.h:221
TString fJobName
! jobname, used as extension in weight file names
Definition Factory.h:219
Bool_t HasMethod(const TString &datasetname, const TString &title) const
Checks whether a given method name is defined for a given dataset.
Definition Factory.cxx:586
TGraph * GetROCCurve(DataLoader *loader, TString theMethodName, Bool_t setTitles=kTRUE, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Argument iClass specifies the class to generate the ROC curve in a multiclass setting.
Definition Factory.cxx:912
MethodBase * BookMethod(DataLoader *, TMVA::Types::EMVA, TString, TString, TMVA::Types::EMVA, TString)
Definition Factory.h:102
void TrainAllMethodsForRegression(void)
Definition Factory.h:116
TH1F * EvaluateImportanceAll(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition Factory.cxx:2246
void SetVerbose(Bool_t v=kTRUE)
Definition Factory.cxx:343
TFile * fgTargetFile
! ROOT output file
Definition Factory.h:205
std::vector< TMVA::VariableTransformBase * > fDefaultTrfs
! list of transformations on default DataSet
Definition Factory.h:208
IMethod * GetMethod(const TString &datasetname, const TString &title) const
Returns pointer to MVA that corresponds to given method title.
Definition Factory.cxx:566
void DeleteAllMethods(void)
Delete methods.
Definition Factory.cxx:324
TString fTransformations
! list of transformations to test
Definition Factory.h:212
void Greetings()
Print welcome message.
Definition Factory.cxx:295
Interface for all concrete MVA method implementations.
Definition IMethod.h:53
Virtual base Class for all MVA method.
Definition MethodBase.h:111
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition TMultiGraph.h:34
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
create variable transformations