Logo ROOT  
Reference Guide
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  * Web : http://tmva.sourceforge.net *
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  * (http://tmva.sourceforge.net/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 
61 class TCanvas;
62 class TDirectory;
63 class TFile;
64 class TGraph;
65 class TH1F;
66 class TMultiGraph;
67 class TTree;
68 namespace 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  // contructor 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 0; }
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 hepl 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 corelations
216  Bool_t fROC; //! enable to calculate ROC values
217  Bool_t fSilentFile; //! used in contructor wihtout 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
TMVA::Factory::TrainAllMethodsForRegression
void TrainAllMethodsForRegression(void)
Definition: Factory.h:116
TMVA::Factory::fModelPersistence
Bool_t fModelPersistence
the training type
Definition: Factory.h:222
TMVA::Factory::EvaluateImportanceRandom
TH1F * EvaluateImportanceRandom(DataLoader *loader, UInt_t nseeds, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition: Factory.cxx:2473
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMVA::Factory::fVerboseLevel
TString fVerboseLevel
verbose mode
Definition: Factory.h:214
TMVA::Configurable
Definition: Configurable.h:45
TMVA::Factory::fJobName
TString fJobName
used in contructor wihtout file
Definition: Factory.h:219
TMVA::Factory::MakeClass
virtual void MakeClass(const TString &datasetname, const TString &methodTitle="") const
Definition: Factory.cxx:1305
TMVA::Factory::PrintHelpMessage
void PrintHelpMessage(const TString &datasetname, const TString &methodTitle="") const
Print predefined help message of classifier.
Definition: Factory.cxx:1333
TMVA::Factory::OptimizeAllMethods
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
TMVA::Factory::IsSilentFile
Bool_t IsSilentFile() const
Definition: Factory.h:151
TMVA::Types::kTesting
@ kTesting
Definition: Types.h:146
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TMVA::Factory::GetROCIntegral
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
TMVA::Factory::MVector
std::vector< IMethod * > MVector
Definition: Factory.h:84
TMVA::Factory::TestAllMethods
void TestAllMethods()
Evaluates all booked methods on the testing data and adds the output to the Results in the corresponi...
Definition: Factory.cxx:1271
TMVA::Factory::GetImportance
TH1F * GetImportance(const int nbits, std::vector< Double_t > importances, std::vector< TString > varNames)
Definition: Factory.cxx:2593
TMVA::Factory::IsModelPersistence
Bool_t IsModelPersistence() const
Definition: Factory.h:152
TMVA::Factory::fgTargetFile
TFile * fgTargetFile
Definition: Factory.h:205
TMVA::Factory::fVerbose
Bool_t fVerbose
list of transformations to test
Definition: Factory.h:213
TMVA::Factory::fCorrelations
Bool_t fCorrelations
verbosity level, controls granularity of logging
Definition: Factory.h:215
TString
Basic string class.
Definition: TString.h:136
TMVA::Factory::BookMethodWeightfile
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
bool Bool_t
Definition: RtypesCore.h:63
TMVA::Factory::SetInputTreesFromEventAssignTrees
void SetInputTreesFromEventAssignTrees()
v
@ v
Definition: rootcling_impl.cxx:3643
bool
TMVA::Factory::Greetings
void Greetings()
Print welcome message.
Definition: Factory.cxx:295
TMVA::Factory::Verbose
Bool_t Verbose(void) const
Definition: Factory.h:134
TMVA::DataSetInfo
Class that contains all the data information.
Definition: DataSetInfo.h:62
TMVA::Factory::GetROC
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
TMVA::Types::EAnalysisType
EAnalysisType
Definition: Types.h:128
TMVA::Factory::TrainAllMethodsForClassification
void TrainAllMethodsForClassification(void)
Definition: Factory.h:115
TMVA::Factory::BookMethod
MethodBase * BookMethod(DataLoader *, TMVA::Types::EMVA, TString, TString, TMVA::Types::EMVA, TString)
Definition: Factory.h:102
TMVA::Types::ETreeType
ETreeType
Definition: Types.h:144
TMVA::Factory::GetROCCurveAsMultiGraph
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
TMVA::Factory::DeleteAllMethods
void DeleteAllMethods(void)
Delete methods.
Definition: Factory.cxx:324
TMVA::Factory::WriteDataInformation
void WriteDataInformation(DataSetInfo &fDataSetInfo)
Definition: Factory.cxx:602
TMVA::Factory::GetROCCurve
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
TMVA::Factory::EvaluateImportance
TH1F * EvaluateImportance(DataLoader *loader, VIType vitype, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Evaluate Variable Importance.
Definition: Factory.cxx:2217
TCut.h
TMVA::Factory::fOptions
TString fOptions
list of transformations on default DataSet
Definition: Factory.h:211
TMVA::Factory::Factory
Factory(TString theJobName, TFile *theTargetFile, TString theOption="")
Standard constructor.
Definition: Factory.cxx:113
TMVA::Factory
This is the main MVA steering class.
Definition: Factory.h:80
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TMVA::MethodBase
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
Types.h
Configurable.h
TMVA::Factory::fAnalysisType
Types::EAnalysisType fAnalysisType
jobname, used as extension in weight file names
Definition: Factory.h:221
TMVA::Factory::EvaluateImportanceAll
TH1F * EvaluateImportanceAll(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition: Factory.cxx:2246
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TMVA::Factory::fMethodsMap
std::map< TString, MVector * > fMethodsMap
Definition: Factory.h:85
TMVA::IMethod
Interface for all concrete MVA method implementations.
Definition: IMethod.h:53
TMVA::Factory::GetMethod
IMethod * GetMethod(const TString &datasetname, const TString &title) const
Returns pointer to MVA that corresponds to given method title.
Definition: Factory.cxx:566
TMultiGraph
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:36
TMVA::Factory::BookMethod
MethodBase * BookMethod(DataLoader *loader, TString theMethodName, TString methodTitle, TString theOption="")
Book a classifier or regression method.
Definition: Factory.cxx:352
TMVA::Factory::~Factory
virtual ~Factory()
Destructor.
Definition: Factory.cxx:306
Double_t
double Double_t
Definition: RtypesCore.h:59
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
TMVA::Factory::fDefaultTrfs
std::vector< TMVA::VariableTransformBase * > fDefaultTrfs
ROOT output file.
Definition: Factory.h:208
TMVA::Factory::RootBaseDir
TDirectory * RootBaseDir()
Definition: Factory.h:149
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TMVA::Factory::EvaluateAllVariables
void EvaluateAllVariables(DataLoader *loader, TString options="")
Iterates over all MVA input variables and evaluates them.
Definition: Factory.cxx:1360
TMVA::Factory::fSilentFile
Bool_t fSilentFile
enable to calculate ROC values
Definition: Factory.h:217
TMVA::Types::EMVA
EMVA
Definition: Types.h:78
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
TMVA::Factory::HasMethod
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
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:45
TMVA::Factory::OptimizeAllMethodsForRegression
void OptimizeAllMethodsForRegression(TString fomType="ROCIntegral", TString fitType="FitGA")
Definition: Factory.h:111
TMVA::Factory::fTransformations
TString fTransformations
option string given by construction (presently only "V")
Definition: Factory.h:212
TMVA::Factory::fROC
Bool_t fROC
enable to calculate corelations
Definition: Factory.h:216
TMVA::Factory::OptimizeAllMethodsForClassification
void OptimizeAllMethodsForClassification(TString fomType="ROCIntegral", TString fitType="FitGA")
Definition: Factory.h:110
TMVA::Factory::EvaluateAllMethods
void EvaluateAllMethods(void)
Iterates over all MVAs that have been booked, and calls their evaluation methods.
Definition: Factory.cxx:1376
type
int type
Definition: TGX11.cxx:121
TMVA::Factory::TrainAllMethods
void TrainAllMethods()
Iterates through all booked methods and calls training.
Definition: Factory.cxx:1114
TMVA::ROCCurve
Definition: ROCCurve.h:45
TMVA::Factory::EvaluateImportanceShort
TH1F * EvaluateImportanceShort(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Definition: Factory.cxx:2358
DataSet.h
TMVA::Factory::SetVerbose
void SetVerbose(Bool_t v=kTRUE)
Definition: Factory.cxx:343
TMVA::CrossValidation
Class to perform cross validation, splitting the dataloader into folds.
Definition: CrossValidation.h:124
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
TMVA::DataLoader
Definition: DataLoader.h:50