Changeset 7697
- Timestamp:
- 05/05/06 10:53:03 (19 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r7695 r7697 46 46 - removed the obsolste dereferencing from the call to FindBestSplit 47 47 - added some const-qualifiers in funciton calls 48 - make a copy of tclasspop in BuildTree to be able to give the 49 array as a const qualified reference. It is not used at any other 50 place 51 - in TreeHad first get the pointers to the vector with the data to 52 get rid of the range check done by root. This has also the advantage 53 that all TreeHad member function can be unified into a single 54 member function 48 55 49 56 * mhflux/MAlphaFitter.cc: … … 51 58 in the case of off-data. This did in no means effect the result, 52 59 just the performance. 60 61 * mhbase/MH3.cc: 62 - convert the options ToLower case first before checking 63 64 * mjtrain/MJTrainRanForest.[h,cc]: 65 - added AddPar member function 66 - added fPreTasks and fPostTasks 67 - added fEnableWeights 68 - added member functions suporting setting pre- and posttasks 69 and weights 70 71 * mtools/MTFillMatrix.h: 72 - added new member function to clear the fPreCuts, fPreTasks and 73 fPostTasks lists 53 74 54 75 -
trunk/MagicSoft/Mars/NEWS
r7682 r7697 12 12 - general: Added a missing feature in the MFilterLIst class which 13 13 prevented MFEnergySlope from working correctly in trainenergy.C 14 15 - general: Accelerated the random forest training and usage a bit 14 16 15 17 - merpp: Adapted to new raw data file format version 6 -
trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc
r7421 r7697 35 35 #include "MLogManip.h" 36 36 37 #include "MF.h" 38 #include "MParameterCalc.h" 39 37 40 #include "MStatusDisplay.h" 38 39 #include "MF.h"40 41 41 42 ClassImp(MJTrainRanForest); … … 45 46 //------------------------------------------------------------------------ 46 47 // 47 // Add a cut which is used to fill the matrix, eg "MMcEvt.f OartId<1.5"48 // (The rule is applied, n it inverted: The matrix is filled with48 // Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5" 49 // (The rule is applied, not inverted: The matrix is filled with 49 50 // the events fullfilling the condition) 50 51 // … … 52 53 { 53 54 MFilter *f = new MF(rule); 54 f->SetBit(kCanDelete); 55 Add Cut(l, f);55 f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it??? 56 Add(l, f); 56 57 } 57 58 58 59 //------------------------------------------------------------------------ 59 60 // 60 // Add a cut which is used to fill the matrix. If kCanDelete is set 61 // Add an additional parameter (MParameterCalc), eg "0.5", "MWeight" 62 // The default container name is "MWeight" 63 // 64 void MJTrainRanForest::AddPar(TList &l, const char *rule, const char *pname) 65 { 66 TString tname(pname); 67 tname += "Calc"; 68 69 MParameterCalc *par = new MParameterCalc(rule, tname); 70 par->SetNameParameter(pname); 71 // par->SetBit(kCanDelete); //FIXME!!!! MTaskList is deleting it 72 Add(l, par); 73 } 74 75 //------------------------------------------------------------------------ 76 // 77 // Add a task/cut which is used to fill the matrix. If kCanDelete is set 61 78 // MJOptimize takes the ownership. 62 79 // 63 void MJTrainRanForest::Add Cut(TList &l, MFilter*f)80 void MJTrainRanForest::Add(TList &l, MTask *f) 64 81 { 65 82 l.Add(f); -
trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h
r7552 r7697 6 6 #endif 7 7 8 class MTask; 8 9 class MFilter; 9 10 … … 12 13 protected: 13 14 Bool_t fDebug; 15 Bool_t fEnableWeights; 14 16 15 17 TList fRules; … … 18 20 TList fTrainCuts; 19 21 TList fTestCuts; 22 TList fPreTasks; 23 TList fPostTasks; 20 24 21 25 UShort_t fNumTrees; … … 26 30 27 31 void AddCut(TList &l, const char *rule); 28 void AddCut(TList &l, MFilter *f); 32 void AddPar(TList &l, const char *rule, const char *name); 33 void Add(TList &l, MTask *f); 29 34 30 35 public: 31 MJTrainRanForest() : fDebug(kFALSE) 36 MJTrainRanForest() : fDebug(kFALSE), fEnableWeights(kFALSE) 32 37 { 33 38 fNumTrees = 100; //100 … … 36 41 } 37 42 38 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 43 void AddPreTask(MTask *t) { Add(fPreTasks, t); } 44 void AddPreTask(const char *rule, 45 const char *name="MWeight") { AddPar(fPreTasks, rule, name); } 46 47 void AddPostTask(MTask *t) { Add(fPostTasks, t); } 48 void AddPostTask(const char *rule, 49 const char *name="MWeight") { AddPar(fPostTasks, rule, name); } 50 51 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 52 53 void SetWeights(const char *rule) { if (fEnableWeights) return; fEnableWeights=kTRUE; AddPostTask(rule); } 54 void SetWeights(MTask *t) { if (fEnableWeights) return; fEnableWeights=kTRUE; AddPostTask(t); } 39 55 40 56 void AddPreCut(const char *rule) { AddCut(fPreCuts, rule); } 41 void AddPreCut(MFilter *f) { Add Cut(fPreCuts, f); }57 void AddPreCut(MFilter *f) { Add(fPreCuts, (MTask*)(f)); } 42 58 43 59 void AddTrainCut(const char *rule) { AddCut(fTrainCuts, rule); } 44 void AddTrainCut(MFilter *f) { Add Cut(fTrainCuts, f); }60 void AddTrainCut(MFilter *f) { Add(fTrainCuts, (MTask*)(f)); } 45 61 46 62 void AddTestCut(const char *rule) { AddCut(fTestCuts, rule); } 47 void AddTestCut(MFilter *f) { Add Cut(fTestCuts, f); }63 void AddTestCut(MFilter *f) { Add(fTestCuts, (MTask*)(f)); } 48 64 49 void SetNumTrees(UShort_t n=100) { fNumTrees = n; }50 void SetNdSize(UShort_t n=5) { fNdSize = n; }51 void SetNumTry(UShort_t n=0) { fNumTry = n; }65 void SetNumTrees(UShort_t n=100) { fNumTrees = n; } 66 void SetNdSize(UShort_t n=5) { fNdSize = n; } 67 void SetNumTry(UShort_t n=0) { fNumTry = n; } 52 68 53 69 Int_t AddParameter(const char *rule); -
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r7693 r7697 99 99 100 100 void MRanTree::GrowTree(TMatrix *mat, const MArrayF &hadtrue, const MArrayI &idclass, 101 MArrayI &datasort, const MArrayI &datarang, MArrayF &tclasspop,101 MArrayI &datasort, const MArrayI &datarang, const MArrayF &tclasspop, 102 102 const Float_t &mean, const Float_t &square, const MArrayI &jinbag, const MArrayF &winbag, 103 103 const int nclass) … … 192 192 for (Int_t mt=0; mt<fNumTry; mt++) 193 193 { 194 const Int_t mvar= Int_t(gRandom->Rndm()*mdim);194 const Int_t mvar= gRandom->Integer(mdim); 195 195 const Int_t mn = mvar*numdata; 196 196 … … 201 201 Double_t rld=0; 202 202 203 MArrayF wl(nclass); // left node //nclass203 MArrayF wl(nclass); // left node //nclass 204 204 MArrayF wr(tclasspop); // right node//nclass 205 205 … … 212 212 213 213 // do classification, Gini index as split rule 214 rln+=u*( 2*wl[k]+u);214 rln+=u*( 2*wl[k]+u); 215 215 rrn+=u*(-2*wr[k]+u); 216 216 … … 445 445 void MRanTree::BuildTree(MArrayI &datasort,const MArrayI &datarang, const MArrayF &hadtrue, 446 446 const MArrayI &idclass, MArrayI &bestsplit, MArrayI &bestsplitnext, 447 MArrayF &tclasspop, const Float_t &tmean, const Float_t &tsquare, const MArrayF &winbag,447 const MArrayF &tclasspop, const Float_t &tmean, const Float_t &tsquare, const MArrayF &winbag, 448 448 Int_t ninbag, const int nclass) 449 449 { … … 481 481 MArrayF mean(nrnodes); 482 482 MArrayF square(nrnodes); 483 MArrayF lclasspop(tclasspop); 483 484 484 485 mean[0]=tmean; … … 502 503 503 504 for (Int_t j=0;j<nclass;j++) 504 tclasspop[j]=classpop[j*nrnodes+kbuild];505 lclasspop[j]=classpop[j*nrnodes+kbuild]; 505 506 506 507 Int_t msplit, nbest; … … 508 509 509 510 if ((this->*FindBestSplit)(datasort,datarang,hadtrue,idclass,ndstart, 510 ndend, tclasspop,mean[kbuild],square[kbuild],msplit,decsplit,511 ndend, lclasspop,mean[kbuild],square[kbuild],msplit,decsplit, 511 512 nbest,winbag,nclass)) 512 513 { … … 621 622 } 622 623 623 Double_t MRanTree::TreeHad(const TVector &event) 624 { 625 Int_t kt=0; 624 Double_t MRanTree::TreeHad(const Float_t *evt) 625 { 626 626 // to optimize on storage space node status and node class 627 627 // are coded into fBestVar: … … 631 631 // hadronness assigned to node kt = fBestSplit[kt] 632 632 633 for (Int_t k=0;k<fNumNodes;k++) 634 { 635 if (fBestVar[kt]<0) 633 // To get rid of the range check of the root classes 634 const Float_t *split = fBestSplit.GetArray(); 635 const Int_t *map1 = fTreeMap1.GetArray(); 636 const Int_t *map2 = fTreeMap2.GetArray(); 637 const Int_t *best = fBestVar.GetArray(); 638 639 Int_t kt=0; 640 for (Int_t k=0; k<fNumNodes; k++) 641 { 642 if (best[kt]<0) 636 643 break; 637 644 638 const Int_t m=fBestVar[kt]; 639 kt = event(m)<=fBestSplit[kt] ? fTreeMap1[kt] : fTreeMap2[kt]; 640 } 641 642 return fBestSplit[kt]; 645 const Int_t m=best[kt]; 646 kt = evt[m]<=split[kt] ? map1[kt] : map2[kt]; 647 } 648 649 return split[kt]; 650 } 651 652 Double_t MRanTree::TreeHad(const TVector &event) 653 { 654 return TreeHad(event.GetMatrixArray()); 643 655 } 644 656 645 657 Double_t MRanTree::TreeHad(const TMatrixRow &event) 646 658 { 647 Int_t kt=0; 648 // to optimize on storage space node status and node class 649 // are coded into fBestVar: 650 // status of node kt = TMath::Sign(1,fBestVar[kt]) 651 // class of node kt = fBestVar[kt]+2 (class defined by larger 652 // node population, actually not used) 653 // hadronness assigned to node kt = fBestSplit[kt] 654 655 for (Int_t k=0;k<fNumNodes;k++) 656 { 657 if (fBestVar[kt]<0) 658 break; 659 660 const Int_t m=fBestVar[kt]; 661 kt = event(m)<=fBestSplit[kt] ? fTreeMap1[kt] : fTreeMap2[kt]; 662 } 663 664 return fBestSplit[kt]; 659 return TreeHad(event.GetPtr()); 665 660 } 666 661 -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r7693 r7697 45 45 Int_t &, const MArrayF &, const int); //! 46 46 47 Double_t TreeHad(const Float_t *evt); 47 48 48 49 int FindBestSplitGini(const MArrayI &datasort, const MArrayI &datarang, … … 66 67 void BuildTree(MArrayI &datasort, const MArrayI &datarang, const MArrayF &hadtrue, 67 68 const MArrayI &idclass,MArrayI &bestsplit,MArrayI &bestsplitnext, 68 MArrayF &tclasspop, const Float_t &tmean, const Float_t &tsquare, const MArrayF &winbag,69 const MArrayF &tclasspop, const Float_t &tmean, const Float_t &tsquare, const MArrayF &winbag, 69 70 Int_t ninbag, const int nclass); 70 71 … … 97 98 // functions used in tree growing process 98 99 void GrowTree(TMatrix *mat, const MArrayF &hadtrue, const MArrayI &idclass, 99 MArrayI &datasort, const MArrayI &datarang, MArrayF &tclasspop,100 MArrayI &datasort, const MArrayI &datarang,const MArrayF &tclasspop, 100 101 const Float_t &mean, const Float_t &square, const MArrayI &jinbag, const MArrayF &winbag, 101 102 const int nclass); -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
r7687 r7697 90 90 void AddPostTasks(const TList &list); 91 91 92 void ClearPreCuts() { fPreCuts.Clear(); } 93 void ClearPreTasks() { fPreTasks.Clear(); } 94 void ClearPostTasks() { fPostTasks.Clear(); } 95 92 96 Bool_t Process(const MParList &plist=MParList()); 93 97 Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
Note:
See TracChangeset
for help on using the changeset viewer.