Changeset 7697 for trunk/MagicSoft/Mars/mranforest
- Timestamp:
- 05/05/06 10:53:03 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/mranforest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.