source: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h@ 7551

Last change on this file since 7551 was 7425, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.3 KB
Line 
1#ifndef MARS_MRanForestCalc
2#define MARS_MRanForestCalc
3
4#ifndef MARS_MTask
5#include "MTask.h"
6#endif
7
8#ifndef ROOT_TObjArray
9#include <TObjArray.h>
10#endif
11
12#ifndef ROOT_TArrayD
13#include <TArrayD.h>
14#endif
15
16class MDataArray;
17class MParameterD;
18class MHMatrix;
19
20class MRanForestCalc : public MTask
21{
22public:
23 enum EstimationMode_t
24 {
25 kMean,
26 kMaximum,
27 kFit
28 };
29
30private:
31 static const TString gsDefName; //! Default Name
32 static const TString gsDefTitle; //! Default Title
33 static const TString gsNameOutput; //! Default Output name
34
35 MDataArray *fData; //! Used to store the MDataChains to get the event values
36 MParameterD *fRFOut; //! Used to store result
37 MHMatrix *fTestMatrix; //! Test Matrix used in Process (together with MMatrixLoop)
38
39 TObjArray fEForests; //! List of forests read or to be written
40
41 Int_t fNumTrees; //! Training parameters
42 Int_t fNumTry; //! Training parameters
43 Int_t fNdSize; //! Training parameters
44
45 Int_t fNumObsoleteVariables; //! Training parameters
46
47 TString fFileName; // File name to forest
48 TString fNameOutput; // Name of output container
49
50 Bool_t fDebug; // Debugging of eventloop while training on/off
51
52 EstimationMode_t fEstimationMode; // Mode of estimation in case of multi random forest regression
53
54private:
55 // MTask
56 Int_t PreProcess(MParList *plist);
57 Int_t Process();
58
59 // MRanForestCalc
60 Int_t ReadForests(MParList &plist);
61
62 // MParContainer
63 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
64
65 // Train Interface
66 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver);
67
68public:
69 MRanForestCalc(const char *name=NULL, const char *title=NULL);
70 ~MRanForestCalc();
71
72 // TObject
73 void Print(Option_t *o="") const; //*MENU*
74
75 // Setter for estimation
76 void SetFileName(TString filename) { fFileName = filename; }
77 void SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
78 void SetNameOutput(TString name=gsNameOutput) { fNameOutput = name; }
79
80 // Setter for training
81 void SetNumTrees(UShort_t n=100) { fNumTrees = n; }
82 void SetNdSize(UShort_t n=5) { fNdSize = n; }
83 void SetNumTry(UShort_t n=0) { fNumTry = n; }
84 void SetDebug(Bool_t b=kTRUE) { fDebug = b; }
85
86 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
87
88 // Train Interface
89 Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid)
90 {
91 // One yes/no-classification forest is trained for each bin
92 return Train(n, grid, 0);
93 }
94 Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD())
95 {
96 // w/o Grid: Last Column contains classifier
97 // w/ Grid: Last Column will be converted by grid into classifier
98 return Train(n, grid, grid.GetSize()==0 ? 2 : 1);
99 }
100 Int_t TrainRegression(const MHMatrix &n)
101 {
102 // Use last column for regression
103 return Train(n, TArrayD(), 3);
104 }
105
106 // Test Interface
107 void SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
108 void InitMapping(MHMatrix *m=0) { fTestMatrix=m; }
109
110 ClassDef(MRanForestCalc, 1) // Task to calculate RF output and for RF training
111};
112
113#endif
Note: See TracBrowser for help on using the repository browser.