Changeset 7697


Ignore:
Timestamp:
05/05/06 10:53:03 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7695 r7697  
    4646     - removed the obsolste dereferencing from the call to FindBestSplit
    4747     - added some const-qualifiers in funciton calls
     48     - make a copy of tclasspop in BuildTree to be able to give the
     49       array as a const qualified reference. It is not used at any other
     50       place
     51     - in TreeHad first get the pointers to the vector with the data to
     52       get rid of the range check done by root. This has also the advantage
     53       that all TreeHad member function can be unified into a single
     54       member function
    4855
    4956   * mhflux/MAlphaFitter.cc:
     
    5158       in the case of off-data. This did in no means effect the result,
    5259       just the performance.
     60
     61   * mhbase/MH3.cc:
     62     - convert the options ToLower case first before checking
     63
     64   * mjtrain/MJTrainRanForest.[h,cc]:
     65     - added AddPar member function
     66     - added fPreTasks and fPostTasks
     67     - added fEnableWeights
     68     - added member functions suporting setting pre- and posttasks
     69       and weights
     70
     71   * mtools/MTFillMatrix.h:
     72     - added new member function to clear the fPreCuts, fPreTasks and
     73       fPostTasks lists
    5374
    5475
  • trunk/MagicSoft/Mars/NEWS

    r7682 r7697  
    1212   - general: Added a missing feature in the MFilterLIst class which
    1313     prevented MFEnergySlope from working correctly in trainenergy.C
     14
     15   - general: Accelerated the random forest training and usage a bit
    1416
    1517   - merpp: Adapted to new raw data file format version 6
  • trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc

    r7421 r7697  
    3535#include "MLogManip.h"
    3636
     37#include "MF.h"
     38#include "MParameterCalc.h"
     39
    3740#include "MStatusDisplay.h"
    38 
    39 #include "MF.h"
    4041
    4142ClassImp(MJTrainRanForest);
     
    4546//------------------------------------------------------------------------
    4647//
    47 // Add a cut which is used to fill the matrix, eg "MMcEvt.fOartId<1.5"
    48 // (The rule is applied, nit inverted: The matrix is filled with
     48// Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5"
     49// (The rule is applied, not inverted: The matrix is filled with
    4950// the events fullfilling the condition)
    5051//
     
    5253{
    5354    MFilter *f = new MF(rule);
    54     f->SetBit(kCanDelete);
    55     AddCut(l, f);
     55    f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it???
     56    Add(l, f);
    5657}
    5758
    5859//------------------------------------------------------------------------
    5960//
    60 // Add a cut which is used to fill the matrix. If kCanDelete is set
     61// Add an additional parameter (MParameterCalc), eg "0.5", "MWeight"
     62// The default container name is "MWeight"
     63//
     64void MJTrainRanForest::AddPar(TList &l, const char *rule, const char *pname)
     65{
     66    TString tname(pname);
     67    tname += "Calc";
     68
     69    MParameterCalc *par = new MParameterCalc(rule, tname);
     70    par->SetNameParameter(pname);
     71//    par->SetBit(kCanDelete);  //FIXME!!!! MTaskList is deleting it
     72    Add(l, par);
     73}
     74
     75//------------------------------------------------------------------------
     76//
     77// Add a task/cut which is used to fill the matrix. If kCanDelete is set
    6178// MJOptimize takes the ownership.
    6279//
    63 void MJTrainRanForest::AddCut(TList &l, MFilter *f)
     80void MJTrainRanForest::Add(TList &l, MTask *f)
    6481{
    6582    l.Add(f);
  • trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h

    r7552 r7697  
    66#endif
    77
     8class MTask;
    89class MFilter;
    910
     
    1213protected:
    1314    Bool_t fDebug;
     15    Bool_t fEnableWeights;
    1416
    1517    TList fRules;
     
    1820    TList fTrainCuts;
    1921    TList fTestCuts;
     22    TList fPreTasks;
     23    TList fPostTasks;
    2024
    2125    UShort_t fNumTrees;
     
    2630
    2731    void AddCut(TList &l, const char *rule);
    28     void AddCut(TList &l, MFilter *f);
     32    void AddPar(TList &l, const char *rule, const char *name);
     33    void Add(TList &l, MTask *f);
    2934
    3035public:
    31     MJTrainRanForest() : fDebug(kFALSE)
     36    MJTrainRanForest() : fDebug(kFALSE), fEnableWeights(kFALSE)
    3237    {
    3338        fNumTrees = 100; //100
     
    3641    }
    3742
    38     void SetDebug(Bool_t b=kTRUE) { fDebug = b; }
     43    void AddPreTask(MTask *t)                    { Add(fPreTasks,  t); }
     44    void AddPreTask(const char *rule,
     45                    const char *name="MWeight")  { AddPar(fPreTasks, rule, name); }
     46
     47    void AddPostTask(MTask *t)                   { Add(fPostTasks, t); }
     48    void AddPostTask(const char *rule,
     49                     const char *name="MWeight") { AddPar(fPostTasks, rule, name); }
     50
     51    void SetDebug(Bool_t b=kTRUE)      { fDebug = b; }
     52
     53    void SetWeights(const char *rule)  { if (fEnableWeights) return; fEnableWeights=kTRUE; AddPostTask(rule); }
     54    void SetWeights(MTask *t)          { if (fEnableWeights) return; fEnableWeights=kTRUE; AddPostTask(t);    }
    3955
    4056    void AddPreCut(const char *rule)   { AddCut(fPreCuts, rule); }
    41     void AddPreCut(MFilter *f)         { AddCut(fPreCuts, f); }
     57    void AddPreCut(MFilter *f)         { Add(fPreCuts, (MTask*)(f)); }
    4258
    4359    void AddTrainCut(const char *rule) { AddCut(fTrainCuts, rule); }
    44     void AddTrainCut(MFilter *f)       { AddCut(fTrainCuts, f); }
     60    void AddTrainCut(MFilter *f)       { Add(fTrainCuts, (MTask*)(f)); }
    4561
    4662    void AddTestCut(const char *rule)  { AddCut(fTestCuts, rule); }
    47     void AddTestCut(MFilter *f)        { AddCut(fTestCuts, f); }
     63    void AddTestCut(MFilter *f)        { Add(fTestCuts, (MTask*)(f)); }
    4864
    49     void SetNumTrees(UShort_t n=100) { fNumTrees = n; }
    50     void SetNdSize(UShort_t n=5)     { fNdSize   = n; }
    51     void SetNumTry(UShort_t n=0)     { fNumTry   = n; }
     65    void SetNumTrees(UShort_t n=100)   { fNumTrees = n; }
     66    void SetNdSize(UShort_t n=5)       { fNdSize   = n; }
     67    void SetNumTry(UShort_t n=0)       { fNumTry   = n; }
    5268
    5369    Int_t AddParameter(const char *rule);
  • trunk/MagicSoft/Mars/mranforest/MRanTree.cc

    r7693 r7697  
    9999
    100100void 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,
    102102                        const Float_t &mean, const Float_t &square, const MArrayI &jinbag, const MArrayF &winbag,
    103103                        const int nclass)
     
    192192    for (Int_t mt=0; mt<fNumTry; mt++)
    193193    {
    194         const Int_t mvar=Int_t(gRandom->Rndm()*mdim);
     194        const Int_t mvar= gRandom->Integer(mdim);
    195195        const Int_t mn  = mvar*numdata;
    196196
     
    201201        Double_t rld=0;
    202202
    203         MArrayF wl(nclass); // left node //nclass
     203        MArrayF wl(nclass);     // left node //nclass
    204204        MArrayF wr(tclasspop);  // right node//nclass
    205205
     
    212212
    213213            // do classification, Gini index as split rule
    214             rln+=u*(2*wl[k]+u);
     214            rln+=u*( 2*wl[k]+u);
    215215            rrn+=u*(-2*wr[k]+u);
    216216
     
    445445void MRanTree::BuildTree(MArrayI &datasort,const MArrayI &datarang, const MArrayF &hadtrue,
    446446                         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,
    448448                         Int_t ninbag, const int nclass)
    449449{
     
    481481    MArrayF mean(nrnodes);
    482482    MArrayF square(nrnodes);
     483    MArrayF lclasspop(tclasspop);
    483484
    484485    mean[0]=tmean;
     
    502503
    503504          for (Int_t j=0;j<nclass;j++)
    504               tclasspop[j]=classpop[j*nrnodes+kbuild];
     505              lclasspop[j]=classpop[j*nrnodes+kbuild];
    505506
    506507          Int_t msplit, nbest;
     
    508509
    509510          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,
    511512                                     nbest,winbag,nclass))
    512513          {
     
    621622}
    622623
    623 Double_t MRanTree::TreeHad(const TVector &event)
    624 {
    625     Int_t kt=0;
     624Double_t MRanTree::TreeHad(const Float_t *evt)
     625{
    626626    // to optimize on storage space node status and node class
    627627    // are coded into fBestVar:
     
    631631    // hadronness assigned to node kt = fBestSplit[kt]
    632632
    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)
    636643            break;
    637644
    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
     652Double_t MRanTree::TreeHad(const TVector &event)
     653{
     654    return TreeHad(event.GetMatrixArray());
    643655}
    644656
    645657Double_t MRanTree::TreeHad(const TMatrixRow &event)
    646658{
    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());
    665660}
    666661
  • trunk/MagicSoft/Mars/mranforest/MRanTree.h

    r7693 r7697  
    4545         Int_t &, const MArrayF &, const int); //!
    4646
     47    Double_t TreeHad(const Float_t *evt);
    4748
    4849    int FindBestSplitGini(const MArrayI &datasort, const MArrayI &datarang,
     
    6667    void BuildTree(MArrayI &datasort, const MArrayI &datarang, const MArrayF &hadtrue,
    6768                   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,
    6970                   Int_t ninbag, const int nclass);
    7071
     
    9798    // functions used in tree growing process
    9899    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,
    100101                  const Float_t &mean, const Float_t &square, const MArrayI &jinbag, const MArrayF &winbag,
    101102                  const int nclass);
  • trunk/MagicSoft/Mars/mtools/MTFillMatrix.h

    r7687 r7697  
    9090    void AddPostTasks(const TList &list);
    9191
     92    void ClearPreCuts()   { fPreCuts.Clear(); }
     93    void ClearPreTasks()  { fPreTasks.Clear(); }
     94    void ClearPostTasks() { fPostTasks.Clear(); }
     95
    9296    Bool_t Process(const MParList &plist=MParList());
    9397    Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
Note: See TracChangeset for help on using the changeset viewer.