Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
MethodLikelihood.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss, Peter Speckmayer, Eckhard von Toerne, Jan Therhaag
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodLikelihood *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Likelihood analysis ("non-parametric approach") *
12  * Also implemented is a "diagonalized likelihood approach", *
13  * which improves over the uncorrelated likelihood ansatz by transforming *
14  * linearly the input variables into a diagonal space, using the square-root *
15  * of the covariance matrix. This approach can be chosen by inserting *
16  * the letter "D" into the option string. *
17  * *
18  * Authors (alphabetical): *
19  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
20  * Peter Speckmayer <Peter.Speckmazer@cern.ch> - CERN, Switzerland *
21  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
22  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
23  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
24  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
25  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
26  * *
27  * Copyright (c) 2005-2011: *
28  * CERN, Switzerland *
29  * U. of Victoria, Canada *
30  * MPI-K Heidelberg, Germany *
31  * U. of Bonn, Germany *
32  * *
33  * Redistribution and use in source and binary forms, with or without *
34  * modification, are permitted according to the terms listed in LICENSE *
35  * (http://tmva.sourceforge.net/LICENSE) *
36  **********************************************************************************/
37 
38 #ifndef ROOT_TMVA_MethodLikelihood
39 #define ROOT_TMVA_MethodLikelihood
40 
41 //////////////////////////////////////////////////////////////////////////
42 // //
43 // MethodLikelihood //
44 // //
45 // Likelihood analysis ("non-parametric approach") //
46 // Also implemented is a "diagonalized likelihood approach", //
47 // which improves over the uncorrelated likelihood ansatz by //
48 // transforming linearly the input variables into a diagonal space, //
49 // using the square-root of the covariance matrix //
50 // //
51 //////////////////////////////////////////////////////////////////////////
52 
53 #include "TMVA/MethodBase.h"
54 #include "TMVA/PDF.h"
55 
56 class TH1D;
57 
58 namespace TMVA {
59 
60  class MethodLikelihood : public MethodBase {
61 
62  public:
63 
64  MethodLikelihood( const TString& jobName,
65  const TString& methodTitle,
66  DataSetInfo& theData,
67  const TString& theOption = "");
68 
69  MethodLikelihood( DataSetInfo& theData,
70  const TString& theWeightFile);
71 
72  virtual ~MethodLikelihood();
73 
74  virtual Bool_t HasAnalysisType( Types::EAnalysisType type,
75  UInt_t numberClasses, UInt_t numberTargets );
76 
77  // training method
78  void Train();
79 
80  // write weights to file
81  void WriteWeightsToStream( TFile& rf ) const;
82  void AddWeightsXMLTo( void* parent ) const;
83 
84  // read weights from file
85  void ReadWeightsFromStream( std::istream& istr );
86  void ReadWeightsFromStream( TFile& istr );
87  void ReadWeightsFromXML( void* wghtnode );
88  // calculate the MVA value
89  // the argument is used for internal ranking tests
90  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
91 
92  // write method specific histos to target file
93  void WriteMonitoringHistosToFile() const;
94 
95  // ranking of input variables
96  const Ranking* CreateRanking();
97 
98  virtual void WriteOptionsToStream ( std::ostream& o, const TString& prefix ) const;
99 
100  protected:
101 
102  void DeclareCompatibilityOptions();
103 
104  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
105  void MakeClassSpecific( std::ostream&, const TString& ) const;
106 
107  // header and auxiliary classes
108  void MakeClassSpecificHeader( std::ostream&, const TString& = "" ) const;
109 
110  // get help message text
111  void GetHelpMessage() const;
112 
113  private:
114 
115  // returns transformed or non-transformed output
116  Double_t TransformLikelihoodOutput( Double_t ps, Double_t pb ) const;
117 
118  // the option handling methods
119  void Init();
120  void DeclareOptions();
121  void ProcessOptions();
122 
123  // options
124  Double_t fEpsilon; // minimum number of likelihood (to avoid zero)
125  Bool_t fTransformLikelihoodOutput; // likelihood output is sigmoid-transformed
126 
127  Int_t fDropVariable; // for ranking test
128 
129  std::vector<TH1*>* fHistSig; // signal PDFs (histograms)
130  std::vector<TH1*>* fHistBgd; // background PDFs (histograms)
131  std::vector<TH1*>* fHistSig_smooth; // signal PDFs (smoothed histograms)
132  std::vector<TH1*>* fHistBgd_smooth; // background PDFs (smoothed histograms)
133 
134  PDF* fDefaultPDFLik; // pdf that contains default definitions
135  std::vector<PDF*>* fPDFSig; // list of PDFs (signal)
136  std::vector<PDF*>* fPDFBgd; // list of PDFs (background)
137 
138  // default initialisation called by all constructors
139 
140  // obsolete variables kept for backward combatibility
141  Int_t fNsmooth; // number of smooth passes
142  Int_t* fNsmoothVarS; // number of smooth passes
143  Int_t* fNsmoothVarB; // number of smooth passes
144  Int_t fAverageEvtPerBin; // average events per bin; used to calculate fNbins
145  Int_t* fAverageEvtPerBinVarS; // average events per bin; used to calculate fNbins
146  Int_t* fAverageEvtPerBinVarB; // average events per bin; used to calculate fNbins
147  TString fBorderMethodString; // the method to take care about "border" effects (string)
148  Float_t fKDEfineFactor; // fine tuning factor for Adaptive KDE
149  TString fKDEiterString; // Number of iterations (string)
150  TString fKDEtypeString; // Kernel type to use for KDE (string)
151  TString* fInterpolateString; // which interpolation method used for reference histograms (individual for each variable)
152 
153  ClassDef(MethodLikelihood,0); // Likelihood analysis ("non-parametric approach")
154  };
155 
156 } // namespace TMVA
157 
158 #endif // MethodLikelihood_H