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