Changeset 7693 for trunk/MagicSoft/Mars/mranforest/MRanTree.cc
- Timestamp:
- 05/05/06 07:46:50 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r7420 r7693 38 38 #include <TRandom.h> 39 39 40 #include "MArrayI.h" 41 #include "MArrayF.h" 42 40 43 #include "MLog.h" 41 44 #include "MLogManip.h" … … 95 98 } 96 99 97 void MRanTree::GrowTree(TMatrix *mat, const TArrayF &hadtrue, const TArrayI &idclass,98 TArrayI &datasort, const TArrayI &datarang, TArrayF &tclasspop,99 float &mean, float &square, TArrayI &jinbag, const TArrayF &winbag,100 void MRanTree::GrowTree(TMatrix *mat, const MArrayF &hadtrue, const MArrayI &idclass, 101 MArrayI &datasort, const MArrayI &datarang, MArrayF &tclasspop, 102 const Float_t &mean, const Float_t &square, const MArrayI &jinbag, const MArrayF &winbag, 100 103 const int nclass) 101 104 { … … 110 113 for (Int_t n=0;n<numdata;n++) if(jinbag[n]==1) ninbag++; 111 114 112 TArrayI bestsplit(nrnodes); bestsplit.Reset(0);113 TArrayI bestsplitnext(nrnodes); bestsplitnext.Reset(0);114 115 fBestVar.Set(nrnodes); fBestVar.Reset( 0);116 fTreeMap1.Set(nrnodes); fTreeMap1.Reset( 0);117 fTreeMap2.Set(nrnodes); fTreeMap2.Reset( 0);118 fBestSplit.Set(nrnodes); fBestSplit.Reset( 0);119 fGiniDec.Set(numdim); fGiniDec.Reset( 0);115 MArrayI bestsplit(nrnodes); 116 MArrayI bestsplitnext(nrnodes); 117 118 fBestVar.Set(nrnodes); fBestVar.Reset(); 119 fTreeMap1.Set(nrnodes); fTreeMap1.Reset(); 120 fTreeMap2.Set(nrnodes); fTreeMap2.Reset(); 121 fBestSplit.Set(nrnodes); fBestSplit.Reset(); 122 fGiniDec.Set(numdim); fGiniDec.Reset(); 120 123 121 124 … … 139 142 const Int_t &msp =fBestVar[k]; 140 143 141 fBestSplit[k] = (*mat)(bsp, msp); 142 fBestSplit[k] += (*mat)(bspn,msp); 143 fBestSplit[k] /= 2.; 144 fBestSplit[k] = ((*mat)(bsp, msp)+(*mat)(bspn,msp))/2; 144 145 } 145 146 … … 151 152 } 152 153 153 int MRanTree::FindBestSplitGini(const TArrayI &datasort,const TArrayI &datarang,154 const TArrayF &hadtrue,const TArrayI &idclass,155 Int_t ndstart,Int_t ndend, TArrayF &tclasspop,156 float &mean, float &square, Int_t &msplit,157 Float_t &decsplit,Int_t &nbest, const TArrayF &winbag,154 int MRanTree::FindBestSplitGini(const MArrayI &datasort,const MArrayI &datarang, 155 const MArrayF &hadtrue,const MArrayI &idclass, 156 Int_t ndstart,Int_t ndend, const MArrayF &tclasspop, 157 const Float_t &mean, const Float_t &square, Int_t &msplit, 158 Float_t &decsplit,Int_t &nbest, const MArrayF &winbag, 158 159 const int nclass) 159 160 { … … 161 162 const Int_t numdata = (nrnodes-1)/2; 162 163 const Int_t mdim = fGiniDec.GetSize(); 163 164 TArrayF wr(nclass); wr.Reset(0);// right node165 164 166 165 // For the best split, msplit is the index of the variable (e.g Hillas par., … … 202 201 Double_t rld=0; 203 202 204 TArrayF wl(nclass); wl.Reset(0.);// left node //nclass205 wr = tclasspop;203 MArrayF wl(nclass); // left node //nclass 204 MArrayF wr(tclasspop); // right node//nclass 206 205 207 206 Double_t critvar=-1.0e20; … … 230 229 const Double_t crit=(rln/rld)+(rrn/rrd); 231 230 232 233 231 if (crit<=critvar) continue; 234 232 … … 249 247 } 250 248 251 int MRanTree::FindBestSplitSigma(const TArrayI &datasort,const TArrayI &datarang,252 const TArrayF &hadtrue, const TArrayI &idclass,253 Int_t ndstart,Int_t ndend, TArrayF &tclasspop,254 float &mean, float &square, Int_t &msplit,255 Float_t &decsplit,Int_t &nbest, const TArrayF &winbag,249 int MRanTree::FindBestSplitSigma(const MArrayI &datasort,const MArrayI &datarang, 250 const MArrayF &hadtrue, const MArrayI &idclass, 251 Int_t ndstart,Int_t ndend, const MArrayF &tclasspop, 252 const Float_t &mean, const Float_t &square, Int_t &msplit, 253 Float_t &decsplit,Int_t &nbest, const MArrayF &winbag, 256 254 const int nclass) 257 255 { … … 259 257 const Int_t numdata = (nrnodes-1)/2; 260 258 const Int_t mdim = fGiniDec.GetSize(); 261 262 float wr=0;// right node263 259 264 260 // For the best split, msplit is the index of the variable (e.g Hillas par., zenith angle ,...) … … 300 296 for (Int_t mt=0; mt<fNumTry; mt++) 301 297 { 302 const Int_t mvar= Int_t(gRandom->Rndm()*mdim);298 const Int_t mvar= gRandom->Integer(mdim); 303 299 const Int_t mn = mvar*numdata; 304 300 305 301 Double_t rrn=0, rrd=0, rln=0, rld=0; 306 Double_t esumr=0, esuml=0, e2sumr=0,e2suml=0; 307 308 esumr =mean; 309 e2sumr=square; 310 esuml =0; 311 e2suml=0; 302 303 Double_t esumr =mean; 304 Double_t e2sumr=square; 305 Double_t esuml =0; 306 Double_t e2suml=0; 312 307 313 308 float wl=0.;// left node 314 wr = tclasspop[0];309 float wr=tclasspop[0]; // right node 315 310 316 311 Double_t critvar=critmin; … … 400 395 } 401 396 402 void MRanTree::MoveData( TArrayI &datasort,Int_t ndstart, Int_t ndend,403 TArrayI &idmove,TArrayI &ncase,Int_t msplit,397 void MRanTree::MoveData(MArrayI &datasort,Int_t ndstart, Int_t ndend, 398 MArrayI &idmove,MArrayI &ncase,Int_t msplit, 404 399 Int_t nbest,Int_t &ndendl) 405 400 { … … 410 405 const Int_t mdim = fGiniDec.GetSize(); 411 406 412 TArrayI tdatasort(numdata); tdatasort.Reset(0);407 MArrayI tdatasort(numdata); 413 408 414 409 // compute idmove = indicator of case nos. going left … … 448 443 } 449 444 450 void MRanTree::BuildTree( TArrayI &datasort,const TArrayI &datarang, const TArrayF &hadtrue,451 const TArrayI &idclass, TArrayI &bestsplit, TArrayI &bestsplitnext,452 TArrayF &tclasspop, float &tmean, float &tsquare, const TArrayF &winbag,445 void MRanTree::BuildTree(MArrayI &datasort,const MArrayI &datarang, const MArrayF &hadtrue, 446 const MArrayI &idclass, MArrayI &bestsplit, MArrayI &bestsplitnext, 447 MArrayF &tclasspop, const Float_t &tmean, const Float_t &tsquare, const MArrayF &winbag, 453 448 Int_t ninbag, const int nclass) 454 449 { … … 470 465 const Int_t numdata = (nrnodes-1)/2; 471 466 472 TArrayI nodepop(nrnodes); nodepop.Reset(0);473 TArrayI nodestart(nrnodes); nodestart.Reset(0);474 TArrayI parent(nrnodes); parent.Reset(0);475 476 TArrayI ncase(numdata); ncase.Reset(0);477 TArrayI idmove(numdata); idmove.Reset(0);478 TArrayI iv(mdim); iv.Reset(0);479 480 TArrayF classpop(nrnodes*nclass); classpop.Reset(0.);//nclass481 TArrayI nodestatus(nrnodes); nodestatus.Reset(0);467 MArrayI nodepop(nrnodes); 468 MArrayI nodestart(nrnodes); 469 MArrayI parent(nrnodes); 470 471 MArrayI ncase(numdata); 472 MArrayI idmove(numdata); 473 MArrayI iv(mdim); 474 475 MArrayF classpop(nrnodes*nclass);//nclass 476 MArrayI nodestatus(nrnodes); 482 477 483 478 for (Int_t j=0;j<nclass;j++) 484 479 classpop[j*nrnodes+0]=tclasspop[j]; 485 480 486 TArrayF mean(nrnodes); mean.Reset(0.);487 TArrayF square(nrnodes); square.Reset(0.);481 MArrayF mean(nrnodes); 482 MArrayF square(nrnodes); 488 483 489 484 mean[0]=tmean; … … 509 504 tclasspop[j]=classpop[j*nrnodes+kbuild]; 510 505 511 tmean=mean[kbuild];512 tsquare=square[kbuild];513 514 506 Int_t msplit, nbest; 515 507 Float_t decsplit=0; 516 508 517 if (( *this.*FindBestSplit)(datasort,datarang,hadtrue,idclass,ndstart,518 ndend, tclasspop, tmean, tsquare,msplit,decsplit,509 if ((this->*FindBestSplit)(datasort,datarang,hadtrue,idclass,ndstart, 510 ndend, tclasspop,mean[kbuild],square[kbuild],msplit,decsplit, 519 511 nbest,winbag,nclass)) 520 512 {
Note:
See TracChangeset
for help on using the changeset viewer.