Logo ROOT   6.14/05
Reference Guide
Envelope.h
Go to the documentation of this file.
1 // @(#)root/tmva:$Id$
2 // Author: Omar Zapata 2016
3 
4 /*************************************************************************
5  * Copyright (C) 2016, Omar Andres Zapata Mesa *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 #ifndef ROOT_TMVA_Envelope
12 #define ROOT_TMVA_Envelope
13 
14 #include <sstream>
15 #include<iostream>
16 #include <memory>
17 
18 #include <TROOT.h>
19 #include <TStopwatch.h>
20 
21 #include <TProcPool.h>
22 #include <TStopwatch.h>
23 
24 #include <TMVA/OptionMap.h>
25 #include <TMVA/Config.h>
26 #include <TMVA/Tools.h>
27 #include <TMVA/DataLoader.h>
28 #include <TMVA/DataLoader.h>
29 
30 /*! \class TMVA::Envelope
31  * Abstract base class for all high level ml algorithms,
32  * you can book ml methods like BDT, MLP. SVM etc..
33  * and set a TMVA::DataLoader object to run your code
34  * in the overloaded method Evaluate.
35 \ingroup TMVA
36 
37 Base class for all machine learning algorithms
38 
39 */
40 
41 namespace TMVA {
42 
43  class Envelope:public Configurable
44  {
45  protected:
46  std::vector<OptionMap> fMethods; //! Booked method information
47  std::shared_ptr<DataLoader> fDataLoader; //! data
48  std::shared_ptr<TFile> fFile; //! file to save the results
49  Bool_t fModelPersistence; //! flag to save the trained model
50  Bool_t fVerbose; //! flag for extra information
51  TString fTransformations; //! List of transformations to test
52  Bool_t fSilentFile; //! if true dont produce file output
53  TProcPool fWorkers; //! procpool object
54  UInt_t fJobs; //! number of jobs to run some high level algorithm in parallel
55  TStopwatch fTimer; //! timer to measute the time.
56 
57  Envelope(const TString &name, DataLoader *dataloader = nullptr, TFile *file = nullptr,
58  const TString options = "");
59 
60  public:
61  /**
62  Default destructor
63  */
64  ~Envelope();
65 
66  virtual void BookMethod( TString methodname, TString methodtitle, TString options = "");
67  virtual void BookMethod( Types::EMVA method, TString methodtitle, TString options = "");
68 
69  // parse the internal option string
70  virtual void ParseOptions();
71 
73  TFile* GetFile();
74  void SetFile(TFile *file);
75  Bool_t HasMethod(TString methodname, TString methodtitle);
76 
78  void SetDataLoader(DataLoader *dalaloader);
80  void SetModelPersistence(Bool_t status=kTRUE);
81  Bool_t IsVerbose();
82  void SetVerbose(Bool_t status);
83 
84  /**
85  Virtual method to be implemented with your algorithm.
86  */
87  virtual void Evaluate() = 0;
88 
89  std::vector<OptionMap> &GetMethods();
90 
91  protected:
92  /**
93  Utility method to get TMVA::DataInputHandler reference from the DataLoader.
94  \return TMVA::DataInputHandler reference.
95  */
96  DataInputHandler &GetDataLoaderDataInput() { return *fDataLoader->fDataInputHandler; }
97 
98  /**
99  Utility method to get TMVA::DataSetInfo reference from the DataLoader.
100  \return TMVA::DataSetInfo reference.
101  */
102  DataSetInfo &GetDataLoaderDataSetInfo() { return fDataLoader->DefaultDataSetInfo(); }
103 
104  /**
105  Utility method to get TMVA::DataSetManager pointer from the DataLoader.
106  \return TMVA::DataSetManager pointer.
107  */
108  DataSetManager *GetDataLoaderDataSetManager() { return fDataLoader->fDataSetManager; }
109 
110  /**
111  Utility method to get base dir directory from current file.
112  \return TDirectory* pointer.
113  */
114  TDirectory *RootBaseDir() { return (TDirectory *)fFile.get(); }
115 
116  void WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType);
117 
118  ClassDef(Envelope, 0);
119  };
120 }
121 
122 #endif
virtual void BookMethod(TString methodname, TString methodtitle, TString options="")
Method to book the machine learning method to perform the algorithm.
Definition: Envelope.cxx:168
DataSetInfo & GetDataLoaderDataSetInfo()
Utility method to get TMVA::DataSetInfo reference from the DataLoader.
Definition: Envelope.h:102
Bool_t fVerbose
flag to save the trained model
Definition: Envelope.h:50
~Envelope()
Default destructor.
Definition: Envelope.cxx:67
void SetFile(TFile *file)
Method to set the pointer to TFile object, with a writable file.
Definition: Envelope.cxx:91
Bool_t IsModelPersistence()
Method to see if the algorithm model is saved in xml or serialized files.
Definition: Envelope.cxx:141
TString fTransformations
flag for extra information
Definition: Envelope.h:51
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
EAnalysisType
Definition: Types.h:127
void WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType)
method to save Train/Test information into the output file.
Definition: Envelope.cxx:240
Basic string class.
Definition: TString.h:131
bool Bool_t
Definition: RtypesCore.h:59
Bool_t fSilentFile
List of transformations to test.
Definition: Envelope.h:52
std::shared_ptr< TFile > fFile
data
Definition: Envelope.h:48
Bool_t IsSilentFile()
Method to see if a file is available to save results.
Definition: Envelope.cxx:76
TDirectory * RootBaseDir()
Utility method to get base dir directory from current file.
Definition: Envelope.h:114
std::vector< OptionMap > & GetMethods()
Method get the Booked methods in a option map object.
Definition: Envelope.cxx:112
DataLoader * GetDataLoader()
Method to get the pointer to TMVA::DataLoader object.
Definition: Envelope.cxx:123
Bool_t HasMethod(TString methodname, TString methodtitle)
function to check methods booked
Definition: Envelope.cxx:225
#define ClassDef(name, id)
Definition: Rtypes.h:320
Envelope(const TString &name, DataLoader *dataloader=nullptr, TFile *file=nullptr, const TString options="")
timer to measute the time.
Definition: Envelope.cxx:45
Abstract base class for all high level ml algorithms, you can book ml methods like BDT...
Definition: Envelope.h:43
Class that contains all the data information.
Definition: DataSetInfo.h:60
virtual void ParseOptions()
Method to parse the internal option string.
Definition: Envelope.cxx:187
This class provides a simple interface to execute the same task multiple times in parallel...
Class that contains all the data information.
void SetVerbose(Bool_t status)
Method enable print extra information in the algorithms.
Definition: Envelope.cxx:105
void SetDataLoader(DataLoader *dalaloader)
Method to set the pointer to TMVA::DataLoader object.
Definition: Envelope.cxx:131
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t IsVerbose()
Method to see if the algorithm should print extra information.
Definition: Envelope.cxx:98
void SetModelPersistence(Bool_t status=kTRUE)
Method enable model persistence, then algorithms model is saved in xml or serialized files...
Definition: Envelope.cxx:148
Class that contains all the data information.
Describe directory structure in memory.
Definition: TDirectory.h:34
Bool_t fModelPersistence
file to save the results
Definition: Envelope.h:49
std::shared_ptr< DataLoader > fDataLoader
Booked method information.
Definition: Envelope.h:47
UInt_t fJobs
procpool object
Definition: Envelope.h:54
Abstract ClassifierFactory template that handles arbitrary types.
TFile * GetFile()
Method to get the pointer to TFile object.
Definition: Envelope.cxx:83
Definition: file.py:1
DataSetManager * GetDataLoaderDataSetManager()
Utility method to get TMVA::DataSetManager pointer from the DataLoader.
Definition: Envelope.h:108
DataInputHandler & GetDataLoaderDataInput()
Utility method to get TMVA::DataInputHandler reference from the DataLoader.
Definition: Envelope.h:96
virtual void Evaluate()=0
Virtual method to be implemented with your algorithm.
TStopwatch fTimer
number of jobs to run some high level algorithm in parallel
Definition: Envelope.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
std::vector< OptionMap > fMethods
Definition: Envelope.h:46
TProcPool fWorkers
if true dont produce file output
Definition: Envelope.h:53
char name[80]
Definition: TGX11.cxx:109
Stopwatch class.
Definition: TStopwatch.h:28