ROOT logo
// @(#)root/tmva $Id: MethodBoost.h 31458 2009-11-30 13:58:20Z stelzer $   
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss,Or Cohen 

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : MethodCompositeBase                                                   *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Virtual base class for all MVA method                                     *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker    <Andreas.Hocker@cern.ch> - CERN, Switzerland           *
 *      Joerg Stelzer      <Joerg.Stelzer@cern.ch>  - CERN, Switzerland           *
 *      Helge Voss         <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany   *
 *      Kai Voss           <Kai.Voss@cern.ch>       - U. of Victoria, Canada      *
 *      Or Cohen           <orcohenor@gmail.com>    - Weizmann Inst., Israel      *
 *      Eckhard v. Toerne  <evt@uni-bonn.de>        - U of Bonn, Germany          *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         * 
 *      U. of Victoria, Canada                                                    * 
 *      MPI-K Heidelberg, Germany                                                 * 
 *      LAPP, Annecy, France                                                      *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_MethodBoost
#define ROOT_TMVA_MethodBoost

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MethodBoost                                                          //
//                                                                      //
// Class for boosting a TMVA method                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <iosfwd>
#include <vector>

#ifndef ROOT_TMVA_MethodBase
#include "TMVA/MethodBase.h"
#endif

#ifndef ROOT_TMVA_MethodCompositeBase
#include "TMVA/MethodCompositeBase.h"
#endif

namespace TMVA {

   class MethodBoost : public MethodCompositeBase {

   public :

      // constructors
      MethodBoost( const TString& jobName,
                   const TString& methodTitle,
                   DataSetInfo& theData,
                   const TString& theOption = "",
                   TDirectory* theTargetDir = NULL );

      MethodBoost( DataSetInfo& dsi, 
                   const TString& theWeightFile,  
                   TDirectory* theTargetDir = NULL );      
      
      virtual ~MethodBoost( void );

      virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t /*numberTargets*/ );

      // training and boosting all the classifiers
      void Train( void );

      // ranking of input variables
      const Ranking* CreateRanking();
         
      // saves the name and options string of the boosted classifier
      Bool_t BookMethod( Types::EMVA theMethod, TString methodTitle, TString theOption );
      void SetBoostedMethodName ( TString methodName )     { fBoostedMethodName  = methodName; }

      Int_t          GetBoostNum() { return fBoostNum; }

      // gives the monitoring historgram from the vector according to index of the 
      // histrogram added in the MonitorBoost function
      TH1*           GetMonitoringHist( Int_t histInd ) { return (*fMonitorHist)[fDefaultHistNum+histInd]; }

      void           AddMonitoringHist( TH1* hist )     { return fMonitorHist->push_back(hist); }

      Types::EBoostStage    GetBoostStage() { return fBoostStage; }

      void CleanBoostOptions();

      Double_t GetMvaValue( Double_t* err );

   private :
      // clean up 
      void ClearAll();

      // print fit results
      void PrintResults( const TString&, std::vector<Double_t>&, const Double_t ) const;

      // initializing mostly monitoring tools of the boost process
      void Init();
      void InitHistos();
      void CheckSetup();

      // the option handling methods
      void DeclareOptions();
      void ProcessOptions();

      MethodBoost* SetStage( Types::EBoostStage stage ) { fBoostStage = stage; return this; }

      //training a single classifier
      void SingleTrain();

      //calculating a boosting weight from the classifier, storing it in the next one
      void SingleBoost();

      //writing the monitoring histograms and tree to a file
      void WriteMonitoringHistosToFile( void ) const;

      // write evaluation histograms into target file
      virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype);

      // performs the MethodBase testing + testing of each boosted classifier
      virtual void TestClassification();

      //finding the MVA to cut between sig and bgd according to fMVACutPerc,fMVACutType
      void FindMVACut();

      //setting all the boost weights to 1
      void ResetBoostWeights();

      //creating the vectors of histogram for monitoring MVA response of each classifier
      void CreateMVAHistorgrams();

      //Number of times the classifier is boosted (set by the user)
      Int_t             fBoostNum;
      // string specifying the boost type (AdaBoost / Bagging )
      TString           fBoostType; 

      // string specifying the boost type ( ByError,Average,LastMethod )
      TString           fMethodWeightType;

      //estimation of the level error of the classifier analysing the train dataset
      Double_t          fMethodError;
      //estimation of the level error of the classifier analysing the train dataset (with unboosted weights)
      Double_t          fOrigMethodError;

      //the weight used to boost the next classifier
      Double_t          fBoostWeight;

      // min and max values for the classifier response
      TString fTransformString;

      //ADA boost parameter, default is 1
      Double_t          fADABoostBeta;

      // details of the boosted classifier
      TString           fBoostedMethodName;
      TString           fBoostedMethodTitle;
      TString           fBoostedMethodOptions;

      // histograms to monitor values during the boosting
      std::vector<TH1*>* fMonitorHist;

      //whether to monitor the MVA response of every classifier using the
      Bool_t                fMonitorBoostedMethod;

      //MVA output from each classifier over the training hist, using orignal events weights
      std::vector< TH1* >   fTrainSigMVAHist;
      std::vector< TH1* >   fTrainBgdMVAHist;
      //MVA output from each classifier over the training hist, using boosted events weights
      std::vector< TH1* >   fBTrainSigMVAHist;
      std::vector< TH1* >   fBTrainBgdMVAHist;
      //MVA output from each classifier over the testing hist
      std::vector< TH1* >   fTestSigMVAHist;
      std::vector< TH1* >   fTestBgdMVAHist;

      // tree  to monitor values during the boosting
      TTree*            fMonitorTree;

      // the stage of the boosting 
      Types::EBoostStage fBoostStage;

      //the number of histogram filled for every type of boosted classifier
      Int_t             fDefaultHistNum;

      //whether to recalculate the MVA cut at every boosting step
      Bool_t            fRecalculateMVACut;

   protected:

      // get help message text
      void GetHelpMessage() const;

      ClassDef(MethodBoost,0)
   };
}

#endif
 MethodBoost.h:1
 MethodBoost.h:2
 MethodBoost.h:3
 MethodBoost.h:4
 MethodBoost.h:5
 MethodBoost.h:6
 MethodBoost.h:7
 MethodBoost.h:8
 MethodBoost.h:9
 MethodBoost.h:10
 MethodBoost.h:11
 MethodBoost.h:12
 MethodBoost.h:13
 MethodBoost.h:14
 MethodBoost.h:15
 MethodBoost.h:16
 MethodBoost.h:17
 MethodBoost.h:18
 MethodBoost.h:19
 MethodBoost.h:20
 MethodBoost.h:21
 MethodBoost.h:22
 MethodBoost.h:23
 MethodBoost.h:24
 MethodBoost.h:25
 MethodBoost.h:26
 MethodBoost.h:27
 MethodBoost.h:28
 MethodBoost.h:29
 MethodBoost.h:30
 MethodBoost.h:31
 MethodBoost.h:32
 MethodBoost.h:33
 MethodBoost.h:34
 MethodBoost.h:35
 MethodBoost.h:36
 MethodBoost.h:37
 MethodBoost.h:38
 MethodBoost.h:39
 MethodBoost.h:40
 MethodBoost.h:41
 MethodBoost.h:42
 MethodBoost.h:43
 MethodBoost.h:44
 MethodBoost.h:45
 MethodBoost.h:46
 MethodBoost.h:47
 MethodBoost.h:48
 MethodBoost.h:49
 MethodBoost.h:50
 MethodBoost.h:51
 MethodBoost.h:52
 MethodBoost.h:53
 MethodBoost.h:54
 MethodBoost.h:55
 MethodBoost.h:56
 MethodBoost.h:57
 MethodBoost.h:58
 MethodBoost.h:59
 MethodBoost.h:60
 MethodBoost.h:61
 MethodBoost.h:62
 MethodBoost.h:63
 MethodBoost.h:64
 MethodBoost.h:65
 MethodBoost.h:66
 MethodBoost.h:67
 MethodBoost.h:68
 MethodBoost.h:69
 MethodBoost.h:70
 MethodBoost.h:71
 MethodBoost.h:72
 MethodBoost.h:73
 MethodBoost.h:74
 MethodBoost.h:75
 MethodBoost.h:76
 MethodBoost.h:77
 MethodBoost.h:78
 MethodBoost.h:79
 MethodBoost.h:80
 MethodBoost.h:81
 MethodBoost.h:82
 MethodBoost.h:83
 MethodBoost.h:84
 MethodBoost.h:85
 MethodBoost.h:86
 MethodBoost.h:87
 MethodBoost.h:88
 MethodBoost.h:89
 MethodBoost.h:90
 MethodBoost.h:91
 MethodBoost.h:92
 MethodBoost.h:93
 MethodBoost.h:94
 MethodBoost.h:95
 MethodBoost.h:96
 MethodBoost.h:97
 MethodBoost.h:98
 MethodBoost.h:99
 MethodBoost.h:100
 MethodBoost.h:101
 MethodBoost.h:102
 MethodBoost.h:103
 MethodBoost.h:104
 MethodBoost.h:105
 MethodBoost.h:106
 MethodBoost.h:107
 MethodBoost.h:108
 MethodBoost.h:109
 MethodBoost.h:110
 MethodBoost.h:111
 MethodBoost.h:112
 MethodBoost.h:113
 MethodBoost.h:114
 MethodBoost.h:115
 MethodBoost.h:116
 MethodBoost.h:117
 MethodBoost.h:118
 MethodBoost.h:119
 MethodBoost.h:120
 MethodBoost.h:121
 MethodBoost.h:122
 MethodBoost.h:123
 MethodBoost.h:124
 MethodBoost.h:125
 MethodBoost.h:126
 MethodBoost.h:127
 MethodBoost.h:128
 MethodBoost.h:129
 MethodBoost.h:130
 MethodBoost.h:131
 MethodBoost.h:132
 MethodBoost.h:133
 MethodBoost.h:134
 MethodBoost.h:135
 MethodBoost.h:136
 MethodBoost.h:137
 MethodBoost.h:138
 MethodBoost.h:139
 MethodBoost.h:140
 MethodBoost.h:141
 MethodBoost.h:142
 MethodBoost.h:143
 MethodBoost.h:144
 MethodBoost.h:145
 MethodBoost.h:146
 MethodBoost.h:147
 MethodBoost.h:148
 MethodBoost.h:149
 MethodBoost.h:150
 MethodBoost.h:151
 MethodBoost.h:152
 MethodBoost.h:153
 MethodBoost.h:154
 MethodBoost.h:155
 MethodBoost.h:156
 MethodBoost.h:157
 MethodBoost.h:158
 MethodBoost.h:159
 MethodBoost.h:160
 MethodBoost.h:161
 MethodBoost.h:162
 MethodBoost.h:163
 MethodBoost.h:164
 MethodBoost.h:165
 MethodBoost.h:166
 MethodBoost.h:167
 MethodBoost.h:168
 MethodBoost.h:169
 MethodBoost.h:170
 MethodBoost.h:171
 MethodBoost.h:172
 MethodBoost.h:173
 MethodBoost.h:174
 MethodBoost.h:175
 MethodBoost.h:176
 MethodBoost.h:177
 MethodBoost.h:178
 MethodBoost.h:179
 MethodBoost.h:180
 MethodBoost.h:181
 MethodBoost.h:182
 MethodBoost.h:183
 MethodBoost.h:184
 MethodBoost.h:185
 MethodBoost.h:186
 MethodBoost.h:187
 MethodBoost.h:188
 MethodBoost.h:189
 MethodBoost.h:190
 MethodBoost.h:191
 MethodBoost.h:192
 MethodBoost.h:193
 MethodBoost.h:194
 MethodBoost.h:195
 MethodBoost.h:196
 MethodBoost.h:197
 MethodBoost.h:198
 MethodBoost.h:199
 MethodBoost.h:200
 MethodBoost.h:201
 MethodBoost.h:202
 MethodBoost.h:203
 MethodBoost.h:204
 MethodBoost.h:205