Logo ROOT   6.07/09
Reference Guide
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 
112  const TString& theWeightFile);
113 
114  virtual ~MethodPDEFoam( void );
115 
116  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
117 
118  // training methods
119  void Train( void );
120  void TrainMonoTargetRegression( void ); // Regression output: one value
121  void TrainMultiTargetRegression( void ); // Regression output: any number of values
122  void TrainSeparatedClassification( void ); // Classification: one foam for Sig, one for Bg
123  void TrainUnifiedClassification( void ); // Classification: one foam for Signal and Bg
124  void TrainMultiClassification(); // Classification: one foam for every class
125 
127 
128  // write weights to stream
129  void AddWeightsXMLTo( void* parent ) const;
130 
131  // read weights from stream
132  void ReadWeightsFromStream( std::istream & i );
133  void ReadWeightsFromXML ( void* wghtnode );
134 
135  // write/read pure foams to/from file
136  void WriteFoamsToFile() const;
137  void ReadFoamsFromFile();
139 
140  // calculate the MVA value
141  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
142 
143  // calculate multiclass MVA values
144  const std::vector<Float_t>& GetMulticlassValues();
145 
146  // regression procedure
147  virtual const std::vector<Float_t>& GetRegressionValues();
148 
149  // reset the method
150  virtual void Reset();
151 
152  // ranking of input variables
153  const Ranking* CreateRanking();
154 
155  // get number of cuts in every dimension, starting at cell
156  void GetNCuts(PDEFoamCell *cell, std::vector<UInt_t> &nCuts);
157 
158  // helper functions to convert enum types to UInt_t and back
159  EKernel GetKernel( void ) { return fKernel; }
160  UInt_t KernelToUInt(EKernel ker) const { return UInt_t(ker); }
164 
165  protected:
166 
167  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
168  void MakeClassSpecific( std::ostream&, const TString& ) const;
169 
170  // get help message text
171  void GetHelpMessage() const;
172 
173  // calculate the error on the Mva value
175 
176  // calculate Xmin and Xmax for Foam
177  void CalcXminXmax();
178 
179  // Set Xmin, Xmax in foam with index 'foam_index'
180  void SetXminXmax(TMVA::PDEFoam*);
181 
182  // create foam and set foam options
184 
185  // create pdefoam kernel
187 
188  // delete all trained foams
189  void DeleteFoams();
190 
191  // fill variable names into foam
192  void FillVariableNamesToFoam() const;
193 
194  private:
195 
196  // the option handling methods
197  void DeclareOptions();
199  void ProcessOptions();
200 
201  // nice output
202  void PrintCoefficients( void );
203 
204  // Square function (fastest implementation)
205  template<typename T> T Sqr(T x) const { return x*x; }
206 
207  // options to be used
208  Bool_t fSigBgSeparated; // Separate Sig and Bg, or not
209  Float_t fFrac; // Fraction used for calc of Xmin, Xmax
210  Float_t fDiscrErrCut; // cut on discrimant error
211  Float_t fVolFrac; // volume fraction (used for density calculation during buildup)
212  Int_t fnCells; // Number of Cells (1000)
213  Int_t fnActiveCells; // Number of active cells
214  Int_t fnSampl; // Number of MC events per cell in build-up (1000)
215  Int_t fnBin; // Number of bins in build-up (100)
216  Int_t fEvPerBin; // Maximum events (equiv.) per bin in buid-up (1000)
217 
218  Bool_t fCompress; // compress foam output file
219  Bool_t fMultiTargetRegression; // do regression on multible targets
220  UInt_t fNmin; // minimal number of events in cell necessary to split cell"
221  Bool_t fCutNmin; // Keep for bw compatibility: Grabbing cell with maximal RMS to split next (TFoam default)
222  UInt_t fMaxDepth; // maximum depth of cell tree
223 
224  TString fKernelStr; // Kernel for GetMvaValue() (option string)
225  EKernel fKernel; // Kernel for GetMvaValue()
226  PDEFoamKernelBase *fKernelEstimator;// Kernel estimator
227  TString fTargetSelectionStr; // method of selecting the target (only mulit target regr.)
228  ETargetSelection fTargetSelection; // method of selecting the target (only mulit target regr.)
229  Bool_t fFillFoamWithOrigWeights; // fill the foam with boost weights
230  Bool_t fUseYesNoCell; // return -1 or 1 for bg or signal like event
231  TString fDTLogic; // use DT algorithm to split cells
232  EDTSeparation fDTSeparation; // enum which specifies the separation to use for the DT logic
233  Bool_t fPeekMax; // BACKWARDS COMPATIBILITY: peek up cell with max. driver integral for split
234 
235  std::vector<Float_t> fXmin, fXmax; // range for histograms and foams
236 
237  std::vector<PDEFoam*> fFoam; // grown PDEFoams
238 
239  // default initialisation called by all constructors
240  void Init( void );
241 
242  ClassDef(MethodPDEFoam,0); // Multi-dimensional probability density estimator using TFoam (PDE-Foam)
243  };
244 
245 } // namespace TMVA
246 
247 #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 &#39;nCuts&#39; the number of cuts made in every foam dimension, starting at the root cell &#39;cell&#39;...
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...
double T(double x)
Definition: ChebyshevPol.h:34
void PrintCoefficients(void)
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:128
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
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 &#39;foamname&#39; 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 &#39;fFrac&#39; 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...
MethodPDEFoam(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="PDEFoam")
init PDEFoam objects
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...
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 ...
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.
Abstract ClassifierFactory template that handles arbitrary types.
void DeleteFoams()
Deletes all trained foams.
ETargetSelection fTargetSelection
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