Changeset 7687 for trunk/MagicSoft


Ignore:
Timestamp:
05/03/06 14:13:48 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7686 r7687  
    4646   * mraw/MRawRunHeader.cc:
    4747     - removed an obsolete Print() which enetered for debugging
     48
     49   * mimage/MHNewImagePar.cc:
     50     - the plots for CocCOG and ConcCore had the same color... fixed
     51
     52   * mranforest/MRanForestCalc.[h,cc]:
     53     - allow to set weights for each event
     54
     55   * mtools/MTFillMatrix.[h,cc]:
     56     - implemented the possibility to set pre- and post-tasks
     57       executed in the eventloop
     58
    4859
    4960
  • trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc

    r7599 r7687  
    362362        fHistUsedPix.SetLineColor(kCyan);
    363363        fHistConc1.SetLineColor(kMagenta);
    364         fHistConcCOG.SetLineColor(kCyan);
     364        fHistConc.SetLineColor(kCyan);
     365        fHistConcCOG.SetLineColor(kMagenta);
    365366        fHistConcCore.SetLineColor(kCyan);
    366         fHistConc.SetLineColor(kCyan);
    367367        fHistCoreArea.SetLineColor(kMagenta);
    368368        fHistUsedArea.SetLineColor(kCyan);
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc

    r7425 r7687  
    6363    : fData(0), fRFOut(0), fTestMatrix(0),
    6464    fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
     65    fLastDataColumnHasWeights(kFALSE),
    6566    fNameOutput(gsNameOutput), fDebug(kFALSE), fEstimationMode(kMean)
    6667{
     
    116117    }
    117118
    118     const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns
     119    // The number of columns which have to be removed for the training
     120    // The last data column may contain weight which also have to be removed
     121    const Int_t nobs = fNumObsoleteVariables + (fLastDataColumnHasWeights?1:0); // Number of obsolete columns
    119122
    120123    const MDataArray &dcol = *matrixtrain.GetColumns();
    121124
     125    // Make a copy of the rules for accessing the train-data
    122126    MDataArray usedrules;
    123127    for (Int_t i=0; i<ncols; i++)
     
    127131            *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl;
    128132
     133    // In the case of regression store the rule to be regessed in the
     134    // last entry of your rules
    129135    MDataArray rules(usedrules);
    130136    rules.AddEntry(ver<3?"Classification":dcol[ncols-1].GetRule());
    131137
    132     // prepare matrix for current energy bin
     138    // prepare train-matrix finally used
    133139    TMatrix mat(matrixtrain.GetM());
    134140
    135     // last column must be removed (true energy col.)
     141    // Resize it such that the obsolete columns are removed
    136142    mat.ResizeTo(nrows, ncols-nobs+1);
    137143
     
    139145        gLog.SetNullOutput(kTRUE);
    140146
     147    // In the case one independant RF is trained for each bin (e.g.
     148    // energy-bin) train all of them
    141149    const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1;
    142150    for (Int_t ie=0; ie<nbins; ie++)
    143151    {
     152        // In the case weights should be used initialize the
     153        // corresponding array
     154        TArrayF weights(nrows);
     155        if (fLastDataColumnHasWeights)
     156            for (Int_t j=0; j<nrows; j++)
     157            {
     158                weights[j] = matrixtrain.GetM()(j, ncols-nobs);
     159                if (j%100==0)
     160                    cout << weights[j] << " ";
     161            }
     162
     163        // Setup the matrix such that the last comlumn contains
     164        // the classifier or the regeression target value
    144165        switch (ver)
    145166        {
    146         case 0: // Replace last column by a classification
     167        case 0: // Replace last column by a classification which is 1 in
     168                // the case the event belongs to this bin, 0 otherwise
    147169            {
    148170                Int_t irows=0;
    149171                for (Int_t j=0; j<nrows; j++)
    150172                {
    151                     const Double_t energy = matrixtrain.GetM()(j,ncols-1);
    152                     const Bool_t   inside = energy>grid[ie] && energy<=grid[ie+1];
     173                    const Double_t value = matrixtrain.GetM()(j,ncols-1);
     174                    const Bool_t   inside = value>grid[ie] && value<=grid[ie+1];
    153175
    154176                    mat(j, ncols-nobs) = inside ? 1 : 0;
     
    162184                    *fLog << inf << "Training RF for";
    163185
    164                 *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;
     186                *fLog << " bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;
    165187
    166188                if (irows==0)
     
    191213        if (ver==1)
    192214            rf.SetGrid(grid);
     215        if (fLastDataColumnHasWeights)
     216            rf.SetWeights(weights);
    193217
    194218        plist.AddToList(&rf);
  • trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h

    r7425 r7687  
    4444
    4545    Int_t        fNumObsoleteVariables; //! Training parameters
     46    Bool_t       fLastDataColumnHasWeights; //! Training parameters
    4647
    4748    TString      fFileName;             // File name to forest
     
    8485    void SetDebug(Bool_t b=kTRUE)    { fDebug    = b; }
    8586
    86     void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
     87    void SetNumObsoleteVariables(Int_t n=1)          { fNumObsoleteVariables = n; }
     88    void SetLastDataColumnHasWeights(Bool_t b=kTRUE) { fLastDataColumnHasWeights = b; }
    8789
    8890    // Train Interface
  • trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc

    r7642 r7687  
    183183//------------------------------------------------------------------------
    184184//
     185// Function serving AddPreCuts, AddPreTasks and AddPostTasks
     186//
     187void MTFillMatrix::Add(const TList &src, const TClass *cls, TList &dest)
     188{
     189    TIter Next(&src);
     190    TObject *obj=0;
     191    while ((obj=Next()))
     192        if (obj->InheritsFrom(cls))
     193            dest.Add(obj);
     194}
     195
     196//------------------------------------------------------------------------
     197//
    185198// Add a cut which is used to fill the matrix, eg "MMcEvt.fOartId<1.5"
    186199// (The rule is applied, nit inverted: The matrix is filled with
     
    211224void MTFillMatrix::AddPreCuts(const TList &list)
    212225{
    213     TIter Next(&list);
    214     TObject *obj=0;
    215     while ((obj=Next()))
    216         if (obj->InheritsFrom(MFilter::Class()))
    217             fPreCuts.Add(obj);
     226    Add(list, MFilter::Class(), fPreCuts);
     227}
     228
     229//------------------------------------------------------------------------
     230//
     231// Add a task which is executed before the precuts. If kCanDelete is set
     232// MJOptimize takes the ownership.
     233//
     234void MTFillMatrix::AddPreTask(MTask *t)
     235{
     236    fPreTasks.Add(t);
     237}
     238
     239//------------------------------------------------------------------------
     240//
     241// Add all entries deriving from MTask from list to PreTasks.
     242// The ownership is not affected.
     243//
     244void MTFillMatrix::AddPreTasks(const TList &list)
     245{
     246    Add(list, MTask::Class(), fPreTasks);
     247}
     248
     249//------------------------------------------------------------------------
     250//
     251// Add a task which is executed after the precuts. If kCanDelete is set
     252// MJOptimize takes the ownership.
     253//
     254void MTFillMatrix::AddPostTask(MTask *t)
     255{
     256    fPostTasks.Add(t);
     257}
     258
     259//------------------------------------------------------------------------
     260//
     261// Add all entries deriving from MTask from list to PostTasks.
     262// The ownership is not affected.
     263//
     264void MTFillMatrix::AddPostTasks(const TList &list)
     265{
     266    Add(list, MTask::Class(), fPostTasks);
    218267}
    219268
     
    315364    MFillH fill1(fDestMatrix1);
    316365    MFillH fill2(fDestMatrix2);
    317     if (selector)
    318     {
    319         fill1.SetFilter(&split);
    320         fill2.SetFilter(&invsplit);
    321     }
     366    fill1.SetFilter(&split);
     367    fill2.SetFilter(&invsplit);
    322368
    323369    // entries in MTaskList
    324370    tlist.AddToList(fReader);        // Read events
     371    tlist.AddToList(fPreTasks);      // PreTasks
    325372    if (fPreCuts.GetEntries()>0)
    326373        tlist.AddToList(&cont0);     // PreCuts
     
    328375        tlist.AddToList(&cont);      // select a sample of events
    329376    tlist.AddToList(&invsplit);      // process invsplit (which implicitly processes split)
     377    tlist.AddToList(fPostTasks);     // PostTasks
    330378    if (fDestMatrix1)
    331379        tlist.AddToList(&fill1);     // fill matrix 1
  • trunk/MagicSoft/Mars/mtools/MTFillMatrix.h

    r7413 r7687  
    3131
    3232    TList     fPreCuts;
     33    TList     fPreTasks;
     34    TList     fPostTasks;
     35
     36    void Add(const TList &src, const TClass *cls, TList &dest);
    3337
    3438    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     
    8084    void AddPreCuts(const TList &list);
    8185
     86    void AddPreTask(MTask *t);
     87    void AddPreTasks(const TList &list);
     88
     89    void AddPostTask(MTask *t);
     90    void AddPostTasks(const TList &list);
     91
    8292    Bool_t Process(const MParList &plist=MParList());
    8393    Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
Note: See TracChangeset for help on using the changeset viewer.