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

Last change on this file since 8339 was 7687, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.5 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 Bool_t fLastDataColumnHasWeights; //! Training parameters
47
48 TString fFileName; // File name to forest
49 TString fNameOutput; // Name of output container
50
51 Bool_t fDebug; // Debugging of eventloop while training on/off
52
53 EstimationMode_t fEstimationMode; // Mode of estimation in case of multi random forest regression
54
55private:
56 // MTask
57 Int_t PreProcess(MParList *plist);
58 Int_t Process();
59
60 // MRanForestCalc
61 Int_t ReadForests(MParList &plist);
62
63 // MParContainer
64 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
65
66 // Train Interface
67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver);
68
69public:
70 MRanForestCalc(const char *name=NULL, const char *title=NULL);
71 ~MRanForestCalc();
72
73 // TObject
74 void Print(Option_t *o="") const; //*MENU*
75
76 // Setter for estimation
77 void SetFileName(TString filename) { fFileName = filename; }
78 void SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; }
79 void SetNameOutput(TString name=gsNameOutput) { fNameOutput = name; }
80
81 // Setter for training
82 void SetNumTrees(UShort_t n=100) { fNumTrees = n; }
83 void SetNdSize(UShort_t n=5) { fNdSize = n; }
84 void SetNumTry(UShort_t n=0) { fNumTry = n; }
85 void SetDebug(Bool_t b=kTRUE) { fDebug = b; }
86
87 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
88 void SetLastDataColumnHasWeights(Bool_t b=kTRUE) { fLastDataColumnHasWeights = b; }
89
90 // Train Interface
91 Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid)
92 {
93 // One yes/no-classification forest is trained for each bin
94 return Train(n, grid, 0);
95 }
96 Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD())
97 {
98 // w/o Grid: Last Column contains classifier
99 // w/ Grid: Last Column will be converted by grid into classifier
100 return Train(n, grid, grid.GetSize()==0 ? 2 : 1);
101 }
102 Int_t TrainRegression(const MHMatrix &n)
103 {
104 // Use last column for regression
105 return Train(n, TArrayD(), 3);
106 }
107
108 // Test Interface
109 void SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
110 void InitMapping(MHMatrix *m=0) { fTestMatrix=m; }
111
112 ClassDef(MRanForestCalc, 1) // Task to calculate RF output and for RF training
113};
114
115#endif
Note: See TracBrowser for help on using the repository browser.