Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:53

0001 // @(#)root/tmva $Id$
0002 // Author: Andreas Hoecker, Xavier Prudent, Joerg Stelzer, Helge Voss, Kai Voss
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : MethodFisher                                                          *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Analysis of Fisher discriminant (Fisher or Mahalanobis approach)          *
0012  *                                                                                *
0013  * Original author of this Fisher-Discriminant implementation:                    *
0014  *      Andre Gaidot, CEA-France;                                                 *
0015  *      (Translation from FORTRAN)                                                *
0016  *                                                                                *
0017  * Authors (alphabetical):                                                        *
0018  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
0019  *      Xavier Prudent  <prudent@lapp.in2p3.fr>  - LAPP, France                   *
0020  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
0021  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
0022  *                                                                                *
0023  * Copyright (c) 2005:                                                            *
0024  *      CERN, Switzerland                                                         *
0025  *      U. of Victoria, Canada                                                    *
0026  *      MPI-K Heidelberg, Germany                                                 *
0027  *      LAPP, Annecy, France                                                      *
0028  *                                                                                *
0029  * Redistribution and use in source and binary forms, with or without             *
0030  * modification, are permitted according to the terms listed in LICENSE           *
0031  * (see tmva/doc/LICENSE)                                          *
0032  **********************************************************************************/
0033 
0034 #ifndef ROOT_TMVA_MethodFisher
0035 #define ROOT_TMVA_MethodFisher
0036 
0037 //////////////////////////////////////////////////////////////////////////
0038 //                                                                      //
0039 // MethodFisher                                                         //
0040 //                                                                      //
0041 // Analysis of Fisher discriminant (Fisher or Mahalanobis approach)     //
0042 //                                                                      //
0043 //////////////////////////////////////////////////////////////////////////
0044 
0045 #include <vector>
0046 
0047 #include "TMVA/MethodBase.h"
0048 #include "TMatrixDfwd.h"
0049 
0050 class TH1D;
0051 
0052 namespace TMVA {
0053 
0054    class MethodFisher : public MethodBase {
0055 
0056    public:
0057 
0058       MethodFisher( const TString& jobName,
0059                     const TString& methodTitle,
0060                     DataSetInfo& dsi,
0061                     const TString& theOption = "Fisher");
0062 
0063       MethodFisher( DataSetInfo& dsi,
0064                     const TString& theWeightFile);
0065 
0066       virtual ~MethodFisher( void );
0067 
0068       virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
0069 
0070 
0071       // training method
0072       void Train( void );
0073 
0074       using MethodBase::ReadWeightsFromStream;
0075 
0076       // write weights to stream
0077       void AddWeightsXMLTo     ( void* parent ) const;
0078 
0079       // read weights from stream
0080       void ReadWeightsFromStream( std::istream & i );
0081       void ReadWeightsFromXML   ( void* wghtnode );
0082 
0083       // calculate the MVA value
0084       Double_t GetMvaValue( Double_t* err = nullptr, Double_t* errUpper = nullptr );
0085 
0086       enum EFisherMethod { kFisher, kMahalanobis };
0087       EFisherMethod GetFisherMethod( void ) { return fFisherMethod; }
0088 
0089       // ranking of input variables
0090       const Ranking* CreateRanking();
0091 
0092       // nice output
0093       void PrintCoefficients( void );
0094 
0095 
0096    protected:
0097 
0098       // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
0099       void MakeClassSpecific( std::ostream&, const TString& ) const;
0100 
0101       // get help message text
0102       void GetHelpMessage() const;
0103 
0104    private:
0105 
0106       // the option handling methods
0107       void DeclareOptions();
0108       void ProcessOptions();
0109 
0110       // Initialization and allocation of matrices
0111       void InitMatrices( void );
0112 
0113       // get mean value of variables
0114       void GetMean( void );
0115 
0116       // get matrix of covariance within class
0117       void GetCov_WithinClass( void );
0118 
0119       // get matrix of covariance between class
0120       void GetCov_BetweenClass( void );
0121 
0122       // and the full covariance matrix
0123       void GetCov_Full( void );
0124 
0125       // get discriminating power
0126       void GetDiscrimPower( void );
0127 
0128       // get Fisher coefficients
0129       void GetFisherCoeff( void );
0130 
0131       // matrix of variables means: S, B, S+B vs. variables
0132       TMatrixD *fMeanMatx;
0133 
0134       // method to be used
0135       TString       fTheMethod;       ///< Fisher or Mahalanobis
0136       EFisherMethod fFisherMethod;    ///< Fisher or Mahalanobis
0137 
0138       // covariance matrices
0139       TMatrixD *fBetw;                ///< between-class matrix
0140       TMatrixD *fWith;                ///< within-class matrix
0141       TMatrixD *fCov;                 ///< full covariance matrix
0142 
0143       // number of events (sumOfWeights)
0144       Double_t fSumOfWeightsS;        ///< sum-of-weights for signal training events
0145       Double_t fSumOfWeightsB;        ///< sum-of-weights for background training events
0146 
0147       std::vector<Double_t>* fDiscrimPow;  ///< discriminating power
0148       std::vector<Double_t>* fFisherCoeff; ///< Fisher coefficients
0149       Double_t fF0;                   ///< offset
0150 
0151       // default initialisation called by all constructors
0152       void Init( void );
0153 
0154       ClassDef(MethodFisher,0); // Analysis of Fisher discriminant (Fisher or Mahalanobis approach)
0155    };
0156 
0157 } // namespace TMVA
0158 
0159 #endif // MethodFisher_H