ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PyMethodBase.h
Go to the documentation of this file.
1 // @(#)root/tmva/pymva $Id$
2 // Authors: Omar Zapata, Lorenzo Moneta, Sergei Gleyzer 2015
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : PyMethodBase *
8  * Web : http://oproject.org *
9  * *
10  * Description: *
11  * Virtual base class for all MVA method based on Python *
12  * *
13  **********************************************************************************/
14 
15 #ifndef ROOT_TMVA_PyMethodBase
16 #define ROOT_TMVA_PyMethodBase
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 // //
20 // PyMethodBase //
21 // //
22 // Virtual base class for all TMVA method based on Python/scikit-learn //
23 // //
24 ////////////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TMVA_MethodBase
27 #include "TMVA/MethodBase.h"
28 #endif
29 
30 
31 class TGraph;
32 class TTree;
33 class TDirectory;
34 class TSpline;
35 class TH1F;
36 class TH1D;
37 
38 struct _object;
39 typedef _object PyObject;
40 
41 // needed by NPY_API_VERSION
42 #include "numpy/numpyconfig.h"
43 
44 #if (NPY_API_VERSION >= 0x00000007 )
45 struct tagPyArrayObject;
46 typedef tagPyArrayObject PyArrayObject;
47 #else
48 struct PyArrayObject;
49 #endif
50 
51 
52 namespace TMVA {
53 
54  class Ranking;
55  class PDF;
56  class TSpline1;
57  class MethodCuts;
58  class MethodBoost;
59  class DataSetInfo;
60 
61  class PyMethodBase : public MethodBase {
62 
63  friend class Factory;
64  public:
65 
66  // default constructur
67  PyMethodBase(const TString &jobName,
68  Types::EMVA methodType,
69  const TString &methodTitle,
70  DataSetInfo &dsi,
71  const TString &theOption = "",
72  TDirectory *theBaseDir = 0);
73 
74  // constructor used for Testing + Application of the MVA, only (no training),
75  // using given weight file
76  PyMethodBase(Types::EMVA methodType,
77  DataSetInfo &dsi,
78  const TString &weightFile,
79  TDirectory *theBaseDir = 0);
80 
81  // default destructur
82  virtual ~PyMethodBase();
83  //basic python related function
84  static void PyInitialize();
85  static int PyIsInitialized();
86  static void PyFinalize();
87  static void PySetProgramName(TString name);
88  static TString Py_GetProgramName();
89 
90  static PyObject *Eval(TString code);//required to parse booking options from string to pyobjects
91 
92  virtual void Train() = 0;
93  // options treatment
94  virtual void Init() = 0;
95  virtual void DeclareOptions() = 0;
96  virtual void ProcessOptions() = 0;
97  // create ranking
98  virtual const Ranking *CreateRanking() = 0;
99 
100  virtual Double_t GetMvaValue(Double_t *errLower = 0, Double_t *errUpper = 0) = 0;
101 
102  Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) = 0;
103  protected:
104  // the actual "weights"
105  virtual void AddWeightsXMLTo(void *parent) const = 0;
106  virtual void ReadWeightsFromXML(void *wghtnode) = 0;
107  virtual void ReadWeightsFromStream(std::istream &) = 0; // backward compatibility
108  virtual void ReadWeightsFromStream(TFile &) {} // backward compatibility
109 
110  protected:
111  PyObject *fModule;//Module to load
112  PyObject *fClassifier;//Classifier object
113 
114  PyArrayObject *fTrainData;
115  PyArrayObject *fTrainDataWeights;//array of weights
116  PyArrayObject *fTrainDataClasses;//array with sig/bgk class
117  private:
118 
120  static PyObject *fEval;
121  protected:
122  static PyObject *fModulePickle; //Module for model persistence
123  static PyObject *fPickleDumps; //Function to dumps PyObject information into string
124  static PyObject *fPickleLoads; //Function to load PyObject information from string
125 
126  ClassDef(PyMethodBase, 0) // Virtual base class for all TMVA method
127 
128  };
129 } // namespace TMVA
130 
131 #endif
132 
133 
PyObject * fClassifier
Definition: PyMethodBase.h:112
static PyObject * fModulePickle
Definition: PyMethodBase.h:122
virtual void DeclareOptions()=0
Base class for spline implementation containing the Draw/Paint methods //.
Definition: TSpline.h:22
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
EAnalysisType
Definition: Types.h:124
virtual void Init()=0
Basic string class.
Definition: TString.h:137
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual void Train()=0
bool Bool_t
Definition: RtypesCore.h:59
static PyObject * fModuleBuiltin
Definition: PyMethodBase.h:119
PyArrayObject * fTrainDataClasses
Definition: PyMethodBase.h:116
static int PyIsInitialized()
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)=0
static void PyInitialize()
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void ReadWeightsFromStream(TFile &)
Definition: PyMethodBase.h:108
static PyObject * Eval(TString code)
PyArrayObject * fTrainDataWeights
Definition: PyMethodBase.h:115
PyMethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="", TDirectory *theBaseDir=0)
virtual void ReadWeightsFromStream(std::istream &)=0
PyObject * fModule
Definition: PyMethodBase.h:111
static PyObject * fEval
Definition: PyMethodBase.h:120
static void PyFinalize()
static TString Py_GetProgramName()
_object PyObject
Definition: PyMethodBase.h:38
virtual const Ranking * CreateRanking()=0
static void PySetProgramName(TString name)
unsigned int UInt_t
Definition: RtypesCore.h:42
PyArrayObject * fTrainData
Definition: PyMethodBase.h:114
virtual void AddWeightsXMLTo(void *parent) const =0
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
virtual void ReadWeightsFromXML(void *wghtnode)=0
double Double_t
Definition: RtypesCore.h:55
Describe directory structure in memory.
Definition: TDirectory.h:44
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
int type
Definition: TGX11.cxx:120
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void ProcessOptions()=0
static PyObject * fPickleLoads
Definition: PyMethodBase.h:124
static PyObject * fPickleDumps
Definition: PyMethodBase.h:123
virtual ~PyMethodBase()
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
A TTree object has a header with a name and a title.
Definition: TTree.h:98
_object PyObject
Definition: TPyArg.h:22