Logo ROOT  
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 #include "TMVA/MethodBase.h"
51 #include "TMVA/BinarySearchTree.h"
52 #include "TVector.h"
53 #include "ThreadLocalStorage.h"
54 #include <vector>
55 
56 namespace TMVA {
57 
58  class Volume;
59  class Event;
60 
61  class MethodPDERS : public MethodBase {
62 
63  public:
64 
65  MethodPDERS( const TString& jobName,
66  const TString& methodTitle,
67  DataSetInfo& theData,
68  const TString& theOption);
69 
70  MethodPDERS( DataSetInfo& theData,
71  const TString& theWeightFile);
72 
73  virtual ~MethodPDERS( void );
74 
75  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
76 
77 
78  // training method
79  void Train( void );
80 
81  // write weights to file
82  void WriteWeightsToStream( TFile& rf ) const;
83  void AddWeightsXMLTo( void* parent ) const;
84 
85  // read weights from file
86  void ReadWeightsFromStream( std::istream& istr );
87  void ReadWeightsFromStream( TFile& istr );
88  void ReadWeightsFromXML( void* wghtnode );
89 
90  // calculate the MVA value
91  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
92 
93  // calculate the MVA value
94  const std::vector<Float_t>& GetRegressionValues();
95  public:
96 
97  // for root finder
100 
101  // static pointer to this object
102  static MethodPDERS* ThisPDERS( void );
103 
104  protected:
105 
106  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
107  void MakeClassSpecific( std::ostream&, const TString& ) const;
108 
109  // get help message text
110  void GetHelpMessage() const;
111 
112  Volume* fHelpVolume; // auxiliary variable
113  Int_t fFcnCall; // number of external function calls (RootFinder)
114 
115  // accessors
116  BinarySearchTree* GetBinaryTree( void ) const { return fBinaryTree; }
117 
118  Double_t CKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume& );
119  void RKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume&, std::vector<Float_t> *pdfSum );
120 
121  Double_t ApplyKernelFunction( Double_t normalized_distance );
123  Double_t GetNormalizedDistance( const TMVA::Event &base_event,
124  const BinarySearchTreeNode &sample_event,
125  Double_t *dim_normalization);
128 
129  // ranking of input variables
130  const Ranking* CreateRanking() { return 0; }
131 
132  private:
133 
134  // the option handling methods
135  void DeclareOptions();
136  void ProcessOptions();
137 
138  // calculate the averages of the input variables needed for adaptive training
139  void CalcAverages();
140 
141  // create binary search trees for signal and background
143 
144  // get sample of training events
145  void GetSample( const Event &e, std::vector<const BinarySearchTreeNode*>& events, Volume *volume);
146 
147  // option
148  TString fVolumeRange; // option volume range
149  TString fKernelString; // option kernel estimator
150 
157  kkNN
159 
161  kBox = 0,
165  kSinc3, // the sinc enumerators must be consecutive and in order!
174  kTrim
176 
177  BinarySearchTree* fBinaryTree; // binary tree
178 
179  std::vector<Float_t>* fDelta; // size of volume
180  std::vector<Float_t>* fShift; // volume center
181  std::vector<Float_t> fAverageRMS; // average RMS of signal and background
182 
183  Float_t fScaleS; // weight for signal events
184  Float_t fScaleB; // weight for background events
185  Float_t fDeltaFrac; // fraction of RMS
186  Double_t fGaussSigma; // size of Gauss in adaptive volume
187  Double_t fGaussSigmaNorm;// size of Gauss in adaptive volume (normalised to dimensions)
188 
189  Double_t fNRegOut; // number of output dimensions for regression
190 
191  // input for adaptive volume adjustment
192  Float_t fNEventsMin; // minimum number of events in adaptive volume
193  Float_t fNEventsMax; // maximum number of events in adaptive volume
194  Float_t fMaxVIterations;// maximum number of iterations to adapt volume size
195  Float_t fInitialScale; // initial scale for adaptive volume
196 
197  Bool_t fInitializedVolumeEle; // is volume element initialized ?
198 
199  Int_t fkNNMin; // min number of events in kNN tree
200  Int_t fkNNMax; // max number of events in kNN tree
201 
202  Double_t fMax_distance; // maximum distance
203  Bool_t fPrinted; // print
204  Bool_t fNormTree; // binary-search tree is normalised
205 
206  void SetVolumeElement ( void );
207 
208  Double_t CRScalc ( const Event& );
209  void RRScalc ( const Event&, std::vector<Float_t>* count );
210 
211  Float_t GetError ( Float_t countS, Float_t countB,
212  Float_t sumW2S, Float_t sumW2B ) const;
213 
214  // This is a workaround for OSx where static thread_local data members are
215  // not supported. The C++ solution would indeed be the following:
216  static MethodPDERS*& GetMethodPDERSThreadLocal() {TTHREAD_TLS(MethodPDERS*) fgThisPDERS(nullptr); return fgThisPDERS;};
217  void UpdateThis();
218 
219  void Init( void );
220 
221  ClassDef(MethodPDERS,0); // Multi-dimensional probability density estimator range search (PDERS) method
222  };
223 
224 } // namespace TMVA
225 
226 #endif // MethodPDERS_H
TMVA::MethodPDERS::DeclareOptions
void DeclareOptions()
define the options (their key words) that can be set in the option string.
Definition: MethodPDERS.cxx:252
TMVA::MethodPDERS::IGetVolumeContentForRoot
static Double_t IGetVolumeContentForRoot(Double_t)
Interface to RootFinder.
Definition: MethodPDERS.cxx:529
TMVA::MethodPDERS::fBinaryTree
BinarySearchTree * fBinaryTree
Definition: MethodPDERS.h:177
TMVA::MethodPDERS::Init
void Init(void)
default initialisation routine called by all constructors
Definition: MethodPDERS.cxx:176
TMVA::MethodPDERS::RKernelEstimate
void RKernelEstimate(const Event &, std::vector< const BinarySearchTreeNode * > &, Volume &, std::vector< Float_t > *pdfSum)
normalization factors so we can work with radius 1 hyperspheres
Definition: MethodPDERS.cxx:875
TMVA::MethodPDERS::GetMethodPDERSThreadLocal
static MethodPDERS *& GetMethodPDERSThreadLocal()
Definition: MethodPDERS.h:216
e
#define e(i)
Definition: RSha256.hxx:103
TMVA::MethodPDERS::fInitializedVolumeEle
Bool_t fInitializedVolumeEle
Definition: MethodPDERS.h:197
TMVA::MethodPDERS::GetRegressionValues
const std::vector< Float_t > & GetRegressionValues()
Definition: MethodPDERS.cxx:390
TMVA::MethodPDERS::GetError
Float_t GetError(Float_t countS, Float_t countB, Float_t sumW2S, Float_t sumW2B) const
statistical error estimate for RS estimator
Definition: MethodPDERS.cxx:1080
TMVA::MethodPDERS::kLanczos5
@ kLanczos5
Definition: MethodPDERS.h:172
TMVA::Ranking
Ranking for variables in method (implementation)
Definition: Ranking.h:48
TMVA::Volume
Volume for BinarySearchTree.
Definition: Volume.h:47
TMVA::MethodPDERS::~MethodPDERS
virtual ~MethodPDERS(void)
destructor
Definition: MethodPDERS.cxx:208
TMVA::MethodPDERS::ProcessOptions
void ProcessOptions()
process the options specified by the user
Definition: MethodPDERS.cxx:289
TMVA::MethodPDERS::CRScalc
Double_t CRScalc(const Event &)
Definition: MethodPDERS.cxx:778
TMVA::MethodPDERS::fVRangeMode
enum TMVA::MethodPDERS::EVolumeRangeMode fVRangeMode
TMVA::MethodPDERS::fMax_distance
Double_t fMax_distance
Definition: MethodPDERS.h:202
TMVA::MethodPDERS::GetVolumeContentForRoot
Double_t GetVolumeContentForRoot(Double_t)
count number of events in rescaled volume
Definition: MethodPDERS.cxx:537
TMVA::MethodPDERS::kBox
@ kBox
Definition: MethodPDERS.h:161
TMVA::MethodPDERS::MethodPDERS
MethodPDERS(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption)
standard constructor for the PDERS method
Definition: MethodPDERS.cxx:100
Float_t
float Float_t
Definition: RtypesCore.h:57
TMVA::MethodPDERS::GetHelpMessage
void GetHelpMessage() const
get help message text
Definition: MethodPDERS.cxx:1209
x
Double_t x[n]
Definition: legend1.C:17
TMVA::MethodPDERS::fVolumeRange
TString fVolumeRange
Definition: MethodPDERS.h:148
TMVA::MethodPDERS::HasAnalysisType
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.
Definition: MethodPDERS.cxx:166
MethodBase.h
TMVA::MethodPDERS::fDeltaFrac
Float_t fDeltaFrac
Definition: MethodPDERS.h:185
TMVA::MethodPDERS::fNEventsMin
Float_t fNEventsMin
Definition: MethodPDERS.h:192
TString
Basic string class.
Definition: TString.h:136
TMVA::MethodPDERS::UpdateThis
void UpdateThis()
update static this pointer
Definition: MethodPDERS.cxx:1189
TMVA::MethodPDERS::kAdaptive
@ kAdaptive
Definition: MethodPDERS.h:155
TMVA::MethodPDERS::kUnscaled
@ kUnscaled
Definition: MethodPDERS.h:156
TMVA::MethodPDERS::CalcAverages
void CalcAverages()
compute also average RMS values required for adaptive Gaussian
Definition: MethodPDERS.cxx:433
TMVA::MethodPDERS::kSinc11
@ kSinc11
Definition: MethodPDERS.h:169
TMVA::MethodPDERS::kLanczos2
@ kLanczos2
Definition: MethodPDERS.h:170
bool
TMVA::MethodPDERS::fKernelString
TString fKernelString
Definition: MethodPDERS.h:149
TMVA::MethodPDERS::ReadWeightsFromXML
void ReadWeightsFromXML(void *wghtnode)
Definition: MethodPDERS.cxx:1111
TMVA::MethodPDERS::fGaussSigma
Double_t fGaussSigma
Definition: MethodPDERS.h:186
TMVA::MethodPDERS::SetVolumeElement
void SetVolumeElement(void)
defines volume dimensions
Definition: MethodPDERS.cxx:481
TMVA::MethodPDERS::ApplyKernelFunction
Double_t ApplyKernelFunction(Double_t normalized_distance)
from the normalized euclidean distance calculate the distance for a certain kernel
Definition: MethodPDERS.cxx:922
TMVA::MethodPDERS::kkNN
@ kkNN
Definition: MethodPDERS.h:157
TMVA::MethodPDERS::EKernelEstimator
EKernelEstimator
Definition: MethodPDERS.h:160
TMVA::DataSetInfo
Class that contains all the data information.
Definition: DataSetInfo.h:62
TMVA::MethodPDERS::LanczosFilter
Double_t LanczosFilter(Int_t level, Double_t x)
Lanczos Filter.
Definition: MethodPDERS.cxx:1060
TMVA::MethodPDERS::fNEventsMax
Float_t fNEventsMax
Definition: MethodPDERS.h:193
TMVA::MethodPDERS::fAverageRMS
std::vector< Float_t > fAverageRMS
Definition: MethodPDERS.h:181
TMVA::MethodPDERS::MakeClassSpecific
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
Definition: MethodPDERS.cxx:1197
TMVA::MethodPDERS::CKernelEstimate
Double_t CKernelEstimate(const Event &, std::vector< const BinarySearchTreeNode * > &, Volume &)
normalization factors so we can work with radius 1 hyperspheres
Definition: MethodPDERS.cxx:834
TMVA::BinarySearchTree
A simple Binary search tree including a volume search method.
Definition: BinarySearchTree.h:65
TMVA::MethodPDERS::kSinc9
@ kSinc9
Definition: MethodPDERS.h:168
BinarySearchTree.h
TMVA::Types::EAnalysisType
EAnalysisType
Definition: Types.h:128
TMVA::Types::ETreeType
ETreeType
Definition: Types.h:144
TMVA::MethodPDERS::fInitialScale
Float_t fInitialScale
Definition: MethodPDERS.h:195
TMVA::MethodPDERS::GetMvaValue
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
Definition: MethodPDERS.cxx:370
TMVA::MethodPDERS::GetSample
void GetSample(const Event &e, std::vector< const BinarySearchTreeNode * > &events, Volume *volume)
Definition: MethodPDERS.cxx:548
TMVA::MethodPDERS::CreateRanking
const Ranking * CreateRanking()
Definition: MethodPDERS.h:130
TMVA::MethodPDERS::kUnsupported
@ kUnsupported
Definition: MethodPDERS.h:152
TMVA::MethodPDERS::fPrinted
Bool_t fPrinted
Definition: MethodPDERS.h:203
TMVA::MethodPDERS::kTrim
@ kTrim
Definition: MethodPDERS.h:174
TMVA::MethodBase
Virtual base Class for all MVA method.
Definition: MethodBase.h:111
TMVA::MethodPDERS::kGauss
@ kGauss
Definition: MethodPDERS.h:164
TMVA::MethodPDERS::fNormTree
Bool_t fNormTree
Definition: MethodPDERS.h:204
TMVA::MethodPDERS::kLanczos8
@ kLanczos8
Definition: MethodPDERS.h:173
TMVA::MethodPDERS::fGaussSigmaNorm
Double_t fGaussSigmaNorm
Definition: MethodPDERS.h:187
TMVA::MethodPDERS::kSinc7
@ kSinc7
Definition: MethodPDERS.h:167
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TMVA::MethodPDERS::CreateBinarySearchTree
void CreateBinarySearchTree(Types::ETreeType type)
create binary search trees for signal and background
Definition: MethodPDERS.cxx:455
TMVA::MethodPDERS::fScaleB
Float_t fScaleB
Definition: MethodPDERS.h:184
TMVA::MethodPDERS::KernelNormalization
Double_t KernelNormalization(Double_t pdf)
Calculating the normalization factor only once (might need a reset at some point.
Definition: MethodPDERS.cxx:974
TMVA::MethodPDERS::kSinc5
@ kSinc5
Definition: MethodPDERS.h:166
unsigned int
TMVA::MethodPDERS::ReadWeightsFromStream
void ReadWeightsFromStream(std::istream &istr)
read weight info from file
Definition: MethodPDERS.cxx:1138
TMVA::MethodPDERS::fFcnCall
Int_t fFcnCall
Definition: MethodPDERS.h:113
TMVA::MethodPDERS::kRMS
@ kRMS
Definition: MethodPDERS.h:154
TMVA::MethodPDERS::AddWeightsXMLTo
void AddWeightsXMLTo(void *parent) const
write weights to xml file
Definition: MethodPDERS.cxx:1099
TMVA::MethodPDERS::WriteWeightsToStream
void WriteWeightsToStream(TFile &rf) const
write training sample (TTree) to file
Definition: MethodPDERS.cxx:1168
TMVA::MethodPDERS::kTeepee
@ kTeepee
Definition: MethodPDERS.h:163
TMVA::MethodPDERS::kSinc3
@ kSinc3
Definition: MethodPDERS.h:165
TVector.h
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MethodPDERS::fkNNMin
Int_t fkNNMin
Definition: MethodPDERS.h:199
TMVA::MethodPDERS::fKernelEstimator
enum TMVA::MethodPDERS::EKernelEstimator fKernelEstimator
TMVA::MethodPDERS::fScaleS
Float_t fScaleS
Definition: MethodPDERS.h:183
TMVA::MethodPDERS::fShift
std::vector< Float_t > * fShift
Definition: MethodPDERS.h:180
TMVA::Event
Definition: Event.h:51
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::MethodPDERS::fkNNMax
Int_t fkNNMax
Definition: MethodPDERS.h:200
TMVA::MethodPDERS::kSphere
@ kSphere
Definition: MethodPDERS.h:162
TMVA::BinarySearchTreeNode
Node for the BinarySearch or Decision Trees.
Definition: BinarySearchTreeNode.h:55
TMVA::MethodPDERS
This is a generalization of the above Likelihood methods to dimensions, where is the number of inpu...
Definition: MethodPDERS.h:61
TMVA::MethodPDERS::fHelpVolume
Volume * fHelpVolume
Definition: MethodPDERS.h:112
TMVA::MethodPDERS::fDelta
std::vector< Float_t > * fDelta
Definition: MethodPDERS.h:179
TMVA::MethodPDERS::kMinMax
@ kMinMax
Definition: MethodPDERS.h:153
TMVA::MethodPDERS::NormSinc
Double_t NormSinc(Double_t x)
NormSinc.
Definition: MethodPDERS.cxx:1039
TMVA::MethodPDERS::RRScalc
void RRScalc(const Event &, std::vector< Float_t > *count)
Definition: MethodPDERS.cxx:807
TMVA::MethodPDERS::GetBinaryTree
BinarySearchTree * GetBinaryTree(void) const
Definition: MethodPDERS.h:116
type
int type
Definition: TGX11.cxx:121
TMVA::MethodPDERS::EVolumeRangeMode
EVolumeRangeMode
Definition: MethodPDERS.h:151
ThreadLocalStorage.h
TMVA::MethodPDERS::kLanczos3
@ kLanczos3
Definition: MethodPDERS.h:171
TMVA::MethodPDERS::GetNormalizedDistance
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.
Definition: MethodPDERS.cxx:1022
TMVA::MethodPDERS::fNRegOut
Double_t fNRegOut
Definition: MethodPDERS.h:189
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int
TMVA::MethodPDERS::fMaxVIterations
Float_t fMaxVIterations
Definition: MethodPDERS.h:194
TMVA::MethodPDERS::Train
void Train(void)
this is a dummy training: the preparation work to do is the construction of the binary tree as a poin...
Definition: MethodPDERS.cxx:350
TMVA::MethodPDERS::ThisPDERS
static MethodPDERS * ThisPDERS(void)
static pointer to this object
Definition: MethodPDERS.cxx:1182