Ignore:
Timestamp:
11/22/05 11:06:56 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mranforest
Files:
6 edited

Legend:

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

    r7417 r7420  
    6262// Default constructor.
    6363//
    64 MRanForest::MRanForest(const char *name, const char *title) : fClassify(1), fNumTrees(100), fNumTry(0), fNdSize(1), fRanTree(NULL), fUserVal(-1)
     64MRanForest::MRanForest(const char *name, const char *title)
     65    : fClassify(kTRUE), fNumTrees(100), fNumTry(0), fNdSize(1),
     66    fRanTree(NULL), fRules(NULL), fMatrix(NULL), fUserVal(-1)
    6567{
    6668    fName  = name  ? name  : "MRanForest";
     
    125127{
    126128    delete fForest;
     129    if (fMatrix)
     130        delete fMatrix;
     131    if (fRules)
     132        delete fRules;
    127133}
    128134
     
    152158void MRanForest::SetWeights(const TArrayF &weights)
    153159{
    154     const int n=weights.GetSize();
    155     fWeight.Set(n);
    156160    fWeight=weights;
    157 
    158     return;
    159161}
    160162
     
    175177    //for(int i=0;i<n;i++)
    176178    //    *fLog<<inf<<" "<<i<<") "<<fGrid[i]<<endl;
    177 
    178     return;
    179179}
    180180
     
    227227}
    228228
    229 /*
    230 Bool_t MRanForest::PreProcess(MParList *plist)
    231 {
    232     if (!fRules)
    233     {
    234         *fLog << err << dbginf << "MDataArray with rules not initialized... aborting." << endl;
    235         return kFALSE;
    236     }
    237 
    238     if (!fRules->PreProcess(plist))
    239     {
    240         *fLog << err << dbginf << "PreProcessing of MDataArray failed... aborting." << endl;
    241         return kFALSE;
    242     }
    243 
    244     return kTRUE;
    245 }
    246 */
    247 
    248229Double_t MRanForest::CalcHadroness()
    249230{
     
    285266    // access matrix, copy last column (target) preliminarily
    286267    // into fHadTrue
     268    if (fMatrix)
     269        delete fMatrix;
    287270    fMatrix = new TMatrix(mat->GetM());
    288271
     
    337320    }
    338321
     322    if (fRules)
     323        delete fRules;
    339324    fRules = new MDataArray();
    340325    fRules->Reset();
  • trunk/MagicSoft/Mars/mranforest/MRanForest.h

    r7396 r7420  
    3030{
    3131private:
    32     Int_t fClassify;
     32    Bool_t fClassify;
    3333
    3434    Int_t fNumTrees;       // Number of trees
     
    8383    void SetNdSize(Int_t n);
    8484
    85     void SetClassify(Int_t n){ fClassify=n; }
     85    void SetClassify(Bool_t n){ fClassify=n; }
    8686    void PrepareClasses();
    8787
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r7413 r7420  
    7979}
    8080
     81// --------------------------------------------------------------------------
     82//
     83// ver=0: One yes/no-classification forest is trained for each bin.
     84//        the yes/no classification is done using the grid
     85// ver=1: One classification forest is trained. The last column contains a
     86//        value which is turned into a classifier by rf itself using the grid
     87// ver=2: One classification forest is trained. The last column already contains
     88//        the classifier
     89// ver=3: A regression forest is trained. The last column contains the
     90//        classifier
     91//
    8192Int_t MRanForestCalc::Train(const MHMatrix &matrixtrain, const TArrayD &grid, Int_t ver)
    8293{
     
    117128
    118129    MDataArray rules(usedrules);
    119     rules.AddEntry(ver<2?"Classification":dcol[ncols-1].GetRule());
     130    rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule());
    120131
    121132    // prepare matrix for current energy bin
     
    133144        switch (ver)
    134145        {
    135         case 0: // Replace Energy Grid by classification
     146        case 0: // Replace last column by a classification
    136147            {
    137148                Int_t irows=0;
     
    158169            break;
    159170
    160         case 1: // Use Energy as classifier
     171        case 1: // Use last column as classifier or for regression
    161172        case 2:
     173        case 3:
    162174            for (Int_t j=0; j<nrows; j++)
    163175                mat(j, ncols-nobs) = matrixtrain.GetM()(j,ncols-1);
     
    176188        rf.SetNumTry(fNumTry);
    177189        rf.SetNdSize(fNdSize);
    178         rf.SetClassify(ver<2 ? 1 : 0);
     190        rf.SetClassify(ver<3 ? kTRUE : kFALSE);
    179191        if (ver==1)
    180192            rf.SetGrid(grid);
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h

    r7413 r7420  
    6565
    6666    // Train Interface
    67     Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver=2);
     67    Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver);
    6868
    6969public:
     
    8787    Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid)
    8888    {
     89        // One yes/no-classification forest is trained for each bin
    8990        return Train(n, grid, 0);
    9091    }
    9192    Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD())
    9293    {
     94        // w/o Grid: Last Column contains classifier
     95        // w/  Grid: Last Column will be converted by grid into classifier
    9396        return Train(n, grid, grid.GetSize()==0 ? 2 : 1);
     97    }
     98    Int_t TrainRegression(const MHMatrix &n)
     99    {
     100        // Use last column for regression
     101        return Train(n, TArrayD(), 3);
    94102    }
    95103
  • trunk/MagicSoft/Mars/mranforest/MRanTree.cc

    r7396 r7420  
    4949// Default constructor.
    5050//
    51 MRanTree::MRanTree(const char *name, const char *title):fClassify(1),fNdSize(0), fNumTry(3)
     51MRanTree::MRanTree(const char *name, const char *title):fClassify(kTRUE),fNdSize(0), fNumTry(3)
    5252{
    5353
  • trunk/MagicSoft/Mars/mranforest/MRanTree.h

    r7413 r7420  
    2222{
    2323private:
    24     Int_t fClassify;
     24    Bool_t fClassify;
     25
    2526    Int_t fNdSize;
    2627    Int_t fNumTry;
     
    8889    Float_t GetGiniDec(Int_t i)  const { return fGiniDec.At(i); }
    8990
    90     void SetClassify(Int_t n){ fClassify=n; }
     91    void SetClassify(Bool_t n){ fClassify=n; }
    9192
    9293    // functions used in tree growing process
Note: See TracChangeset for help on using the changeset viewer.