Ignore:
Timestamp:
07/24/07 14:36:39 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mranforest/MRanForest.cc

    r8203 r8644  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.26 2006-11-02 08:57:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.27 2007-07-24 13:35:39 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    124124
    125125    fNTimesOutBag = rf.fNTimesOutBag;
    126 
    127126}
    128127
     
    435434    // initialize running output
    436435
    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);
    439438
    440439    if (fTreeNo==1)
     
    443442
    444443        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;
    446445        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;
    448447                     //        12345678901234567890123456789012345678901234567890
    449448    }
     
    498497                       jinbag,winbag,nclass);
    499498
    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//
     520Double_t MRanForest::EstimateError(const MArrayI &jinbag, Bool_t calcResolution)
     521{
     522    const Int_t numdata = GetNumData();
     523
    510524    Int_t ninbag = 0;
    511525    for (Int_t ievt=0;ievt<numdata;ievt++)
     
    522536
    523537    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);
    538567
    539568    //-------------------------------------------------------------------
     
    543572    *fLog << setw(9) << fRanTree->GetNumEndNodes();
    544573    *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);
    546577    *fLog << endl;
    547578
    548     fRanTree->SetError(ferr);
    549 
    550     // adding tree to forest
    551     AddTree();
    552 
    553     return fTreeNo<fNumTrees;
     579    return ferr;
    554580}
    555581
Note: See TracChangeset for help on using the changeset viewer.