MethodFisher.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: MethodFisher.h 36966 2010-11-26 09:50:13Z evt $
00002 // Author: Andreas Hoecker, Xavier Prudent, Joerg Stelzer, Helge Voss, Kai Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : MethodFisher                                                          *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Analysis of Fisher discriminant (Fisher or Mahalanobis approach)          *
00012  *                                                                                *
00013  * Original author of this Fisher-Discriminant implementation:                    *
00014  *      Andre Gaidot, CEA-France;                                                 *
00015  *      (Translation from FORTRAN)                                                *
00016  *                                                                                *
00017  * Authors (alphabetical):                                                        *
00018  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00019  *      Xavier Prudent  <prudent@lapp.in2p3.fr>  - LAPP, France                   *
00020  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00021  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00022  *                                                                                *
00023  * Copyright (c) 2005:                                                            *
00024  *      CERN, Switzerland                                                         *
00025  *      U. of Victoria, Canada                                                    *
00026  *      MPI-K Heidelberg, Germany                                                 *
00027  *      LAPP, Annecy, France                                                      *
00028  *                                                                                *
00029  * Redistribution and use in source and binary forms, with or without             *
00030  * modification, are permitted according to the terms listed in LICENSE           *
00031  * (http://tmva.sourceforge.net/LICENSE)                                          *
00032  **********************************************************************************/
00033 
00034 #ifndef ROOT_TMVA_MethodFisher
00035 #define ROOT_TMVA_MethodFisher
00036 
00037 //////////////////////////////////////////////////////////////////////////
00038 //                                                                      //
00039 // MethodFisher                                                         //
00040 //                                                                      //
00041 // Analysis of Fisher discriminant (Fisher or Mahalanobis approach)     //
00042 //                                                                      //
00043 //////////////////////////////////////////////////////////////////////////
00044 
00045 #include <vector>
00046 
00047 #ifndef ROOT_TMVA_MethodBase
00048 #include "TMVA/MethodBase.h"
00049 #endif
00050 #ifndef ROOT_TMatrixDfwd
00051 #include "TMatrixDfwd.h"
00052 #endif
00053 
00054 class TH1D;
00055 
00056 namespace TMVA {
00057 
00058    class MethodFisher : public MethodBase {
00059 
00060    public:
00061 
00062       MethodFisher( const TString& jobName,
00063                     const TString& methodTitle,
00064                     DataSetInfo& dsi,
00065                     const TString& theOption = "Fisher",
00066                     TDirectory* theTargetDir = 0 );
00067 
00068       MethodFisher( DataSetInfo& dsi,
00069                     const TString& theWeightFile,
00070                     TDirectory* theTargetDir = NULL );
00071 
00072       virtual ~MethodFisher( void );
00073 
00074       virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
00075 
00076 
00077       // training method
00078       void Train( void );
00079 
00080       using MethodBase::ReadWeightsFromStream;
00081 
00082       // write weights to stream
00083       void AddWeightsXMLTo     ( void* parent ) const;
00084 
00085       // read weights from stream
00086       void ReadWeightsFromStream( std::istream & i );
00087       void ReadWeightsFromXML   ( void* wghtnode );
00088 
00089       // calculate the MVA value
00090       Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
00091 
00092       enum EFisherMethod { kFisher, kMahalanobis };
00093       EFisherMethod GetFisherMethod( void ) { return fFisherMethod; }
00094 
00095       // ranking of input variables
00096       const Ranking* CreateRanking();
00097 
00098    protected:
00099 
00100       // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
00101       void MakeClassSpecific( std::ostream&, const TString& ) const;
00102 
00103       // get help message text
00104       void GetHelpMessage() const;
00105 
00106    private:
00107 
00108       // the option handling methods
00109       void DeclareOptions();
00110       void ProcessOptions();
00111 
00112       // Initialization and allocation of matrices
00113       void InitMatrices( void );
00114 
00115       // get mean value of variables
00116       void GetMean( void );
00117 
00118       // get matrix of covariance within class
00119       void GetCov_WithinClass( void );
00120 
00121       // get matrix of covariance between class
00122       void GetCov_BetweenClass( void );
00123 
00124       // and the full covariance matrix
00125       void GetCov_Full( void );
00126 
00127       // get discriminating power
00128       void GetDiscrimPower( void );
00129 
00130       // nice output
00131       void PrintCoefficients( void );
00132 
00133       // get Fisher coefficients
00134       void GetFisherCoeff( void );
00135 
00136       // matrix of variables means: S, B, S+B vs. variables
00137       TMatrixD *fMeanMatx;
00138 
00139       // method to be used
00140       TString       fTheMethod;       // Fisher or Mahalanobis
00141       EFisherMethod fFisherMethod;    // Fisher or Mahalanobis 
00142 
00143       // covariance matrices
00144       TMatrixD *fBetw;                // between-class matrix
00145       TMatrixD *fWith;                // within-class matrix
00146       TMatrixD *fCov;                 // full covariance matrix
00147 
00148       // number of events (sumOfWeights)
00149       Double_t fSumOfWeightsS;        // sum-of-weights for signal training events
00150       Double_t fSumOfWeightsB;        // sum-of-weights for background training events
00151       
00152       std::vector<Double_t>* fDiscrimPow;  // discriminating power
00153       std::vector<Double_t>* fFisherCoeff; // Fisher coefficients
00154       Double_t fF0;                   // offset
00155 
00156       // default initialisation called by all constructors
00157       void Init( void );
00158 
00159       ClassDef(MethodFisher,0) // Analysis of Fisher discriminant (Fisher or Mahalanobis approach) 
00160    };
00161 
00162 } // namespace TMVA
00163 
00164 #endif // MethodFisher_H

Generated on Tue Jul 5 14:27:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1