Loading [MathJax]/extensions/tex2jax.js
ROOT  6.07/01
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MethodPDEFoam.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Tancredi Carli, Dominik Dannheim, Alexander Voigt
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate Data analysis *
6  * Package: TMVA *
7  * Class : MethodPDEFoam *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * The PDEFoam method is an extension of the PDERS method, which divides *
12  * the multi-dimensional phase space in a finite number of hyper-rectangles *
13  * (cells) of constant event density. This "foam" of cells is filled with *
14  * averaged probability-density information sampled from a training event *
15  * sample. *
16  * *
17  * Authors (alphabetical): *
18  * Tancredi Carli - CERN, Switzerland *
19  * Dominik Dannheim - CERN, Switzerland *
20  * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
21  * Alexander Voigt - TU Dresden, Germany *
22  * *
23  * Original author of the TFoam implementation: *
24  * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
25  * *
26  * Copyright (c) 2008, 2010: *
27  * CERN, Switzerland *
28  * MPI-K Heidelberg, Germany *
29  * *
30  * Redistribution and use in source and binary forms, with or without *
31  * modification, are permitted according to the terms listed in LICENSE *
32  * (http://tmva.sourceforge.net/LICENSE) *
33  **********************************************************************************/
34 
35 #ifndef ROOT_TMVA_MethodPDEFoam
36 #define ROOT_TMVA_MethodPDEFoam
37 
38 //////////////////////////////////////////////////////////////////////////////
39 // //
40 // MethodPDEFoam //
41 // //
42 //////////////////////////////////////////////////////////////////////////////
43 
44 #ifndef ROOT_TMVA_MethodBase
45 #include "TMVA/MethodBase.h"
46 #endif
47 
48 #ifndef ROOT_TMVA_PDEFoam
49 #include "TMVA/PDEFoam.h"
50 #endif
51 
52 #ifndef ROOT_TMVA_PDEFoamDecisionTree
54 #endif
55 #ifndef ROOT_TMVA_PDEFoamEvent
56 #include "TMVA/PDEFoamEvent.h"
57 #endif
58 #ifndef ROOT_TMVA_PDEFoamDiscriminant
60 #endif
61 #ifndef ROOT_TMVA_PDEFoamTarget
62 #include "TMVA/PDEFoamTarget.h"
63 #endif
64 #ifndef ROOT_TMVA_PDEFoamMultiTarget
66 #endif
67 
68 #ifndef ROOT_TMVA_PDEFoamDensityBase
70 #endif
71 #ifndef ROOT_TMVA_PDEFoamTargetDensity
73 #endif
74 #ifndef ROOT_TMVA_PDEFoamEventDensity
76 #endif
77 #ifndef ROOT_TMVA_PDEFoamDiscriminantDensity
79 #endif
80 #ifndef ROOT_TMVA_PDEFoamDecisionTreeDensity
82 #endif
83 
84 #ifndef ROOT_TMVA_PDEFoamKernelBase
85 #include "TMVA/PDEFoamKernelBase.h"
86 #endif
87 #ifndef ROOT_TMVA_PDEFoamKernelTrivial
89 #endif
90 #ifndef ROOT_TMVA_PDEFoamKernelLinN
91 #include "TMVA/PDEFoamKernelLinN.h"
92 #endif
93 #ifndef ROOT_TMVA_PDEFoamKernelGauss
95 #endif
96 
97 namespace TMVA {
98 
99  class MethodPDEFoam : public MethodBase {
100 
101  public:
102 
103  // kernel types
104  typedef enum EKernel { kNone=0, kGaus=1, kLinN=2 } EKernel;
105 
106  MethodPDEFoam( const TString& jobName,
107  const TString& methodTitle,
108  DataSetInfo& dsi,
109  const TString& theOption = "PDEFoam",
110  TDirectory* theTargetDir = 0 );
111 
113  const TString& theWeightFile,
114  TDirectory* theTargetDir = NULL );
115 
116  virtual ~MethodPDEFoam( void );
117 
118  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
119 
120  // training methods
121  void Train( void );
122  void TrainMonoTargetRegression( void ); // Regression output: one value
123  void TrainMultiTargetRegression( void ); // Regression output: any number of values
124  void TrainSeparatedClassification( void ); // Classification: one foam for Sig, one for Bg
125  void TrainUnifiedClassification( void ); // Classification: one foam for Signal and Bg
126  void TrainMultiClassification(); // Classification: one foam for every class
127 
129 
130  // write weights to stream
131  void AddWeightsXMLTo( void* parent ) const;
132 
133  // read weights from stream
134  void ReadWeightsFromStream( std::istream & i );
135  void ReadWeightsFromXML ( void* wghtnode );
136 
137  // write/read pure foams to/from file
138  void WriteFoamsToFile() const;
139  void ReadFoamsFromFile();
141 
142  // calculate the MVA value
143  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
144 
145  // calculate multiclass MVA values
146  const std::vector<Float_t>& GetMulticlassValues();
147 
148  // regression procedure
149  virtual const std::vector<Float_t>& GetRegressionValues();
150 
151  // reset the method
152  virtual void Reset();
153 
154  // ranking of input variables
155  const Ranking* CreateRanking();
156 
157  // get number of cuts in every dimension, starting at cell
158  void GetNCuts(PDEFoamCell *cell, std::vector<UInt_t> &nCuts);
159 
160  // helper functions to convert enum types to UInt_t and back
161  EKernel GetKernel( void ) { return fKernel; }
162  UInt_t KernelToUInt(EKernel ker) const { return UInt_t(ker); }
166 
167  protected:
168 
169  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
170  void MakeClassSpecific( std::ostream&, const TString& ) const;
171 
172  // get help message text
173  void GetHelpMessage() const;
174 
175  // calculate the error on the Mva value
177 
178  // calculate Xmin and Xmax for Foam
179  void CalcXminXmax();
180 
181  // Set Xmin, Xmax in foam with index 'foam_index'
182  void SetXminXmax(TMVA::PDEFoam*);
183 
184  // create foam and set foam options
186 
187  // create pdefoam kernel
189 
190  // delete all trained foams
191  void DeleteFoams();
192 
193  // fill variable names into foam
194  void FillVariableNamesToFoam() const;
195 
196  private:
197 
198  // the option handling methods
199  void DeclareOptions();
201  void ProcessOptions();
202 
203  // nice output
204  void PrintCoefficients( void );
205 
206  // Square function (fastest implementation)
207  template<typename T> T Sqr(T x) const { return x*x; }
208 
209  // options to be used
210  Bool_t fSigBgSeparated; // Separate Sig and Bg, or not
211  Float_t fFrac; // Fraction used for calc of Xmin, Xmax
212  Float_t fDiscrErrCut; // cut on discrimant error
213  Float_t fVolFrac; // volume fraction (used for density calculation during buildup)
214  Int_t fnCells; // Number of Cells (1000)
215  Int_t fnActiveCells; // Number of active cells
216  Int_t fnSampl; // Number of MC events per cell in build-up (1000)
217  Int_t fnBin; // Number of bins in build-up (100)
218  Int_t fEvPerBin; // Maximum events (equiv.) per bin in buid-up (1000)
219 
220  Bool_t fCompress; // compress foam output file
221  Bool_t fMultiTargetRegression; // do regression on multible targets
222  UInt_t fNmin; // minimal number of events in cell necessary to split cell"
223  Bool_t fCutNmin; // Keep for bw compatibility: Grabbing cell with maximal RMS to split next (TFoam default)
224  UInt_t fMaxDepth; // maximum depth of cell tree
225 
226  TString fKernelStr; // Kernel for GetMvaValue() (option string)
227  EKernel fKernel; // Kernel for GetMvaValue()
228  PDEFoamKernelBase *fKernelEstimator;// Kernel estimator
229  TString fTargetSelectionStr; // method of selecting the target (only mulit target regr.)
230  ETargetSelection fTargetSelection; // method of selecting the target (only mulit target regr.)
231  Bool_t fFillFoamWithOrigWeights; // fill the foam with boost weights
232  Bool_t fUseYesNoCell; // return -1 or 1 for bg or signal like event
233  TString fDTLogic; // use DT algorithm to split cells
234  EDTSeparation fDTSeparation; // enum which specifies the separation to use for the DT logic
235  Bool_t fPeekMax; // BACKWARDS COMPATIBILITY: peek up cell with max. driver integral for split
236 
237  std::vector<Float_t> fXmin, fXmax; // range for histograms and foams
238 
239  std::vector<PDEFoam*> fFoam; // grown PDEFoams
240 
241  // default initialisation called by all constructors
242  void Init( void );
243 
244  ClassDef(MethodPDEFoam,0) // Multi-dimensional probability density estimator using TFoam (PDE-Foam)
245  };
246 
247 } // namespace TMVA
248 
249 #endif // MethodPDEFoam_H
void Train(void)
Train PDE-Foam depending on the set options.
std::vector< Float_t > fXmax
T Sqr(T x) const
virtual void Reset()
reset MethodPDEFoam:
Bool_t fFillFoamWithOrigWeights
EDTSeparation
Definition: PDEFoam.h:70
void GetNCuts(PDEFoamCell *cell, std::vector< UInt_t > &nCuts)
Fill in 'nCuts' the number of cuts made in every foam dimension, starting at the root cell 'cell'...
float Float_t
Definition: RtypesCore.h:53
PDEFoam * InitFoam(TString, EFoamType, UInt_t cls=0)
Create a new PDEFoam, set the PDEFoam options (nCells, nBin, Xmin, Xmax, etc.) and initialize the PDE...
void PrintCoefficients(void)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
EAnalysisType
Definition: Types.h:124
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
void TrainUnifiedClassification(void)
Create only one unified foam (fFoam[0]) whose cells contain the average discriminator (N_sig)/(N_sig ...
bool Bool_t
Definition: RtypesCore.h:59
UInt_t KernelToUInt(EKernel ker) const
TTree * T
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
void GetHelpMessage() const
provide help message
void ReadWeightsFromStream(std::istream &i)
read options and internal parameters
virtual ~MethodPDEFoam(void)
destructor
EFoamType
Definition: PDEFoam.h:74
void DeclareOptions()
Declare MethodPDEFoam options.
std::vector< Float_t > fXmin
void SetXminXmax(TMVA::PDEFoam *)
Set Xmin, Xmax for every dimension in the given pdefoam object.
PDEFoam * ReadClonedFoamFromFile(TFile *, const TString &)
Reads a foam with name 'foamname' from file, and returns a clone of the foam.
void WriteFoamsToFile() const
Write PDEFoams to file.
Double_t CalculateMVAError()
Calculate the error on the Mva value.
void Init(void)
default initialization called by all constructors
void CalcXminXmax()
Determine foam range [fXmin, fXmax] for all dimensions, such that a fraction of 'fFrac' events lie ou...
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
PDEFoam can handle classification with multiple classes and regression with one or more regression-ta...
UInt_t TargetSelectionToUInt(ETargetSelection ts) const
PDEFoamKernelBase * fKernelEstimator
EKernel UIntToKernel(UInt_t iker)
convert UInt_t to EKernel (used for reading weight files)
unsigned int UInt_t
Definition: RtypesCore.h:42
ETargetSelection UIntToTargetSelection(UInt_t its)
convert UInt_t to ETargetSelection (used for reading weight files)
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Return Mva-Value.
void TrainMultiTargetRegression(void)
Training one (multi target regression) foam, whose cells contain the average event density...
MethodPDEFoam(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="PDEFoam", TDirectory *theTargetDir=0)
void FillVariableNamesToFoam() const
store the variable names in all foams
void TrainSeparatedClassification(void)
Creation of 2 separated foams: one for signal events, one for backgound events.
void ReadWeightsFromXML(void *wghtnode)
read PDEFoam variables from xml weight file
EKernel GetKernel(void)
double Double_t
Definition: RtypesCore.h:55
void TrainMultiClassification()
Create one unified foam (see TrainUnifiedClassification()) for each class, where the cells of foam i ...
Describe directory structure in memory.
Definition: TDirectory.h:44
int type
Definition: TGX11.cxx:120
std::vector< PDEFoam * > fFoam
PDEFoamKernelBase * CreatePDEFoamKernel()
create a pdefoam kernel estimator, depending on the current value of fKernel
void TrainMonoTargetRegression(void)
Training one (mono target regression) foam, whose cells contain the average 0th target.
const std::vector< Float_t > & GetMulticlassValues()
Get the multiclass MVA response for the PDEFoam classifier.
const Ranking * CreateRanking()
Compute ranking of input variables from the number of cuts made in each PDEFoam dimension.
void DeleteFoams()
Deletes all trained foams.
ETargetSelection fTargetSelection
#define NULL
Definition: Rtypes.h:82
EDTSeparation fDTSeparation
virtual const std::vector< Float_t > & GetRegressionValues()
Return regression values for both multi- and mono-target regression.
void ProcessOptions()
process user options
void MakeClassSpecific(std::ostream &, const TString &) const
write PDEFoam-specific classifier response NOT IMPLEMENTED YET!
virtual void ReadWeightsFromStream(std::istream &)=0
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
void AddWeightsXMLTo(void *parent) const
create XML output of PDEFoam method variables
void ReadFoamsFromFile()
read foams from file