Changeset 8643


Ignore:
Timestamp:
07/19/07 19:59:27 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8642 r8643  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21
     22 2007/07/19 Thomas Bretz
     23
     24   * mjobs/MJCut.cc:
     25     - added a sanity check for one off-position in on/off-mode
     26
     27   * mjoptim/MJOptimize.[h,cc]:
     28     - moved the functions and data-members to set cuts etc to new
     29       base class
     30     - added setting of pre- and post-tasks to reading the data
     31
     32   * mjoptim/Makefile, mjoptim/OptimLinkDef.h:
     33     - added new MJOptimizeBase
     34
     35   * mjtrain/MJTrainDisp.cc, mjtrain/MJTrainEnergy.cc,
     36     mjtrain/MJTrainSeparation.cc:
     37     - changed to use fDebug and WriteDisplay from the new base class
     38
     39   * mjtrain/MJTrainRanForest.[h,cc]:
     40     - moved all data members and setting of pre-/posttasks/-cuts
     41       to new base class
     42
     43   * mjtrain/Makefile:
     44     - added include of mjoptim for new base class
     45
     46   * mjoptim/MJOptimizeBase.[h,cc]:
     47     - new base class for optimization and training classes
     48
     49
    2050
    2151
  • trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc

    r8244 r8643  
    111111#include "MMatrixLoop.h"
    112112#include "MFillH.h"
     113#include "MParameterCalc.h"
     114#include "MContinue.h"
    113115
    114116// filters
     
    225227}
    226228
    227 MJOptimize::MJOptimize() : fDebug(-1), fNumEvents(0), fType(kSimplex), fNumMaxCalls(0), fTolerance(0), fTestTrain(0), fNameMinimizationValue("MinimizationValue")
     229MJOptimize::MJOptimize() : /*fDebug(-1),*/ fNumEvents(0), fType(kSimplex), fNumMaxCalls(0), fTolerance(0), fTestTrain(0), fNameMinimizationValue("MinimizationValue")
    228230{
    229231    fRules.SetOwner();
     
    287289}
    288290
    289 //------------------------------------------------------------------------
    290 //
    291 // Add a parameter used in your filters (see AddFilter) The parameter
    292 // index is returned,
    293 //
    294 //   Int_t idx = AddParameter("log10(MHillas.fSize)");
    295 //
    296 // The indices area starting with 0 always.
    297 //
    298 Int_t MJOptimize::AddParameter(const char *rule)
    299 {
    300     fRules.Add(new TNamed(rule, ""));
    301     return fRules.GetSize()-1;
    302 }
    303291
    304292//------------------------------------------------------------------------
     
    319307{
    320308    fFilter.Add(new MFDataPhrase(rule));
    321 }
    322 
    323 //------------------------------------------------------------------------
    324 //
    325 // Add a cut which is used to fill the matrix, eg "MMcEvt.fOartId<1.5"
    326 // (The rule is applied, nit inverted: The matrix is filled with
    327 // the events fullfilling the condition)
    328 //
    329 void MJOptimize::AddPreCut(const char *rule)
    330 {
    331     MFilter *f = new MFDataPhrase(rule);
    332     f->SetBit(kCanDelete);
    333     AddPreCut(f);
    334 }
    335 
    336 //------------------------------------------------------------------------
    337 //
    338 // Add a cut which is used to fill the matrix. If kCanDelete is set
    339 // MJOptimize takes the ownership.
    340 //
    341 void MJOptimize::AddPreCut(MFilter *f)
    342 {
    343     fPreCuts.Add(f);
    344309}
    345310
     
    739704    m->Print("cols");
    740705
    741     //MParList parlist;
    742 
    743706    //    MGeomCamMagic cam;
    744707    //    parlist.AddToList(&cam);
    745708
    746     MTaskList tlist;
    747     parlist.Replace(&tlist);
    748 
    749     MFillH fillh(m);
    750 
    751     tlist.AddToList(&read);
    752 
     709    // Setup filter and apply filter to filling of matrix
    753710    MFilterList list;
    754711    if (!list.AddToList(fPreCuts))
     
    757714        SetupFilters(list);
    758715    list.SetName("PreCuts");  // reset Name      set by SetupFilters
    759     list.SetInverted(kFALSE); // reset inversion set by SetupFilters
    760     fillh.SetFilter(&list);
    761     tlist.AddToList(&list);
    762 
    763     tlist.AddToList(&fillh);
     716    list.SetInverted(kTRUE);  // reset inversion set by SetupFilters
     717
     718    MContinue cont(&list);
     719
     720    // Setup filling of matrix
     721    MFillH fillh(m);
     722
     723    // Setup tasklist
     724    MTaskList tlist;
     725    parlist.Replace(&tlist);
     726
     727    // Create task list
     728    tlist.AddToList(&read);        // read data
     729    tlist.AddToList(fPreTasks);    // execute pre-filter tasks
     730    tlist.AddToList(&cont);        // execute filters
     731    tlist.AddToList(fPostTasks);   // execute post-filter tasks
     732    tlist.AddToList(&fillh);       // Fill matrix
    764733
    765734    tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
  • trunk/MagicSoft/Mars/mjoptim/MJOptimize.h

    r7152 r8643  
    22#define MARS_MJOptimize
    33
    4 #ifndef MARS_MJob
    5 #include "MJob.h"
     4#ifndef MARS_MJOptimizeBase
     5#include "MJOptimizeBase.h"
    66#endif
    77
     
    1414class MAlphaFitter;
    1515
     16class MTask;
    1617class MEvtLoop;
    1718class MParList;
     
    2627class MReadTree;
    2728
    28 class MJOptimize : public MJob
     29class MJOptimize : public MJOptimizeBase
    2930{
    3031public:
     
    4142
    4243private:
    43     Int_t fDebug;     // -1 no output, 0 MJOptimize output, 1 PrintStatistics output
    4444    Int_t fNumEvents;
    4545
    46     TList fRules;
    4746    TList fFilter;
    4847
     
    7877
    7978protected:
    80     TList   fPreCuts;
    81 
    8279    TList   fNamesOn;
    8380    TList   fNamesOff;
     
    10097
    10198    // Interface for filter cuts
    102     Int_t AddParameter(const char *rule);
    10399    void AddFilter(const char *rule);
    104     void AddPreCut(const char *rule);
    105     void AddPreCut(MFilter *f);
    106100
    107101    // Steering of optimization
  • trunk/MagicSoft/Mars/mjoptim/Makefile

    r7152 r8643  
    2929# mgeom:     MGeomCam
    3030
    31 SRCFILES = MJOptimize.cc \
     31SRCFILES = MJOptimizeBase.cc \
     32           MJOptimize.cc \
    3233           MJOptimizeCuts.cc \
    3334           MJOptimizeDisp.cc \
  • trunk/MagicSoft/Mars/mjoptim/OptimLinkDef.h

    r7152 r8643  
    66
    77#pragma link C++ class MJOptimize+;
     8#pragma link C++ class MJOptimizeBase+;
    89#pragma link C++ class MJOptimizeCuts+;
    910#pragma link C++ class MJOptimizeDisp+;
  • trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc

    r8244 r8643  
    145145    rf.SetLogStream(fLog);
    146146    rf.SetFileName(out);
    147     rf.SetDebug(fDebug);
     147    rf.SetDebug(fDebug>1);
    148148    rf.SetNameOutput("Disp");
    149149
     
    251251    hist.GetAlphaFitter().Print("result");
    252252
    253     if (!WriteDisplay(out))
     253    if (!WriteDisplay(out, "UPDATE"))
    254254        return kFALSE;
    255255
  • trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc

    r8636 r8643  
    139139    rf.SetLogStream(fLog);
    140140    rf.SetFileName(out);
    141     rf.SetDebug(fDebug);
     141    rf.SetDebug(fDebug>1);
    142142    rf.SetNameOutput("MEnergyEst");
    143143
     
    193193        return kFALSE;
    194194
    195     if (!WriteDisplay(out))
     195    if (!WriteDisplay(out, "UPDATE"))
    196196        return kFALSE;
    197197
  • trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc

    r8091 r8643  
    1818!   Author(s): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2005-2006
     20!   Copyright: MAGIC Software Development, 2005-2007
    2121!
    2222!
     
    2828//
    2929// Base class for classes training a random forest
     30//
     31// The order when reading a file is:
     32//   1) Execution of PreTasks  (set by user)
     33//   2) Execution of PreCuts   (set by user)
     34//   3) Selector               (calculated from number of requested events)
     35//   4) Splitter               (if sample is split automatically in test/train)
     36//   5) PostTasks              (set by user)
     37//
     38// The split into Pre- and PostTasks is done for speed reason. So, if
     39// you calculate a vlue which is not needed for your PreCuts, you can
     40// calculate it afterwards, which will speed up execution.
    3041//
    3142/////////////////////////////////////////////////////////////////////////////
     
    4556
    4657using namespace std;
    47 
     58/*
    4859//------------------------------------------------------------------------
    4960//
     
    120131    return kTRUE;
    121132}
     133*/
  • trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.h

    r7697 r8643  
    22#define MARS_MJTrainRanForest
    33
    4 #ifndef MARS_MJob
    5 #include "MJob.h"
     4#ifndef MARS_MJOptimizeBase
     5#include "MJOptimizeBase.h"
    66#endif
    77
     
    99class MFilter;
    1010
    11 class MJTrainRanForest : public MJob
     11class MJTrainRanForest : public MJOptimizeBase
    1212{
    1313protected:
    14     Bool_t fDebug;
    15     Bool_t fEnableWeights;
    16 
    17     TList fRules;
    18 
    19     TList fPreCuts;
    20     TList fTrainCuts;
    21     TList fTestCuts;
    22     TList fPreTasks;
    23     TList fPostTasks;
    24 
    2514    UShort_t fNumTrees;
    2615    UShort_t fNdSize;
    2716    UShort_t fNumTry;
    2817
    29     Bool_t WriteDisplay(const char *fname) const;
    30 
    31     void AddCut(TList &l, const char *rule);
    32     void AddPar(TList &l, const char *rule, const char *name);
    33     void Add(TList &l, MTask *f);
    34 
    3518public:
    36     MJTrainRanForest() : fDebug(kFALSE), fEnableWeights(kFALSE)
     19    MJTrainRanForest()
    3720    {
    3821        fNumTrees = 100; //100
     
    4124    }
    4225
    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);    }
    55 
    56     void AddPreCut(const char *rule)   { AddCut(fPreCuts, rule); }
    57     void AddPreCut(MFilter *f)         { Add(fPreCuts, (MTask*)(f)); }
    58 
    59     void AddTrainCut(const char *rule) { AddCut(fTrainCuts, rule); }
    60     void AddTrainCut(MFilter *f)       { Add(fTrainCuts, (MTask*)(f)); }
    61 
    62     void AddTestCut(const char *rule)  { AddCut(fTestCuts, rule); }
    63     void AddTestCut(MFilter *f)        { Add(fTestCuts, (MTask*)(f)); }
    64 
    6526    void SetNumTrees(UShort_t n=100)   { fNumTrees = n; }
    6627    void SetNdSize(UShort_t n=5)       { fNdSize   = n; }
    6728    void SetNumTry(UShort_t n=0)       { fNumTry   = n; }
    68 
    69     Int_t AddParameter(const char *rule);
    7029
    7130    ClassDef(MJTrainRanForest, 0)//Base class for Random Forest training classes
  • trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc

    r8223 r8643  
    802802    rf.SetNumObsoleteVariables(1);
    803803    rf.SetLastDataColumnHasWeights(fEnableWeights[kTrainOn] || fEnableWeights[kTrainOff]);
    804     rf.SetDebug(fDebug);
     804    rf.SetDebug(fDebug>1);
    805805    rf.SetDisplay(fDisplay);
    806806    rf.SetLogStream(fLog);
     
    10391039
    10401040    // Write the display
    1041     if (!WriteDisplay(out))
     1041    if (!WriteDisplay(out, "UPDATE"))
    10421042        return kFALSE;
    10431043
  • trunk/MagicSoft/Mars/mjtrain/Makefile

    r7702 r8643  
    2222           -I../manalysis -I../mfilter -I../mjobs -I../mtools \
    2323           -I../mranforest -I../mhflux -I../mmc -I../mhist -I../mpointing \
    24            -I../mimage
     24           -I../mimage -I../mjoptim
    2525
    2626SRCFILES = MJTrainRanForest.cc \
Note: See TracChangeset for help on using the changeset viewer.