Changeset 8644 for trunk/MagicSoft/Mars/mranforest/MRanForest.cc
- Timestamp:
- 07/24/07 14:36:39 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r8203 r8644 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.2 6 2006-11-02 08:57:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.27 2007-07-24 13:35:39 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 124 124 125 125 fNTimesOutBag = rf.fNTimesOutBag; 126 127 126 } 128 127 … … 435 434 // initialize running output 436 435 437 float minfloat= fHadTrue[TMath::LocMin(fHadTrue.GetSize(),fHadTrue.GetArray())];438 Bool_t calcResolution=(minfloat> 0.001);436 float minfloat=TMath::MinElement(fHadTrue.GetSize(),fHadTrue.GetArray()); 437 Bool_t calcResolution=(minfloat>FLT_MIN); 439 438 440 439 if (fTreeNo==1) … … 443 442 444 443 if(calcResolution) 445 *fLog << "TreeNum BagSize NumNodes TestSize res/% (from oob-data -> overest. of error)" << endl;444 *fLog << "TreeNum BagSize NumNodes TestSize Bias/% var/% res/% (from oob-data)" << endl; 446 445 else 447 *fLog << "TreeNum BagSize NumNodes TestSize rms/% (from oob-data -> overest. of error)" << endl;446 *fLog << "TreeNum BagSize NumNodes TestSize Bias/au var/au rms/au (from oob-data)" << endl; 448 447 // 12345678901234567890123456789012345678901234567890 449 448 } … … 498 497 jinbag,winbag,nclass); 499 498 500 //------------------------------------------------------------------- 501 // error-estimates from out-of-bag data (oob data): 502 // 503 // For a single tree the events not(!) contained in the bootstrap 504 // sample of this tree can be used to obtain estimates for the 505 // classification error of this tree. 506 // If you take a certain event, it is contained in the oob-data of 507 // 1/3 of the trees (see comment to ModifyData). This means that the 508 // classification error determined from oob-data is underestimated, 509 // but can still be taken as upper limit. 499 const Double_t ferr = EstimateError(jinbag, calcResolution); 500 501 fRanTree->SetError(ferr); 502 503 // adding tree to forest 504 AddTree(); 505 506 return fTreeNo<fNumTrees; 507 } 508 509 //------------------------------------------------------------------- 510 // error-estimates from out-of-bag data (oob data): 511 // 512 // For a single tree the events not(!) contained in the bootstrap 513 // sample of this tree can be used to obtain estimates for the 514 // classification error of this tree. 515 // If you take a certain event, it is contained in the oob-data of 516 // 1/3 of the trees (see comment to ModifyData). This means that the 517 // classification error determined from oob-data is underestimated, 518 // but can still be taken as upper limit. 519 // 520 Double_t MRanForest::EstimateError(const MArrayI &jinbag, Bool_t calcResolution) 521 { 522 const Int_t numdata = GetNumData(); 523 510 524 Int_t ninbag = 0; 511 525 for (Int_t ievt=0;ievt<numdata;ievt++) … … 522 536 523 537 Int_t n=0; 524 Float_t ferr=0; 525 526 for (Int_t ievt=0;ievt<numdata;ievt++) 527 { 528 if(fNTimesOutBag[ievt]!=0) 529 { 530 float val = fHadEst[ievt]/float(fNTimesOutBag[ievt])-fHadTrue[ievt]; 531 if(calcResolution) val/=fHadTrue[ievt]; 532 533 ferr += val*val; 534 n++; 535 } 536 } 537 ferr = TMath::Sqrt(ferr/n); 538 539 Double_t sum=0; 540 Double_t sq =0; 541 for (Int_t i=0; i<numdata; i++) 542 { 543 if (fNTimesOutBag[i]==0) 544 continue; 545 546 const Float_t hadest = fHadEst[i]/fNTimesOutBag[i]; 547 548 const Float_t val = calcResolution ? 549 hadest/fHadTrue[i] - 1 : hadest - fHadTrue[i]; 550 551 sum += val; 552 sq += val*val; 553 n++; 554 } 555 556 if (calcResolution) 557 { 558 sum *= 100; 559 sq *= 10000; 560 } 561 562 sum /= n; 563 sq /= n; 564 565 const Double_t var = TMath::Sqrt(sq-sum*sum); 566 const Double_t ferr = TMath::Sqrt(sq); 538 567 539 568 //------------------------------------------------------------------- … … 543 572 *fLog << setw(9) << fRanTree->GetNumEndNodes(); 544 573 *fLog << Form(" %9.1f", 100.*n/numdata); 545 *fLog << Form("%18.2f", ferr*100.); 574 *fLog << Form(" %7.2f", sum); 575 *fLog << Form(" %7.2f", var); 576 *fLog << Form(" %7.2f", ferr); 546 577 *fLog << endl; 547 578 548 fRanTree->SetError(ferr); 549 550 // adding tree to forest 551 AddTree(); 552 553 return fTreeNo<fNumTrees; 579 return ferr; 554 580 } 555 581
Note:
See TracChangeset
for help on using the changeset viewer.