Logo ROOT  
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 <memory>
15 #include <vector>
16 
17 #include <TString.h>
18 #include <TROOT.h>
19 #include <TStopwatch.h>
20 
21 #ifndef _MSC_VER
22 #include <TProcPool.h>
23 #endif
24 
25 #include <TMVA/OptionMap.h>
26 #include <TMVA/Config.h>
27 #include <TMVA/Tools.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 #ifndef _MSC_VER
54  TProcPool fWorkers; //! procpool object
55 #endif
56  UInt_t fJobs; //! number of jobs to run some high level algorithm in parallel
57  TStopwatch fTimer; //! timer to measute the time.
58 
59  Envelope(const TString &name, DataLoader *dataloader = nullptr, TFile *file = nullptr,
60  const TString options = "");
61 
62  public:
63  /**
64  Default destructor
65  */
66  ~Envelope();
67 
68  virtual void BookMethod( TString methodname, TString methodtitle, TString options = "");
69  virtual void BookMethod( Types::EMVA method, TString methodtitle, TString options = "");
70 
71  // parse the internal option string
72  virtual void ParseOptions();
73 
75  TFile* GetFile();
76  void SetFile(TFile *file);
77  Bool_t HasMethod(TString methodname, TString methodtitle);
78 
80  void SetDataLoader(DataLoader *dalaloader);
82  void SetModelPersistence(Bool_t status=kTRUE);
83  Bool_t IsVerbose();
84  void SetVerbose(Bool_t status);
85 
86  /**
87  Virtual method to be implemented with your algorithm.
88  */
89  virtual void Evaluate() = 0;
90 
91  std::vector<OptionMap> &GetMethods();
92 
93  protected:
94  /**
95  Utility method to get TMVA::DataInputHandler reference from the DataLoader.
96  \return TMVA::DataInputHandler reference.
97  */
99 
100  /**
101  Utility method to get TMVA::DataSetInfo reference from the DataLoader.
102  \return TMVA::DataSetInfo reference.
103  */
104  DataSetInfo &GetDataLoaderDataSetInfo() { return fDataLoader->GetDataSetInfo(); }
105 
106  /**
107  Utility method to get TMVA::DataSetManager pointer from the DataLoader.
108  \return TMVA::DataSetManager pointer.
109  */
111  {
112  return fDataLoader->GetDataSetInfo().GetDataSetManager();
113  }
114 
115  /**
116  Utility method to get base dir directory from current file.
117  \return TDirectory* pointer.
118  */
119  TDirectory *RootBaseDir() { return (TDirectory *)fFile.get(); }
120 
121  void WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType);
122 
123  ClassDef(Envelope, 0);
124  };
125 }
126 
127 #endif
TMVA::Envelope::RootBaseDir
TDirectory * RootBaseDir()
Utility method to get base dir directory from current file.
Definition: Envelope.h:119
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMVA::Envelope
Abstract base class for all high level ml algorithms, you can book ml methods like BDT,...
Definition: Envelope.h:44
TMVA::Configurable
Definition: Configurable.h:45
TMVA::Envelope::GetDataLoaderDataSetManager
DataSetManager * GetDataLoaderDataSetManager()
Utility method to get TMVA::DataSetManager pointer from the DataLoader.
Definition: Envelope.h:110
TMVA::DataInputHandler
Class that contains all the data information.
Definition: DataInputHandler.h:78
TMVA::Envelope::SetModelPersistence
void SetModelPersistence(Bool_t status=kTRUE)
Method enable model persistence, then algorithms model is saved in xml or serialized files.
Definition: Envelope.cxx:143
TStopwatch.h
TMVA::Envelope::fMethods
std::vector< OptionMap > fMethods
Definition: Envelope.h:46
DataLoader.h
TMVA::Envelope::SetVerbose
void SetVerbose(Bool_t status)
Method enable print extra information in the algorithms.
Definition: Envelope.cxx:100
TMVA::Envelope::GetFile
TFile * GetFile()
Method to get the pointer to TFile object.
Definition: Envelope.cxx:78
TMVA::Envelope::fTransformations
TString fTransformations
flag for extra information
Definition: Envelope.h:51
TString
Basic string class.
Definition: TString.h:136
TString.h
bool
TROOT.h
TMVA::Envelope::GetDataLoaderDataSetInfo
DataSetInfo & GetDataLoaderDataSetInfo()
Utility method to get TMVA::DataSetInfo reference from the DataLoader.
Definition: Envelope.h:104
TMVA::DataSetInfo
Class that contains all the data information.
Definition: DataSetInfo.h:62
TMVA::Envelope::GetMethods
std::vector< OptionMap > & GetMethods()
Method get the Booked methods in a option map object.
Definition: Envelope.cxx:107
TMVA::Envelope::GetDataLoaderDataInput
DataInputHandler & GetDataLoaderDataInput()
Utility method to get TMVA::DataInputHandler reference from the DataLoader.
Definition: Envelope.h:98
TMVA::Types::EAnalysisType
EAnalysisType
Definition: Types.h:128
TMVA::Envelope::fVerbose
Bool_t fVerbose
flag to save the trained model
Definition: Envelope.h:50
TMVA::Envelope::HasMethod
Bool_t HasMethod(TString methodname, TString methodtitle)
function to check methods booked
Definition: Envelope.cxx:220
TMVA::Envelope::Envelope
Envelope(const TString &name, DataLoader *dataloader=nullptr, TFile *file=nullptr, const TString options="")
timer to measute the time.
Definition: Envelope.cxx:40
TMVA::Envelope::fSilentFile
Bool_t fSilentFile
List of transformations to test.
Definition: Envelope.h:52
TMVA::Envelope::BookMethod
virtual void BookMethod(TString methodname, TString methodtitle, TString options="")
Method to book the machine learning method to perform the algorithm.
Definition: Envelope.cxx:163
TProcPool.h
TMVA::Envelope::fJobs
UInt_t fJobs
procpool object
Definition: Envelope.h:56
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TMVA::Envelope::GetDataLoader
DataLoader * GetDataLoader()
Method to get the pointer to TMVA::DataLoader object.
Definition: Envelope.cxx:118
Config.h
unsigned int
TMVA::Envelope::ParseOptions
virtual void ParseOptions()
Method to parse the internal option string.
Definition: Envelope.cxx:182
TMVA::Envelope::IsModelPersistence
Bool_t IsModelPersistence()
Method to see if the algorithm model is saved in xml or serialized files.
Definition: Envelope.cxx:136
TMVA::Envelope::fTimer
TStopwatch fTimer
number of jobs to run some high level algorithm in parallel
Definition: Envelope.h:57
TMVA::DataSetManager
Class that contains all the data information.
Definition: DataSetManager.h:51
OptionMap.h
TMVA::Envelope::fFile
std::shared_ptr< TFile > fFile
data
Definition: Envelope.h:48
TMVA::Envelope::SetDataLoader
void SetDataLoader(DataLoader *dalaloader)
Method to set the pointer to TMVA::DataLoader object.
Definition: Envelope.cxx:126
TMVA::Envelope::IsSilentFile
Bool_t IsSilentFile()
Method to see if a file is available to save results.
Definition: Envelope.cxx:71
TMVA::Envelope::WriteDataInformation
void WriteDataInformation(TMVA::DataSetInfo &fDataSetInfo, TMVA::Types::EAnalysisType fAnalysisType)
method to save Train/Test information into the output file.
Definition: Envelope.cxx:235
ROOT::TProcessExecutor
This class provides a simple interface to execute the same task multiple times in parallel,...
Definition: TProcessExecutor.hxx:38
file
Definition: file.py:1
TMVA::Types::EMVA
EMVA
Definition: Types.h:78
TMVA::Envelope::Evaluate
virtual void Evaluate()=0
Virtual method to be implemented with your algorithm.
TStopwatch
Stopwatch class.
Definition: TStopwatch.h:28
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::Envelope::fWorkers
TProcPool fWorkers
if true dont produce file output
Definition: Envelope.h:54
name
char name[80]
Definition: TGX11.cxx:110
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:45
TMVA::Envelope::SetFile
void SetFile(TFile *file)
Method to set the pointer to TFile object, with a writable file.
Definition: Envelope.cxx:86
Tools.h
TMVA::Envelope::fModelPersistence
Bool_t fModelPersistence
file to save the results
Definition: Envelope.h:49
TMVA::Envelope::~Envelope
~Envelope()
Default destructor.
Definition: Envelope.cxx:62
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
TMVA::DataLoader
Definition: DataLoader.h:50
TMVA::Envelope::IsVerbose
Bool_t IsVerbose()
Method to see if the algorithm should print extra information.
Definition: Envelope.cxx:93
TMVA::Envelope::fDataLoader
std::shared_ptr< DataLoader > fDataLoader
Booked method information.
Definition: Envelope.h:47