ROOT logo
// @(#)root/tmva $Id: MethodCommittee.h 29122 2009-06-22 06:51:30Z brun $ 
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : MethodCommittee                                                       *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Boosting                                                                  *
 *                                                                                *
 * 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      *
 *                                                                                *
 * 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_MethodCommittee
#define ROOT_TMVA_MethodCommittee

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MethodCommittee                                                      //
//                                                                      //
// Committee method                                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <vector>
#include <iosfwd>
#ifndef ROOT_TH2
#include "TH2.h"
#endif
#ifndef ROOT_TTree
#include "TTree.h"
#endif

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

namespace TMVA {

   class MethodCommittee : public MethodBase {

   public:

      // constructor for training and reading
      MethodCommittee( const TString& jobName,
                       const TString& methodTitle,
                       DataSetInfo& dsi, 
                       const TString& theOption,
                       TDirectory* theTargetDir = 0 );

      // constructor for calculating Committee-MVA using previously generatad members
      MethodCommittee( DataSetInfo& theData, 
                       const TString& theWeightFile,  
                       TDirectory* theTargetDir = 0 );
  
      virtual ~MethodCommittee( void );
    
      virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );

      // overloaded members from MethodBase
      void WriteStateToFile() const;

      // the training
      void Train();

      using MethodBase::WriteWeightsToStream;
      using MethodBase::ReadWeightsFromStream;

      // write weights to file
      void WriteWeightsToStream( ostream& o ) const;
      void AddWeightsXMLTo( void* parent ) const;

      // read weights from file
      void ReadWeightsFromStream( istream& istr );
      void ReadWeightsFromXML   ( void* /*wghtnode*/ ) {}

      // write method specific histos to target file
      void WriteMonitoringHistosToFile( void ) const;

      // calculate the MVA value
      Double_t GetMvaValue( Double_t* err = 0 );

      // apply the boost algorithm to a member in the committee
      Double_t Boost(  TMVA::MethodBase*, UInt_t imember );

      // ranking of input variables
      const Ranking* CreateRanking();

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

      // accessors
      const std::vector<TMVA::IMethod*>& GetCommittee()    const { return fCommittee; }
      const std::vector<Double_t>&       GetBoostWeights() const { return fBoostWeights; }

      //return the individual relative variable importance 
      std::vector<Double_t> GetVariableImportance();
      Double_t GetVariableImportance( UInt_t ivar );

   protected:

      // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
      void MakeClassSpecific( std::ostream&, const TString& ) const;

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

   private:

      // accessors
      std::vector<IMethod*>& GetCommittee()    { return fCommittee; }
      std::vector<Double_t>& GetBoostWeights() { return fBoostWeights; }

      // boosting algorithm (adaptive boosting)
      Double_t AdaBoost( MethodBase* );
 
      // boosting as a random re-weighting
      Double_t Bagging( UInt_t imember);
  
      UInt_t                          fNMembers;        // number of members requested
      std::vector<IMethod*>           fCommittee;       // the collection of members
      std::vector<Double_t>           fBoostWeights;    // the weights applied in the individual boosts
      TString                         fBoostType;       // string specifying the boost type

      // options for the MVA method
      Types::EMVA                     fMemberType;      // the MVA method to be boosted
      TString                         fMemberOption;    // the options for that method

      Bool_t                          fUseMemberDecision;  // use binary information from IsSignal
      // use average classification from the members, or have the individual members 
      
      Bool_t                          fUseWeightedMembers; // in the committee weighted from AdaBoost
    

      // Init used in the various constructors
      void Init( void );

      //some histograms for monitoring
      TH1F*                           fBoostFactorHist; // weights applied in boosting
      TH2F*                           fErrFractHist;    // error fraction vs member number
      TTree*                          fMonitorNtuple;   // monitoring ntuple
      Int_t                           fITree      ;     // ntuple var: ith member
      Double_t                        fBoostFactor;     // ntuple var: boost weight
      Double_t                        fErrorFraction;   // ntuple var: misclassification error fraction 
      Int_t                           fNnodes;          // ntuple var: nNodes

      std::vector< Double_t >         fVariableImportance; // the relative importance of the different variables 

      ClassDef(MethodCommittee,0)  // Analysis of Boosted MVA methods
   };

} // namespace TMVA

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