Changeset 7420 for trunk/MagicSoft/Mars/mranforest
- Timestamp:
- 11/22/05 11:06:56 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/mranforest
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r7417 r7420 62 62 // Default constructor. 63 63 // 64 MRanForest::MRanForest(const char *name, const char *title) : fClassify(1), fNumTrees(100), fNumTry(0), fNdSize(1), fRanTree(NULL), fUserVal(-1) 64 MRanForest::MRanForest(const char *name, const char *title) 65 : fClassify(kTRUE), fNumTrees(100), fNumTry(0), fNdSize(1), 66 fRanTree(NULL), fRules(NULL), fMatrix(NULL), fUserVal(-1) 65 67 { 66 68 fName = name ? name : "MRanForest"; … … 125 127 { 126 128 delete fForest; 129 if (fMatrix) 130 delete fMatrix; 131 if (fRules) 132 delete fRules; 127 133 } 128 134 … … 152 158 void MRanForest::SetWeights(const TArrayF &weights) 153 159 { 154 const int n=weights.GetSize();155 fWeight.Set(n);156 160 fWeight=weights; 157 158 return;159 161 } 160 162 … … 175 177 //for(int i=0;i<n;i++) 176 178 // *fLog<<inf<<" "<<i<<") "<<fGrid[i]<<endl; 177 178 return;179 179 } 180 180 … … 227 227 } 228 228 229 /*230 Bool_t MRanForest::PreProcess(MParList *plist)231 {232 if (!fRules)233 {234 *fLog << err << dbginf << "MDataArray with rules not initialized... aborting." << endl;235 return kFALSE;236 }237 238 if (!fRules->PreProcess(plist))239 {240 *fLog << err << dbginf << "PreProcessing of MDataArray failed... aborting." << endl;241 return kFALSE;242 }243 244 return kTRUE;245 }246 */247 248 229 Double_t MRanForest::CalcHadroness() 249 230 { … … 285 266 // access matrix, copy last column (target) preliminarily 286 267 // into fHadTrue 268 if (fMatrix) 269 delete fMatrix; 287 270 fMatrix = new TMatrix(mat->GetM()); 288 271 … … 337 320 } 338 321 322 if (fRules) 323 delete fRules; 339 324 fRules = new MDataArray(); 340 325 fRules->Reset(); -
trunk/MagicSoft/Mars/mranforest/MRanForest.h
r7396 r7420 30 30 { 31 31 private: 32 Int_t fClassify;32 Bool_t fClassify; 33 33 34 34 Int_t fNumTrees; // Number of trees … … 83 83 void SetNdSize(Int_t n); 84 84 85 void SetClassify( Int_t n){ fClassify=n; }85 void SetClassify(Bool_t n){ fClassify=n; } 86 86 void PrepareClasses(); 87 87 -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r7413 r7420 79 79 } 80 80 81 // -------------------------------------------------------------------------- 82 // 83 // ver=0: One yes/no-classification forest is trained for each bin. 84 // the yes/no classification is done using the grid 85 // ver=1: One classification forest is trained. The last column contains a 86 // value which is turned into a classifier by rf itself using the grid 87 // ver=2: One classification forest is trained. The last column already contains 88 // the classifier 89 // ver=3: A regression forest is trained. The last column contains the 90 // classifier 91 // 81 92 Int_t MRanForestCalc::Train(const MHMatrix &matrixtrain, const TArrayD &grid, Int_t ver) 82 93 { … … 117 128 118 129 MDataArray rules(usedrules); 119 rules.AddEntry(ver< 2?"Classification":dcol[ncols-1].GetRule());130 rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule()); 120 131 121 132 // prepare matrix for current energy bin … … 133 144 switch (ver) 134 145 { 135 case 0: // Replace Energy Grid byclassification146 case 0: // Replace last column by a classification 136 147 { 137 148 Int_t irows=0; … … 158 169 break; 159 170 160 case 1: // Use Energy as classifier171 case 1: // Use last column as classifier or for regression 161 172 case 2: 173 case 3: 162 174 for (Int_t j=0; j<nrows; j++) 163 175 mat(j, ncols-nobs) = matrixtrain.GetM()(j,ncols-1); … … 176 188 rf.SetNumTry(fNumTry); 177 189 rf.SetNdSize(fNdSize); 178 rf.SetClassify(ver< 2 ? 1 : 0);190 rf.SetClassify(ver<3 ? kTRUE : kFALSE); 179 191 if (ver==1) 180 192 rf.SetGrid(grid); -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r7413 r7420 65 65 66 66 // Train Interface 67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver =2);67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver); 68 68 69 69 public: … … 87 87 Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid) 88 88 { 89 // One yes/no-classification forest is trained for each bin 89 90 return Train(n, grid, 0); 90 91 } 91 92 Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD()) 92 93 { 94 // w/o Grid: Last Column contains classifier 95 // w/ Grid: Last Column will be converted by grid into classifier 93 96 return Train(n, grid, grid.GetSize()==0 ? 2 : 1); 97 } 98 Int_t TrainRegression(const MHMatrix &n) 99 { 100 // Use last column for regression 101 return Train(n, TArrayD(), 3); 94 102 } 95 103 -
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r7396 r7420 49 49 // Default constructor. 50 50 // 51 MRanTree::MRanTree(const char *name, const char *title):fClassify( 1),fNdSize(0), fNumTry(3)51 MRanTree::MRanTree(const char *name, const char *title):fClassify(kTRUE),fNdSize(0), fNumTry(3) 52 52 { 53 53 -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r7413 r7420 22 22 { 23 23 private: 24 Int_t fClassify; 24 Bool_t fClassify; 25 25 26 Int_t fNdSize; 26 27 Int_t fNumTry; … … 88 89 Float_t GetGiniDec(Int_t i) const { return fGiniDec.At(i); } 89 90 90 void SetClassify( Int_t n){ fClassify=n; }91 void SetClassify(Bool_t n){ fClassify=n; } 91 92 92 93 // functions used in tree growing process
Note:
See TracChangeset
for help on using the changeset viewer.