Logo ROOT   6.08/07
Reference Guide
MethodPDERS.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Yair Mahalalel, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodPDERS *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Multidimensional Likelihood using the "Probability density estimator *
12  * range search" (PDERS) method suggested in *
13  * T. Carli and B. Koblitz, NIM A 501, 576 (2003) *
14  * *
15  * The multidimensional PDFs for signal and background are modeled *
16  * by counting the events in the "vicinity" of a test point. The volume *
17  * that describes "vicinity" is user-defined through the option string. *
18  * A search method based on binary-trees is used to improve the selection *
19  * efficiency of the volume search. *
20  * *
21  * Authors (alphabetical): *
22  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
23  * Yair Mahalalel <Yair.Mahalalel@cern.ch> - CERN, Switzerland *
24  * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
25  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
26  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
27  * *
28  * Copyright (c) 2005: *
29  * CERN, Switzerland *
30  * U. of Victoria, Canada *
31  * MPI-K Heidelberg, 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_MethodPDERS
39 #define ROOT_TMVA_MethodPDERS
40 
41 //////////////////////////////////////////////////////////////////////////
42 // //
43 // MethodPDERS //
44 // //
45 // Multidimensional Likelihood using the "Probability density //
46 // estimator range search" (PDERS) method //
47 // //
48 //////////////////////////////////////////////////////////////////////////
49 
50 #ifndef ROOT_TMVA_MethodBase
51 #include "TMVA/MethodBase.h"
52 #endif
53 #ifndef ROOT_TMVA_BinarySearchTree
54 #include "TMVA/BinarySearchTree.h"
55 #endif
56 #ifndef ROOT_TMVA_TVector
57 #ifndef ROOT_TVector
58 #include "TVector.h"
59 #endif
60 #endif
61 
62 namespace TMVA {
63 
64  class Volume;
65  class Event;
66 
67  class MethodPDERS : public MethodBase {
68 
69  public:
70 
71  MethodPDERS( const TString& jobName,
72  const TString& methodTitle,
73  DataSetInfo& theData,
74  const TString& theOption);
75 
76  MethodPDERS( DataSetInfo& theData,
77  const TString& theWeightFile);
78 
79  virtual ~MethodPDERS( void );
80 
81  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
82 
83 
84  // training method
85  void Train( void );
86 
87  // write weights to file
88  void WriteWeightsToStream( TFile& rf ) const;
89  void AddWeightsXMLTo( void* parent ) const;
90 
91  // read weights from file
92  void ReadWeightsFromStream( std::istream& istr );
93  void ReadWeightsFromStream( TFile& istr );
94  void ReadWeightsFromXML( void* wghtnode );
95 
96  // calculate the MVA value
97  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
98 
99  // calculate the MVA value
100  const std::vector<Float_t>& GetRegressionValues();
101  public:
102 
103  // for root finder
106 
107  // static pointer to this object
108  static MethodPDERS* ThisPDERS( void );
109 
110  protected:
111 
112  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
113  void MakeClassSpecific( std::ostream&, const TString& ) const;
114 
115  // get help message text
116  void GetHelpMessage() const;
117 
118  Volume* fHelpVolume; // auxiliary variable
119  Int_t fFcnCall; // number of external function calls (RootFinder)
120 
121  // accessors
122  BinarySearchTree* GetBinaryTree( void ) const { return fBinaryTree; }
123 
124  Double_t CKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume& );
125  void RKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume&, std::vector<Float_t> *pdfSum );
126 
127  Double_t ApplyKernelFunction( Double_t normalized_distance );
129  Double_t GetNormalizedDistance( const TMVA::Event &base_event,
130  const BinarySearchTreeNode &sample_event,
131  Double_t *dim_normalization);
133  Double_t LanczosFilter( Int_t level, Double_t x );
134 
135  // ranking of input variables
136  const Ranking* CreateRanking() { return 0; }
137 
138  private:
139 
140  // the option handling methods
141  void DeclareOptions();
142  void ProcessOptions();
143 
144  // calculate the averages of the input variables needed for adaptive training
145  void CalcAverages();
146 
147  // create binary search trees for signal and background
149 
150  // get sample of training events
151  void GetSample( const Event &e, std::vector<const BinarySearchTreeNode*>& events, Volume *volume);
152 
153  // option
154  TString fVolumeRange; // option volume range
155  TString fKernelString; // option kernel estimator
156 
164  } fVRangeMode;
165 
167  kBox = 0,
171  kSinc3, // the sinc enumerators must be consecutive and in order!
182 
183  BinarySearchTree* fBinaryTree; // binary tree
184 
185  std::vector<Float_t>* fDelta; // size of volume
186  std::vector<Float_t>* fShift; // volume center
187  std::vector<Float_t> fAverageRMS; // average RMS of signal and background
188 
189  Float_t fScaleS; // weight for signal events
190  Float_t fScaleB; // weight for background events
191  Float_t fDeltaFrac; // fraction of RMS
192  Double_t fGaussSigma; // size of Gauss in adaptive volume
193  Double_t fGaussSigmaNorm;// size of Gauss in adaptive volume (normalised to dimensions)
194 
195  Double_t fNRegOut; // number of output dimensions for regression
196 
197  // input for adaptive volume adjustment
198  Float_t fNEventsMin; // minimum number of events in adaptive volume
199  Float_t fNEventsMax; // maximum number of events in adaptive volume
200  Float_t fMaxVIterations;// maximum number of iterations to adapt volume size
201  Float_t fInitialScale; // initial scale for adaptive volume
202 
203  Bool_t fInitializedVolumeEle; // is volume element initialized ?
204 
205  Int_t fkNNMin; // min number of events in kNN tree
206  Int_t fkNNMax; // max number of events in kNN tree
207 
208  Double_t fMax_distance; // maximum distance
209  Bool_t fPrinted; // print
210  Bool_t fNormTree; // binary-search tree is normalised
211 
212  void SetVolumeElement ( void );
213 
214  Double_t CRScalc ( const Event& );
215  void RRScalc ( const Event&, std::vector<Float_t>* count );
216 
217  Float_t GetError ( Float_t countS, Float_t countB,
218  Float_t sumW2S, Float_t sumW2B ) const;
219 
220  // This is a workaround for OSx where static thread_local data members are
221  // not supported. The C++ solution would indeed be the following:
222  static MethodPDERS*& GetMethodPDERSThreadLocal() {TTHREAD_TLS(MethodPDERS*) fgThisPDERS(nullptr); return fgThisPDERS;};
223  void UpdateThis();
224 
225  void Init( void );
226 
227  ClassDef(MethodPDERS,0); // Multi-dimensional probability density estimator range search (PDERS) method
228  };
229 
230 } // namespace TMVA
231 
232 #endif // MethodPDERS_H
void WriteWeightsToStream(TFile &rf) const
write training sample (TTree) to file
void UpdateThis()
update static this pointer
virtual ~MethodPDERS(void)
destructor
Double_t GetNormalizedDistance(const TMVA::Event &base_event, const BinarySearchTreeNode &sample_event, Double_t *dim_normalization)
We use Euclidian metric here. Might not be best or most efficient.
std::vector< Float_t > * fShift
Definition: MethodPDERS.h:186
Float_t fMaxVIterations
Definition: MethodPDERS.h:200
float Float_t
Definition: RtypesCore.h:53
void GetHelpMessage() const
get help message text
BinarySearchTree * fBinaryTree
Definition: MethodPDERS.h:183
Double_t NormSinc(Double_t x)
NormSinc.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
EAnalysisType
Definition: Types.h:129
void CreateBinarySearchTree(Types::ETreeType type)
create binary search trees for signal and background
Basic string class.
Definition: TString.h:137
void AddWeightsXMLTo(void *parent) const
write weights to xml file
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void RKernelEstimate(const Event &, std::vector< const BinarySearchTreeNode *> &, Volume &, std::vector< Float_t > *pdfSum)
normalization factors so we can work with radius 1 hyperspheres
Float_t fInitialScale
Definition: MethodPDERS.h:201
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
init the size of a volume element using a defined fraction of the volume containing the entire events...
Double_t fMax_distance
Definition: MethodPDERS.h:208
void GetSample(const Event &e, std::vector< const BinarySearchTreeNode *> &events, Volume *volume)
void Init(void)
default initialisation routine called by all constructors
static Double_t IGetVolumeContentForRoot(Double_t)
Interface to RootFinder.
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
void ReadWeightsFromStream(std::istream &istr)
read weight info from file
TString fVolumeRange
Definition: MethodPDERS.h:154
Float_t GetError(Float_t countS, Float_t countB, Float_t sumW2S, Float_t sumW2B) const
statistical error estimate for RS estimator
void CalcAverages()
compute also average RMS values required for adaptive Gaussian
Double_t CRScalc(const Event &)
TString fKernelString
Definition: MethodPDERS.h:155
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: VolumeRangeMo...
Double_t fGaussSigma
Definition: MethodPDERS.h:192
void SetVolumeElement(void)
defines volume dimensions
Bool_t fInitializedVolumeEle
Definition: MethodPDERS.h:203
BinarySearchTree * GetBinaryTree(void) const
Definition: MethodPDERS.h:122
unsigned int UInt_t
Definition: RtypesCore.h:42
void ReadWeightsFromXML(void *wghtnode)
static MethodPDERS * ThisPDERS(void)
static pointer to this object
void Train(void)
this is a dummy training: the preparation work to do is the construction of the binary tree as a poin...
Volume * fHelpVolume
Definition: MethodPDERS.h:118
std::vector< Float_t > * fDelta
Definition: MethodPDERS.h:185
double Double_t
Definition: RtypesCore.h:55
enum TMVA::MethodPDERS::EKernelEstimator fKernelEstimator
int type
Definition: TGX11.cxx:120
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
PDERS can handle classification with 2 classes and regression with one or more regression-targets.
Double_t CKernelEstimate(const Event &, std::vector< const BinarySearchTreeNode *> &, Volume &)
normalization factors so we can work with radius 1 hyperspheres
std::vector< Float_t > fAverageRMS
Definition: MethodPDERS.h:187
const std::vector< Float_t > & GetRegressionValues()
Abstract ClassifierFactory template that handles arbitrary types.
enum TMVA::MethodPDERS::EVolumeRangeMode fVRangeMode
void ProcessOptions()
process the options specified by the user
Double_t GetVolumeContentForRoot(Double_t)
count number of events in rescaled volume
const Ranking * CreateRanking()
Definition: MethodPDERS.h:136
MethodPDERS(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption)
standard constructor for the PDERS method
static MethodPDERS *& GetMethodPDERSThreadLocal()
Definition: MethodPDERS.h:222
Double_t ApplyKernelFunction(Double_t normalized_distance)
from the normalized euclidean distance calculate the distance for a certain kernel ...
Double_t fGaussSigmaNorm
Definition: MethodPDERS.h:193
Double_t LanczosFilter(Int_t level, Double_t x)
Lanczos Filter.
void RRScalc(const Event &, std::vector< Float_t > *count)
Double_t KernelNormalization(Double_t pdf)
Calculating the normalization factor only once (might need a reset at some point. ...
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response