Changeset 7687 for trunk/MagicSoft
- Timestamp:
- 05/03/06 14:13:48 (19 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r7686 r7687 46 46 * mraw/MRawRunHeader.cc: 47 47 - removed an obsolete Print() which enetered for debugging 48 49 * mimage/MHNewImagePar.cc: 50 - the plots for CocCOG and ConcCore had the same color... fixed 51 52 * mranforest/MRanForestCalc.[h,cc]: 53 - allow to set weights for each event 54 55 * mtools/MTFillMatrix.[h,cc]: 56 - implemented the possibility to set pre- and post-tasks 57 executed in the eventloop 58 48 59 49 60 -
trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc
r7599 r7687 362 362 fHistUsedPix.SetLineColor(kCyan); 363 363 fHistConc1.SetLineColor(kMagenta); 364 fHistConcCOG.SetLineColor(kCyan); 364 fHistConc.SetLineColor(kCyan); 365 fHistConcCOG.SetLineColor(kMagenta); 365 366 fHistConcCore.SetLineColor(kCyan); 366 fHistConc.SetLineColor(kCyan);367 367 fHistCoreArea.SetLineColor(kMagenta); 368 368 fHistUsedArea.SetLineColor(kCyan); -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r7425 r7687 63 63 : fData(0), fRFOut(0), fTestMatrix(0), 64 64 fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1), 65 fLastDataColumnHasWeights(kFALSE), 65 66 fNameOutput(gsNameOutput), fDebug(kFALSE), fEstimationMode(kMean) 66 67 { … … 116 117 } 117 118 118 const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns 119 // The number of columns which have to be removed for the training 120 // The last data column may contain weight which also have to be removed 121 const Int_t nobs = fNumObsoleteVariables + (fLastDataColumnHasWeights?1:0); // Number of obsolete columns 119 122 120 123 const MDataArray &dcol = *matrixtrain.GetColumns(); 121 124 125 // Make a copy of the rules for accessing the train-data 122 126 MDataArray usedrules; 123 127 for (Int_t i=0; i<ncols; i++) … … 127 131 *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl; 128 132 133 // In the case of regression store the rule to be regessed in the 134 // last entry of your rules 129 135 MDataArray rules(usedrules); 130 136 rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule()); 131 137 132 // prepare matrix for current energy bin138 // prepare train-matrix finally used 133 139 TMatrix mat(matrixtrain.GetM()); 134 140 135 // last column must be removed (true energy col.)141 // Resize it such that the obsolete columns are removed 136 142 mat.ResizeTo(nrows, ncols-nobs+1); 137 143 … … 139 145 gLog.SetNullOutput(kTRUE); 140 146 147 // In the case one independant RF is trained for each bin (e.g. 148 // energy-bin) train all of them 141 149 const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1; 142 150 for (Int_t ie=0; ie<nbins; ie++) 143 151 { 152 // In the case weights should be used initialize the 153 // corresponding array 154 TArrayF weights(nrows); 155 if (fLastDataColumnHasWeights) 156 for (Int_t j=0; j<nrows; j++) 157 { 158 weights[j] = matrixtrain.GetM()(j, ncols-nobs); 159 if (j%100==0) 160 cout << weights[j] << " "; 161 } 162 163 // Setup the matrix such that the last comlumn contains 164 // the classifier or the regeression target value 144 165 switch (ver) 145 166 { 146 case 0: // Replace last column by a classification 167 case 0: // Replace last column by a classification which is 1 in 168 // the case the event belongs to this bin, 0 otherwise 147 169 { 148 170 Int_t irows=0; 149 171 for (Int_t j=0; j<nrows; j++) 150 172 { 151 const Double_t energy= matrixtrain.GetM()(j,ncols-1);152 const Bool_t inside = energy>grid[ie] && energy<=grid[ie+1];173 const Double_t value = matrixtrain.GetM()(j,ncols-1); 174 const Bool_t inside = value>grid[ie] && value<=grid[ie+1]; 153 175 154 176 mat(j, ncols-nobs) = inside ? 1 : 0; … … 162 184 *fLog << inf << "Training RF for"; 163 185 164 *fLog << " energybin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;186 *fLog << " bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl; 165 187 166 188 if (irows==0) … … 191 213 if (ver==1) 192 214 rf.SetGrid(grid); 215 if (fLastDataColumnHasWeights) 216 rf.SetWeights(weights); 193 217 194 218 plist.AddToList(&rf); -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r7425 r7687 44 44 45 45 Int_t fNumObsoleteVariables; //! Training parameters 46 Bool_t fLastDataColumnHasWeights; //! Training parameters 46 47 47 48 TString fFileName; // File name to forest … … 84 85 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 85 86 86 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; } 87 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; } 88 void SetLastDataColumnHasWeights(Bool_t b=kTRUE) { fLastDataColumnHasWeights = b; } 87 89 88 90 // Train Interface -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
r7642 r7687 183 183 //------------------------------------------------------------------------ 184 184 // 185 // Function serving AddPreCuts, AddPreTasks and AddPostTasks 186 // 187 void MTFillMatrix::Add(const TList &src, const TClass *cls, TList &dest) 188 { 189 TIter Next(&src); 190 TObject *obj=0; 191 while ((obj=Next())) 192 if (obj->InheritsFrom(cls)) 193 dest.Add(obj); 194 } 195 196 //------------------------------------------------------------------------ 197 // 185 198 // Add a cut which is used to fill the matrix, eg "MMcEvt.fOartId<1.5" 186 199 // (The rule is applied, nit inverted: The matrix is filled with … … 211 224 void MTFillMatrix::AddPreCuts(const TList &list) 212 225 { 213 TIter Next(&list); 214 TObject *obj=0; 215 while ((obj=Next())) 216 if (obj->InheritsFrom(MFilter::Class())) 217 fPreCuts.Add(obj); 226 Add(list, MFilter::Class(), fPreCuts); 227 } 228 229 //------------------------------------------------------------------------ 230 // 231 // Add a task which is executed before the precuts. If kCanDelete is set 232 // MJOptimize takes the ownership. 233 // 234 void MTFillMatrix::AddPreTask(MTask *t) 235 { 236 fPreTasks.Add(t); 237 } 238 239 //------------------------------------------------------------------------ 240 // 241 // Add all entries deriving from MTask from list to PreTasks. 242 // The ownership is not affected. 243 // 244 void MTFillMatrix::AddPreTasks(const TList &list) 245 { 246 Add(list, MTask::Class(), fPreTasks); 247 } 248 249 //------------------------------------------------------------------------ 250 // 251 // Add a task which is executed after the precuts. If kCanDelete is set 252 // MJOptimize takes the ownership. 253 // 254 void MTFillMatrix::AddPostTask(MTask *t) 255 { 256 fPostTasks.Add(t); 257 } 258 259 //------------------------------------------------------------------------ 260 // 261 // Add all entries deriving from MTask from list to PostTasks. 262 // The ownership is not affected. 263 // 264 void MTFillMatrix::AddPostTasks(const TList &list) 265 { 266 Add(list, MTask::Class(), fPostTasks); 218 267 } 219 268 … … 315 364 MFillH fill1(fDestMatrix1); 316 365 MFillH fill2(fDestMatrix2); 317 if (selector) 318 { 319 fill1.SetFilter(&split); 320 fill2.SetFilter(&invsplit); 321 } 366 fill1.SetFilter(&split); 367 fill2.SetFilter(&invsplit); 322 368 323 369 // entries in MTaskList 324 370 tlist.AddToList(fReader); // Read events 371 tlist.AddToList(fPreTasks); // PreTasks 325 372 if (fPreCuts.GetEntries()>0) 326 373 tlist.AddToList(&cont0); // PreCuts … … 328 375 tlist.AddToList(&cont); // select a sample of events 329 376 tlist.AddToList(&invsplit); // process invsplit (which implicitly processes split) 377 tlist.AddToList(fPostTasks); // PostTasks 330 378 if (fDestMatrix1) 331 379 tlist.AddToList(&fill1); // fill matrix 1 -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
r7413 r7687 31 31 32 32 TList fPreCuts; 33 TList fPreTasks; 34 TList fPostTasks; 35 36 void Add(const TList &src, const TClass *cls, TList &dest); 33 37 34 38 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); … … 80 84 void AddPreCuts(const TList &list); 81 85 86 void AddPreTask(MTask *t); 87 void AddPreTasks(const TList &list); 88 89 void AddPostTask(MTask *t); 90 void AddPostTasks(const TList &list); 91 82 92 Bool_t Process(const MParList &plist=MParList()); 83 93 Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
Note:
See TracChangeset
for help on using the changeset viewer.