Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:00

0001 // @(#)root/tmva $Id$
0002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss,Or Cohen, Jan Therhaag, Eckhard von Toerne
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : MethodCompositeBase                                                   *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Virtual base class for all MVA method                                     *
0012  *                                                                                *
0013  * Authors (alphabetical):                                                        *
0014  *      Andreas Hoecker    <Andreas.Hocker@cern.ch>   - CERN, Switzerland         *
0015  *      Peter Speckmayer   <Peter.Speckmazer@cern.ch> - CERN, Switzerland         *
0016  *      Joerg Stelzer      <Joerg.Stelzer@cern.ch>    - CERN, Switzerland         *
0017  *      Helge Voss         <Helge.Voss@cern.ch>       - MPI-K Heidelberg, Germany *
0018  *      Jan Therhaag       <Jan.Therhaag@cern.ch>     - U of Bonn, Germany        *
0019  *      Eckhard v. Toerne  <evt@uni-bonn.de>          - U of Bonn, Germany        *
0020  *                                                                                *
0021  * Copyright (c) 2005-2011:                                                       *
0022  *      CERN, Switzerland                                                         *
0023  *      U. of Victoria, Canada                                                    *
0024  *      MPI-K Heidelberg, Germany                                                 *
0025  *      U. of Bonn, Germany                                                       *
0026  *                                                                                *
0027  * Redistribution and use in source and binary forms, with or without             *
0028  * modification, are permitted according to the terms listed in LICENSE           *
0029  * (see tmva/doc/LICENSE)                                          *
0030  **********************************************************************************/
0031 
0032 #ifndef ROOT_TMVA_MethodBoost
0033 #define ROOT_TMVA_MethodBoost
0034 
0035 //////////////////////////////////////////////////////////////////////////
0036 //                                                                      //
0037 // MethodBoost                                                          //
0038 //                                                                      //
0039 // Class for boosting a TMVA method                                     //
0040 //                                                                      //
0041 //////////////////////////////////////////////////////////////////////////
0042 
0043 #include <iosfwd>
0044 #include <vector>
0045 
0046 #include "TMVA/MethodBase.h"
0047 
0048 #include "TMVA/MethodCompositeBase.h"
0049 
0050 namespace TMVA {
0051 
0052    class Factory;  // DSMTEST
0053    class Reader;   // DSMTEST
0054    class DataSetManager;  // DSMTEST
0055    namespace Experimental {
0056    class Classification;
0057    }
0058    class MethodBoost : public MethodCompositeBase {
0059       friend class Factory; // DSMTEST
0060       friend class Reader;  // DSMTEST
0061       friend class Experimental::Classification;
0062 
0063    public :
0064 
0065       // constructors
0066       MethodBoost( const TString& jobName,
0067                    const TString& methodTitle,
0068                    DataSetInfo& theData,
0069                    const TString& theOption = "" );
0070 
0071       MethodBoost( DataSetInfo& dsi,
0072                    const TString& theWeightFile );
0073 
0074       virtual ~MethodBoost( void );
0075 
0076       virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t /*numberTargets*/ );
0077 
0078       // training and boosting all the classifiers
0079       void Train( void );
0080 
0081       // ranking of input variables
0082       const Ranking* CreateRanking();
0083 
0084       // saves the name and options string of the boosted classifier
0085       Bool_t BookMethod( Types::EMVA theMethod, TString methodTitle, TString theOption );
0086       void SetBoostedMethodName ( TString methodName )     { fBoostedMethodName  = methodName; }
0087 
0088       Int_t          GetBoostNum() { return fBoostNum; }
0089 
0090       void CleanBoostOptions();
0091 
0092       Double_t GetMvaValue( Double_t* err = nullptr, Double_t* errUpper = nullptr );
0093 
0094    private :
0095       // clean up
0096       void ClearAll();
0097 
0098       // print fit results
0099       void PrintResults( const TString&, std::vector<Double_t>&, const Double_t ) const;
0100 
0101       // initializing mostly monitoring tools of the boost process
0102       void Init();
0103       void InitHistos();
0104       void CheckSetup();
0105 
0106       void MonitorBoost( Types::EBoostStage stage, UInt_t methodIdx=0);
0107 
0108       // the option handling methods
0109       void DeclareOptions();
0110       void DeclareCompatibilityOptions();
0111       void ProcessOptions();
0112 
0113 
0114       MethodBase*  CurrentMethod(){return fCurrentMethod;}
0115       UInt_t       CurrentMethodIdx(){return fCurrentMethodIdx;}
0116       // training a single classifier
0117       void SingleTrain();
0118 
0119       // calculating a boosting weight from the classifier, storing it in the next one
0120       Double_t SingleBoost(MethodBase* method);
0121       Double_t AdaBoost(MethodBase* method, Bool_t useYesNoLeaf );
0122       Double_t Bagging();
0123 
0124 
0125       // calculate weight of single method
0126       Double_t CalcMethodWeight();
0127 
0128       // return ROC integral on training/testing sample
0129       Double_t GetBoostROCIntegral(Bool_t, Types::ETreeType, Bool_t CalcOverlapIntergral=kFALSE);
0130 
0131       // writing the monitoring histograms and tree to a file
0132       void WriteMonitoringHistosToFile( void ) const;
0133 
0134       // write evaluation histograms into target file
0135       virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype);
0136 
0137       // performs the MethodBase testing + testing of each boosted classifier
0138       virtual void TestClassification();
0139 
0140       // finding the MVA to cut between sig and bgd according to fMVACutPerc,fMVACutType
0141       void FindMVACut(MethodBase* method);
0142 
0143       // setting all the boost weights to 1
0144       void ResetBoostWeights();
0145 
0146       // creating the vectors of histogram for monitoring MVA response of each classifier
0147       void CreateMVAHistorgrams();
0148 
0149       // calculate MVA values of current trained method on training
0150       // sample
0151       void CalcMVAValues();
0152 
0153       UInt_t                 fBoostNum;             ///< Number of times the classifier is boosted
0154       TString                fBoostType;            ///< string specifying the boost type
0155 
0156       TString                fTransformString;      ///< min and max values for the classifier response
0157       Bool_t                 fDetailedMonitoring;   ///< produce detailed monitoring histograms (boost-wise)
0158 
0159       Double_t               fAdaBoostBeta;         ///< ADA boost parameter, default is 1
0160       UInt_t                 fRandomSeed;           ///< seed for random number generator used for bagging
0161       Double_t               fBaggedSampleFraction; ///< rel.Size of bagged sample
0162 
0163       TString                fBoostedMethodName;    ///< details of the boosted classifier
0164       TString                fBoostedMethodTitle;   ///< title
0165       TString                fBoostedMethodOptions; ///< options
0166 
0167       Bool_t                 fMonitorBoostedMethod; ///< monitor the MVA response of every classifier
0168 
0169       // MVA output from each classifier over the training hist, using orignal events weights
0170       std::vector< TH1* >   fTrainSigMVAHist;
0171       std::vector< TH1* >   fTrainBgdMVAHist;
0172       // MVA output from each classifier over the training hist, using boosted events weights
0173       std::vector< TH1* >   fBTrainSigMVAHist;
0174       std::vector< TH1* >   fBTrainBgdMVAHist;
0175       // MVA output from each classifier over the testing hist
0176       std::vector< TH1* >   fTestSigMVAHist;
0177       std::vector
0178          < TH1* >   fTestBgdMVAHist;
0179 
0180       //monitoring tree/ntuple and it's variables
0181       TTree*                fMonitorTree;     ///< tree  to monitor values during the boosting
0182       Double_t              fBoostWeight;     ///< the weight used to boost the next classifier
0183       Double_t              fMethodError;     ///< estimation of the level error of the classifier
0184       // analysing the train dataset
0185       Double_t           fROC_training;       ///< roc integral of last trained method (on training sample)
0186 
0187       // overlap integral of mva distributions for signal and
0188       // background (training sample)
0189       Double_t           fOverlap_integral;
0190 
0191       std::vector<Float_t> *fMVAvalues;       ///< mva values for the last trained method
0192 
0193       DataSetManager*    fDataSetManager;     ///< DSMTEST
0194       TString fHistoricOption;                ///< historic variable, only needed for "CompatibilityOptions"
0195       Bool_t fHistoricBoolOption;             ///< historic variable, only needed for "CompatibilityOptions"
0196 
0197    protected:
0198 
0199       // get help message text
0200       void GetHelpMessage() const;
0201 
0202       ClassDef(MethodBoost,0);
0203    };
0204 }
0205 
0206 #endif