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

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