Changeset 2297
- Timestamp:
- 08/01/03 11:33:07 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2296 r2297 1 1 -*-*- END OF LINE -*-*- 2 2003/08/01: Thomas Bretz 3 4 * mhist/MHCamera.[h,cc]: 5 - added Fill(x, y, w) 6 - renamed GetStats to GetStatisticBox 7 8 * mhist/MHStarMap.[h,cc]: 9 - include TH2 moved to source file 10 11 * mranforest/MRanForest.[h,cc], mranforest/MRanTree.[h,cc]: 12 - do not use all the data numbers and dimensions in thousands 13 of arguments if the data is available eg from the size of an array 14 - removed obsolete variables from header 15 - many small simplifications 16 - removed some obsolete variables from functions 17 - added many const qualifiers 18 - localized many more variables 19 20 * mranforest/MRanForestFill.[h,cc]: 21 - default fNumTrees set to -1 tree (all trees) 22 23 24 2 25 2003/07/29: Thomas Bretz 3 26 -
trunk/MagicSoft/Mars/mhist/MHCamera.cc
r2274 r2297 222 222 } 223 223 224 // ------------------------------------------------------------------------ 225 // 226 // Use x and y in millimeters 227 // 228 Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w) 229 { 230 for (Int_t idx=0; idx<fNcells-2; idx++) 231 { 232 MHexagon hex((*fGeomCam)[idx]); 233 if (hex.DistanceToPrimitive(x, y)>0) 234 continue; 235 236 SetUsed(idx); 237 return Fill(idx, w); 238 } 239 return -1; 240 } 241 224 242 Stat_t MHCamera::GetMean(Int_t axis) const 225 243 { … … 839 857 } 840 858 841 TPaveStats *MHCamera::GetStat s()859 TPaveStats *MHCamera::GetStatisticBox() 842 860 { 843 861 TObject *obj = 0; … … 857 875 void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog) 858 876 { 859 TPaveStats *stats = GetStat s();877 TPaveStats *stats = GetStatisticBox(); 860 878 861 879 const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1); … … 992 1010 // ------------------------------------------------------------------------ 993 1011 // 994 // Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T995 // USE IT!996 1012 // 997 1013 Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const -
trunk/MagicSoft/Mars/mhist/MHCamera.h
r2274 r2297 45 45 void SetRange(); 46 46 47 TPaveStats *GetStat s();47 TPaveStats *GetStatisticBox(); 48 48 49 49 Int_t GetPixelIndex(Int_t px, Int_t py) const; … … 74 74 75 75 Bool_t IsUsed(Int_t idx) const { return TESTBIT(const_cast<TArrayC&>(fUsed)[idx], kIsUsed); } 76 77 Int_t Fill(Axis_t x, Axis_t y, Stat_t w); 76 78 77 79 //void AddPixContent(Int_t idx) const { AddBinContent(idx+1); } … … 146 148 147 149 //void SetStatusBar(TGStatusBar *bar) { fStatusBar = bar; } 150 151 const MGeomCam &GetGeomCam() const { return *fGeomCam; } 148 152 149 153 ClassDef(MHCamera, 1) // Displays the magic camera -
trunk/MagicSoft/Mars/mhist/MHStarMap.cc
r2173 r2297 32 32 // 33 33 ///////////////////////////////////////////////////////////////////////////// 34 35 34 #include "MHStarMap.h" 36 35 36 #include <TH2.h> 37 37 #include <TStyle.h> // gStyle 38 38 #include <TColor.h> // SetRGB -
trunk/MagicSoft/Mars/mhist/MHStarMap.h
r2043 r2297 6 6 #endif 7 7 8 #ifndef ROOT_TH2 9 #include <TH2.h> 10 #endif 11 8 class TH2F; 12 9 class MHillas; 13 10 … … 35 32 Bool_t Fill(const MParContainer *par, const Stat_t w=1); 36 33 37 TH1 *GetHistByName(const TString name) { return fStarMap; }34 TH1 *GetHistByName(const TString name) { return (TH1*)fStarMap; } 38 35 39 36 TH2F *GetHist() { return fStarMap; } -
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r2296 r2297 98 98 } 99 99 100 Int_t MRanForest::GetNumDim() const 101 { 102 return fGammas ? fGammas->GetM().GetNcols() : 0; 103 } 104 105 100 106 Double_t MRanForest::CalcHadroness(const TVector &event) 101 107 { … … 127 133 } 128 134 135 Int_t MRanForest::GetNumData() const 136 { 137 return fHadrons && fGammas ? fHadrons->GetM().GetNrows()+fGammas->GetM().GetNrows() : 0; 138 } 139 129 140 Bool_t MRanForest::SetupGrow(MHMatrix *mhad,MHMatrix *mgam) 130 141 { … … 134 145 135 146 // determine data entries and dimension of Hillas-parameter space 136 fNumHad=fHadrons->GetM().GetNrows(); 137 fNumGam=fGammas->GetM().GetNrows(); 138 fNumDim=fHadrons->GetM().GetNcols(); 139 140 if (fNumDim!=fHadrons->GetM().GetNcols()) return kFALSE; 141 142 fNumData=fNumHad+fNumGam; 147 //fNumHad=fHadrons->GetM().GetNrows(); 148 //fNumGam=fGammas->GetM().GetNrows(); 149 150 const Int_t dim = GetNumDim(); 151 152 if (dim!=fGammas->GetM().GetNcols()) 153 return kFALSE; 154 155 const Int_t numdata = GetNumData(); 143 156 144 157 // allocating and initializing arrays 145 fHadTrue.Set( fNumData);158 fHadTrue.Set(numdata); 146 159 fHadTrue.Reset(); 147 fHadEst.Set( fNumData);160 fHadEst.Set(numdata); 148 161 149 162 fPrior.Set(2); 150 163 fClassPop.Set(2); 151 fWeight.Set( fNumData);152 fNTimesOutBag.Set( fNumData);164 fWeight.Set(numdata); 165 fNTimesOutBag.Set(numdata); 153 166 fNTimesOutBag.Reset(); 154 167 155 fDataSort.Set( fNumDim*fNumData);156 fDataRang.Set( fNumDim*fNumData);168 fDataSort.Set(dim*numdata); 169 fDataRang.Set(dim*numdata); 157 170 158 171 // calculating class populations (= no. of gammas and hadrons) 159 172 fClassPop.Reset(); 160 for(Int_t n=0;n< fNumData;n++)173 for(Int_t n=0;n<numdata;n++) 161 174 fClassPop[fHadTrue[n]]++; 162 175 163 176 // setting weights taking into account priors 164 177 if (!fUsePriors) 165 {166 178 fWeight.Reset(1.); 167 }else{ 179 else 180 { 168 181 for(Int_t j=0;j<2;j++) 169 fPrior[j] *= (fClassPop[j]>=1) ? 170 Float_t(fNumData)/Float_t(fClassPop[j]):0; 171 172 for(Int_t n=0;n<fNumData;n++) 182 fPrior[j] *= (fClassPop[j]>=1) ? (Float_t)numdata/fClassPop[j]:0; 183 184 for(Int_t n=0;n<numdata;n++) 173 185 fWeight[n]=fPrior[fHadTrue[n]]; 174 186 } … … 186 198 187 199 return kTRUE; 200 } 201 202 void MRanForest::InitHadEst(Int_t from, Int_t to, const TMatrix &m, TArrayI &jinbag) 203 { 204 for (Int_t ievt=from;ievt<to;ievt++) 205 { 206 if (jinbag[ievt]>0) 207 continue; 208 fHadEst[ievt] += fRanTree->TreeHad(m, ievt-from); 209 fNTimesOutBag[ievt]++; 210 } 188 211 } 189 212 … … 206 229 } 207 230 208 TArrayF classpopw(2); 209 TArrayI jinbag(fNumData); // Initialization includes filling with 0 210 TArrayF winbag(fNumData); // Initialization includes filling with 0 231 const Int_t numdata = GetNumData(); 211 232 212 233 // bootstrap aggregating (bagging) -> sampling with replacement: … … 215 236 // {0,1,...,fNumData-1}, which is the set of the index numbers of 216 237 // all events in the training sample 217 for (Int_t n=0; n<fNumData; n++) 218 { 219 const Int_t k = Int_t(gRandom->Rndm()*fNumData); 238 TArrayF classpopw(2); 239 TArrayI jinbag(numdata); // Initialization includes filling with 0 240 TArrayF winbag(numdata); // Initialization includes filling with 0 241 242 for (Int_t n=0; n<numdata; n++) 243 { 244 const Int_t k = Int_t(gRandom->Rndm()*numdata); 220 245 221 246 classpopw[fHadTrue[k]]+=fWeight[k]; … … 237 262 238 263 // growing single tree 239 fRanTree->GrowTree(hadrons,gammas,f NumData,fNumDim,fHadTrue,datsortinbag,240 fDataRang,classpopw,jinbag,winbag ,fWeight);264 fRanTree->GrowTree(hadrons,gammas,fHadTrue,datsortinbag, 265 fDataRang,classpopw,jinbag,winbag); 241 266 242 267 // error-estimates from out-of-bag data (oob data): … … 249 274 // determined from oob-data is underestimated, but can still be taken as upper limit. 250 275 251 for (Int_t ievt=0;ievt<fNumHad;ievt++) 276 const Int_t numhad = hadrons.GetNrows(); 277 InitHadEst(0, numhad, hadrons, jinbag); 278 InitHadEst(numhad, numdata, gammas, jinbag); 279 /* 280 for (Int_t ievt=0;ievt<numhad;ievt++) 252 281 { 253 282 if (jinbag[ievt]>0) … … 256 285 fNTimesOutBag[ievt]++; 257 286 } 258 for (Int_t ievt=0;ievt<fNumGam;ievt++) 259 { 260 if (jinbag[fNumHad+ievt]>0) 287 288 for (Int_t ievt=numhad;ievt<numdata;ievt++) 289 { 290 if (jinbag[ievt]>0) 261 291 continue; 262 fHadEst[ fNumHad+ievt] += fRanTree->TreeHad(gammas, ievt);263 fNTimesOutBag[ fNumHad+ievt]++;264 } 265 292 fHadEst[ievt] += fRanTree->TreeHad(gammas, ievt-numhad); 293 fNTimesOutBag[ievt]++; 294 } 295 */ 266 296 Int_t n=0; 267 297 Double_t ferr=0; 268 for (Int_t ievt=0;ievt< fNumData;ievt++)298 for (Int_t ievt=0;ievt<numdata;ievt++) 269 299 if (fNTimesOutBag[ievt]!=0) 270 300 { … … 301 331 // fDataRang(m,n) is the rang of fData(m,n), i.e. if rang = r, fData(m,n) is the r-th highest 302 332 // value of all fData(m,.). There may be more then 1 event with rang r (due to bagging). 303 304 TArrayF v(fNumData); 305 TArrayI isort(fNumData); 333 const Int_t numdata = GetNumData(); 334 335 TArrayF v(numdata); 336 TArrayI isort(numdata); 306 337 307 338 const TMatrix &hadrons=fHadrons->GetM(); 308 339 const TMatrix &gammas=fGammas->GetM(); 309 340 310 for (Int_t j=0;j<fNumHad;j++) 341 const Int_t numgam = gammas.GetNrows(); 342 const Int_t numhad = hadrons.GetNrows(); 343 344 for (Int_t j=0;j<numhad;j++) 311 345 fHadTrue[j]=1; 312 346 313 for (Int_t j=0;j<fNumGam;j++) 314 fHadTrue[j+fNumHad]=0; 315 316 for (Int_t mvar=0;mvar<fNumDim;mvar++) 317 { 318 for(Int_t n=0;n<fNumHad;n++) 347 for (Int_t j=0;j<numgam;j++) 348 fHadTrue[j+numhad]=0; 349 350 const Int_t dim = GetNumDim(); 351 for (Int_t mvar=0;mvar<dim;mvar++) 352 { 353 for(Int_t n=0;n<numhad;n++) 319 354 { 320 355 v[n]=hadrons(n,mvar); … … 322 357 } 323 358 324 for(Int_t n=0;n< fNumGam;n++)359 for(Int_t n=0;n<numgam;n++) 325 360 { 326 v[n+ fNumHad]=gammas(n,mvar);327 isort[n+ fNumHad]=n;361 v[n+numhad]=gammas(n,mvar); 362 isort[n+numhad]=n; 328 363 } 329 364 330 TMath::Sort( fNumData,v.GetArray(),isort.GetArray(),kFALSE);365 TMath::Sort(numdata,v.GetArray(),isort.GetArray(),kFALSE); 331 366 332 367 // this sorts the v[n] in ascending order. isort[n] is the event number … … 334 369 // event numbers are 0,1,...). 335 370 336 for(Int_t n=0;n< fNumData-1;n++)371 for(Int_t n=0;n<numdata-1;n++) 337 372 { 338 373 const Int_t n1=isort[n]; 339 374 const Int_t n2=isort[n+1]; 340 375 341 fDataSort[mvar* fNumData+n]=n1;342 if(n==0) fDataRang[mvar* fNumData+n1]=0;376 fDataSort[mvar*numdata+n]=n1; 377 if(n==0) fDataRang[mvar*numdata+n1]=0; 343 378 if(v[n]<v[n+1]) 344 379 { 345 fDataRang[mvar* fNumData+n2]=fDataRang[mvar*fNumData+n1]+1;380 fDataRang[mvar*numdata+n2]=fDataRang[mvar*numdata+n1]+1; 346 381 }else{ 347 fDataRang[mvar* fNumData+n2]=fDataRang[mvar*fNumData+n1];382 fDataRang[mvar*numdata+n2]=fDataRang[mvar*numdata+n1]; 348 383 } 349 384 } 350 fDataSort[(mvar+1)* fNumData-1]=isort[fNumData-1];385 fDataSort[(mvar+1)*numdata-1]=isort[numdata-1]; 351 386 } 352 387 } … … 354 389 void MRanForest::ModifyDataSort(TArrayI &datsortinbag, Int_t ninbag, const TArrayI &jinbag) 355 390 { 391 const Int_t numdim=GetNumDim(); 392 const Int_t numdata=GetNumData(); 393 356 394 ninbag=0; 357 for (Int_t n=0;n< fNumData;n++)395 for (Int_t n=0;n<numdata;n++) 358 396 if(jinbag[n]==1) ninbag++; 359 397 360 for(Int_t m=0;m< fNumDim;m++)398 for(Int_t m=0;m<numdim;m++) 361 399 { 362 400 Int_t k=0; 363 401 Int_t nt=0; 364 for(Int_t n=0;n< fNumData;n++)402 for(Int_t n=0;n<numdata;n++) 365 403 { 366 if(jinbag[datsortinbag[m* fNumData+k]]==1)404 if(jinbag[datsortinbag[m*numdata+k]]==1) 367 405 { 368 datsortinbag[m* fNumData+nt]=datsortinbag[m*fNumData+k];406 datsortinbag[m*numdata+nt]=datsortinbag[m*numdata+k]; 369 407 k++; 370 408 }else{ 371 for(Int_t j=1;j< fNumData-k;j++)409 for(Int_t j=1;j<numdata-k;j++) 372 410 { 373 if(jinbag[datsortinbag[m* fNumData+k+j]]==1)411 if(jinbag[datsortinbag[m*numdata+k+j]]==1) 374 412 { 375 datsortinbag[m* fNumData+nt]=datsortinbag[m*fNumData+k+j];413 datsortinbag[m*numdata+nt]=datsortinbag[m*numdata+k+j]; 376 414 k+=j+1; 377 415 break; -
trunk/MagicSoft/Mars/mranforest/MRanForest.h
r2296 r2297 29 29 class MRanTree; 30 30 class TVector; 31 class TMatrix; 31 32 32 33 class MRanForest : public MParContainer … … 42 43 MHMatrix *fGammas; 43 44 MHMatrix *fHadrons; 44 45 Int_t fNumGam;46 Int_t fNumHad;47 Int_t fNumData;48 Int_t fNumDim;49 45 50 46 // true and estimated hadronness … … 65 61 // estimates for classification error of growing forest 66 62 TArrayD fTreeHad; 63 64 void InitHadEst(Int_t from, Int_t to, const TMatrix &m, TArrayI &jinbag); 67 65 68 66 protected: … … 90 88 MRanTree *GetCurTree() { return fRanTree; } 91 89 Int_t GetNumTrees() const { return fNumTrees; } 92 Int_t GetNumData() const { return fNumData; }93 Int_t GetNumDim() const { return fNumDim; }90 Int_t GetNumData() const; 91 Int_t GetNumDim() const; 94 92 Double_t GetTreeHad(Int_t i) const { return fTreeHad.At(i); } 95 93 … … 99 97 Bool_t AsciiWrite(ostream &out) const; 100 98 101 ClassDef(MRanForest, 1) // Storage container for tree structure99 ClassDef(MRanForest, 0) // Storage container for tree structure 102 100 }; 103 101 -
trunk/MagicSoft/Mars/mranforest/MRanForestFill.cc
r2207 r2297 53 53 // 54 54 // 55 MRanForestFill::MRanForestFill(const char *name, const char *title):fNumTrees( 100)55 MRanForestFill::MRanForestFill(const char *name, const char *title):fNumTrees(-1) 56 56 { 57 57 // … … 98 98 Int_t MRanForestFill::Process() 99 99 { 100 fNum++; 101 if(!(fRanForest->AddTree(fRanTree))) 100 if (!(fRanForest->AddTree(fRanTree))) 102 101 return kFALSE; 103 102 104 return fNum<fNumTrees; 103 fNum++; 104 105 return fNumTrees<0 ? kTRUE : fNum<fNumTrees; 105 106 } 106 107 … … 108 109 { 109 110 fRanForest->SetNumTrees(fNum); 110 111 111 return kTRUE; 112 112 } -
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r2296 r2297 76 76 } 77 77 78 void MRanTree::GrowTree(const TMatrix &mhad, const TMatrix &mgam,Int_t numdata, Int_t numdim,TArrayI &hadtrue, 79 TArrayI &datasort,TArrayI &datarang,TArrayF &tclasspop,TArrayI &jinbag, 80 TArrayF &winbag,TArrayF &weight) 78 void MRanTree::GrowTree(const TMatrix &mhad, const TMatrix &mgam, 79 const TArrayI &hadtrue, TArrayI &datasort, 80 const TArrayI &datarang, TArrayF &tclasspop, TArrayI &jinbag, 81 const TArrayF &winbag) 81 82 { 82 83 // arrays have to be initialized with generous size, so number of total nodes (nrnodes) 83 84 // is estimated for worst case 84 Int_t nrnodes=2*numdata+1; 85 const Int_t numdim =mhad.GetNcols(); 86 const Int_t numdata=winbag.GetSize(); 87 const Int_t nrnodes=2*numdata+1; 85 88 86 89 // number of events in bootstrap sample … … 91 94 TArrayI bestsplit(nrnodes); 92 95 TArrayI bestsplitnext(nrnodes); 93 TArrayI nodepop(nrnodes);94 TArrayI parent(nrnodes);95 TArrayI nodex(numdata);96 TArrayI nodestart(nrnodes);97 98 TArrayI ncase(numdata);99 TArrayI iv(numdim);100 TArrayI idmove(numdata);101 96 102 97 fBestVar.Set(nrnodes); … … 113 108 114 109 // tree growing 115 BuildTree(datasort,datarang,hadtrue,numdim,numdata,bestsplit, 116 bestsplitnext,nodepop,nodestart,tclasspop,nrnodes, 117 idmove,ncase,parent,jinbag,iv,winbag,ninbag); 110 BuildTree(datasort,datarang,hadtrue,bestsplit, 111 bestsplitnext,tclasspop,winbag,ninbag); 118 112 119 113 // post processing, determine cut (or split) values fBestSplit … … 141 135 } 142 136 143 Int_t MRanTree::FindBestSplit( TArrayI &datasort,TArrayI &datarang,TArrayI &hadtrue,Int_t mdim,144 Int_t numdata,Int_t ndstart,Int_t ndend,TArrayF &tclasspop,145 Int_t &msplit,Float_t &decsplit,Int_t &nbest,TArrayI &ncase,146 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t kbuild)137 Int_t MRanTree::FindBestSplit(const TArrayI &datasort,const TArrayI &datarang, 138 const TArrayI &hadtrue,Int_t ndstart,Int_t ndend,TArrayF &tclasspop, 139 Int_t &msplit,Float_t &decsplit,Int_t &nbest, 140 const TArrayF &winbag) 147 141 { 148 142 if(!gRandom) … … 151 145 return kFALSE; 152 146 } 147 148 const Int_t nrnodes = fBestSplit.GetSize(); 149 const Int_t numdata = (nrnodes-1)/2; 150 const Int_t mdim = fGiniDec.GetSize(); 153 151 154 152 // weighted class populations after split … … 161 159 // and nsplitnext is the case number of the next larger value of msplit. 162 160 163 Int_t nc,nbestvar=0,k; 164 Float_t crit; 165 Float_t rrn, rrd, rln, rld, u; 161 Int_t nbestvar=0; 166 162 167 163 // compute initial values of numerator and denominator of Gini-index, 168 164 // Gini index= pno/dno 169 Float_t pno=0; 170 Float_t pdo=0; 171 165 Double_t pno=0; 166 Double_t pdo=0; 172 167 for (Int_t j=0;j<2;j++) 173 168 { … … 190 185 191 186 // Gini index = rrn/rrd+rln/rld 192 rrn=pno;193 rrd=pdo;194 rln=0;195 rld=0;187 Double_t rrn=pno; 188 Double_t rrd=pdo; 189 Double_t rln=0; 190 Double_t rld=0; 196 191 197 192 TArrayF wl(2); // left node … … 202 197 for(Int_t nsp=ndstart;nsp<=ndend-1;nsp++) 203 198 { 204 nc=datasort[mvar*numdata+nsp]; 205 206 u=winbag[nc]; 207 k=hadtrue[nc]; 208 209 rln=rln+u*(2*wl[k]+u); 210 rrn=rrn+u*(-2*wr[k]+u); 211 rld=rld+u; 212 rrd=rrd-u; 213 214 wl[k]=wl[k]+u; 215 wr[k]=wr[k]-u; 216 217 if (datarang[mvar*numdata+nc]<datarang[mvar*numdata+datasort[mvar*numdata+nsp+1]]) 218 { 219 if (TMath::Min(rrd,rld)>1.0e-5) 220 { 221 crit=(rln/rld)+(rrn/rrd); 222 if (crit>critvar) 223 { 224 nbestvar=nsp; 225 critvar=crit; 226 } 227 } 228 } 199 const Int_t &nc=datasort[mvar*numdata+nsp]; 200 const Int_t &k=hadtrue[nc]; 201 202 const Float_t &u=winbag[nc]; 203 204 rln+=u*(2*wl[k]+u); 205 rrn+=u*(-2*wr[k]+u); 206 rld+=u; 207 rrd-=u; 208 209 wl[k]+=u; 210 wr[k]-=u; 211 212 if (datarang[mvar*numdata+nc]>=datarang[mvar*numdata+datasort[mvar*numdata+nsp+1]]) 213 continue; 214 if (TMath::Min(rrd,rld)<=1.0e-5) 215 continue; 216 217 const Double_t crit=(rln/rld)+(rrn/rrd); 218 if (crit<=critvar) 219 continue; 220 221 nbestvar=nsp; 222 critvar=crit; 229 223 } 230 224 231 if (critvar>critmax) { 232 msplit=mvar; 233 nbest=nbestvar; 234 critmax=critvar; 235 } 225 if (critvar<=critmax) 226 continue; 227 228 msplit=mvar; 229 nbest=nbestvar; 230 critmax=critvar; 236 231 } 237 232 238 233 decsplit=critmax-crit0; 239 if (critmax<-1.0e10) jstat=1; 240 241 return jstat; 242 } 243 244 void MRanTree::MoveData(TArrayI &datasort,Int_t mdim,Int_t numdata,Int_t ndstart, 234 235 return critmax<-1.0e10 ? 1 : jstat; 236 } 237 238 void MRanTree::MoveData(TArrayI &datasort,Int_t ndstart, 245 239 Int_t ndend,TArrayI &idmove,TArrayI &ncase,Int_t msplit, 246 240 Int_t nbest,Int_t &ndendl) … … 249 243 // the data in the part of datasort corresponding to the current node is moved to the 250 244 // left if it belongs to the left child and right if it belongs to the right child-node. 251 252 Int_t nc,k,ih; 245 const Int_t numdata = ncase.GetSize(); 246 const Int_t mdim = fGiniDec.GetSize(); 247 253 248 TArrayI tdatasort(numdata); 254 249 255 250 // compute idmove = indicator of case nos. going left 256 251 257 for (Int_t nsp=ndstart;nsp<=nbest;nsp++) 258 { 259 nc=datasort[msplit*numdata+nsp]; 260 idmove[nc]=1; 261 } 262 for (Int_t nsp=nbest+1;nsp<=ndend;nsp++) 263 { 264 nc=datasort[msplit*numdata+nsp]; 265 idmove[nc]=0; 252 for (Int_t nsp=ndstart;nsp<=ndend;nsp++) 253 { 254 const Int_t &nc=datasort[msplit*numdata+nsp]; 255 idmove[nc]= nsp<=nbest?1:0; 266 256 } 267 257 ndendl=nbest; … … 271 261 for(Int_t msh=0;msh<mdim;msh++) 272 262 { 273 k=ndstart-1;263 Int_t k=ndstart-1; 274 264 for (Int_t n=ndstart;n<=ndend;n++) 275 265 { 276 ih=datasort[msh*numdata+n]; 277 if (idmove[ih]==1) { 278 k++; 279 tdatasort[k]=datasort[msh*numdata+n]; 280 } 266 const Int_t &ih=datasort[msh*numdata+n]; 267 if (idmove[ih]==1) 268 tdatasort[++k]=datasort[msh*numdata+n]; 281 269 } 282 270 283 271 for (Int_t n=ndstart;n<=ndend;n++) 284 272 { 285 ih=datasort[msh*numdata+n]; 286 if (idmove[ih]==0){ 287 k++; 288 tdatasort[k]=datasort[msh*numdata+n]; 289 } 273 const Int_t &ih=datasort[msh*numdata+n]; 274 if (idmove[ih]==0) 275 tdatasort[++k]=datasort[msh*numdata+n]; 290 276 } 291 for(Int_t k=ndstart;k<=ndend;k++) 292 datasort[msh*numdata+k]=tdatasort[k]; 277 278 for(Int_t m=ndstart;m<=ndend;m++) 279 datasort[msh*numdata+m]=tdatasort[m]; 293 280 } 294 281 … … 299 286 } 300 287 301 void MRanTree::BuildTree(TArrayI &datasort,TArrayI &datarang,TArrayI &hadtrue,Int_t mdim, 302 Int_t numdata,TArrayI &bestsplit,TArrayI &bestsplitnext, 303 TArrayI &nodepop,TArrayI &nodestart,TArrayF &tclasspop, 304 Int_t nrnodes,TArrayI &idmove,TArrayI &ncase,TArrayI &parent, 305 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t ninbag) 288 void MRanTree::BuildTree(TArrayI &datasort,const TArrayI &datarang, 289 const TArrayI &hadtrue, TArrayI &bestsplit, 290 TArrayI &bestsplitnext, TArrayF &tclasspop, 291 const TArrayF &winbag, Int_t ninbag) 306 292 { 307 293 // Buildtree consists of repeated calls to two void functions, FindBestSplit and MoveData. … … 318 304 // the next node to be split is numbered k+1. When no more nodes can be split, buildtree 319 305 // returns. 320 321 Int_t msplit, nbest, ndendl; 322 Float_t decsplit=0; 323 TArrayF classpop(2*nrnodes); 306 const Int_t mdim = fGiniDec.GetSize(); 307 const Int_t nrnodes = fBestSplit.GetSize(); 308 const Int_t numdata = (nrnodes-1)/2; 309 310 TArrayI nodepop(nrnodes); 311 TArrayI nodestart(nrnodes); 312 TArrayI parent(nrnodes); 313 314 TArrayI ncase(numdata); 315 TArrayI idmove(numdata); 316 TArrayI iv(mdim); 317 318 TArrayF classpop(nrnodes*2); 324 319 TArrayI nodestatus(nrnodes); 325 326 nodestart.Reset();327 nodepop.Reset();328 320 329 321 for (Int_t j=0;j<2;j++) … … 331 323 332 324 Int_t ncur=0; 333 nodestart[0]=0;334 325 nodepop[0]=ninbag; 335 326 nodestatus[0]=2; 336 327 337 328 // start main loop 338 for (Int_t kbuild=0; kbuild<nrnodes;kbuild++)329 for (Int_t kbuild=0; kbuild<nrnodes; kbuild++) 339 330 { 340 331 if (kbuild>ncur) break; … … 346 337 const Int_t ndend=ndstart+nodepop[kbuild]-1; 347 338 for (Int_t j=0;j<2;j++) 348 tclasspop[j]=classpop[j*nrnodes+kbuild]; 349 350 const Int_t jstat=FindBestSplit(datasort,datarang,hadtrue,mdim,numdata, 351 ndstart,ndend,tclasspop,msplit,decsplit, 352 nbest,ncase,jinbag,iv,winbag,kbuild); 353 354 if(jstat==1) { 339 tclasspop[j]=classpop[j*nrnodes+kbuild]; 340 341 Int_t msplit, nbest; 342 Float_t decsplit=0; 343 const Int_t jstat=FindBestSplit(datasort,datarang,hadtrue, 344 ndstart,ndend,tclasspop,msplit, 345 decsplit,nbest,winbag); 346 347 if (jstat==1) 348 { 355 349 nodestatus[kbuild]=-1; 356 350 continue; 357 }else{358 fBestVar[kbuild]=msplit;359 fGiniDec[msplit]+=decsplit;360 361 bestsplit[kbuild]=datasort[msplit*numdata+nbest];362 bestsplitnext[kbuild]=datasort[msplit*numdata+nbest+1];363 351 } 364 352 365 MoveData(datasort,mdim,numdata,ndstart,ndend,idmove,ncase, 353 fBestVar[kbuild]=msplit; 354 fGiniDec[msplit]+=decsplit; 355 356 bestsplit[kbuild]=datasort[msplit*numdata+nbest]; 357 bestsplitnext[kbuild]=datasort[msplit*numdata+nbest+1]; 358 359 Int_t ndendl; 360 MoveData(datasort,ndstart,ndend,idmove,ncase, 366 361 msplit,nbest,ndendl); 367 362 … … 377 372 for (Int_t n=ndstart;n<=ndendl;n++) 378 373 { 379 const Int_t nc=ncase[n];380 const Int_t j=hadtrue[nc];374 const Int_t &nc=ncase[n]; 375 const Int_t &j=hadtrue[nc]; 381 376 classpop[j*nrnodes+ncur+1]+=winbag[nc]; 382 377 } … … 384 379 for (Int_t n=ndendl+1;n<=ndend;n++) 385 380 { 386 const Int_t nc=ncase[n];387 const Int_t j=hadtrue[nc];381 const Int_t &nc=ncase[n]; 382 const Int_t &j=hadtrue[nc]; 388 383 classpop[j*nrnodes+ncur+2]+=winbag[nc]; 389 384 } -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r2296 r2297 61 61 62 62 // functions used in tree growing process 63 void GrowTree(const TMatrix &mhad, const TMatrix &mgam, Int_t numdata,64 Int_t numdim,TArrayI &hadtrue,65 TArrayI &datasort,TArrayI &datarang,TArrayF &tclasspop,TArrayI &jinbag,66 TArrayF & winbag,TArrayF &weight);63 void GrowTree(const TMatrix &mhad, const TMatrix &mgam, 64 const TArrayI &hadtrue, TArrayI &datasort, 65 const TArrayI &datarang, 66 TArrayF &tclasspop, TArrayI &jinbag, const TArrayF &winbag); 67 67 68 Int_t FindBestSplit(TArrayI &datasort,TArrayI &datarang,TArrayI &hadtrue,Int_t mdim, 69 Int_t numdata,Int_t ndstart,Int_t ndend,TArrayF &tclasspop, 70 Int_t &msplit,Float_t &decsplit,Int_t &nbest,TArrayI &ncase, 71 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t kbuild); 68 Int_t FindBestSplit(const TArrayI &datasort, const TArrayI &datarang, 69 const TArrayI &hadtrue, 70 Int_t ndstart, Int_t ndend, TArrayF &tclasspop, 71 Int_t &msplit, Float_t &decsplit, Int_t &nbest, 72 const TArrayF &winbag); 72 73 73 void MoveData(TArrayI &datasort, Int_t mdim,Int_t numdata,Int_t ndstart,74 Int_t ndend,TArrayI &idmove,TArrayI &ncase,Int_t msplit,75 Int_t nbest, Int_t &ndendl);74 void MoveData(TArrayI &datasort, Int_t ndstart, Int_t ndend, 75 TArrayI &idmove, TArrayI &ncase, Int_t msplit, 76 Int_t nbest, Int_t &ndendl); 76 77 77 void BuildTree(TArrayI &datasort,TArrayI &datarang,TArrayI &hadtrue,Int_t mdim, 78 Int_t numdata,TArrayI &bestsplit,TArrayI &bestsplitnext, 79 TArrayI &nodepop,TArrayI &nodestart,TArrayF &tclasspop, 80 Int_t nrnodes,TArrayI &idmove,TArrayI &ncase,TArrayI &parent, 81 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t ninbag); 78 void BuildTree(TArrayI &datasort, const TArrayI &datarang, 79 const TArrayI &hadtrue, 80 TArrayI &bestsplit,TArrayI &bestsplitnext, 81 TArrayF &tclasspop, 82 const TArrayF &winbag, 83 Int_t ninbag); 82 84 83 85 Double_t TreeHad(const TVector &event);
Note:
See TracChangeset
for help on using the changeset viewer.