Logo ROOT  
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 #include "TMVA/MethodBase.h"
45 
46 #include "TMVA/PDEFoam.h"
47 
49 #include "TMVA/PDEFoamEvent.h"
51 #include "TMVA/PDEFoamTarget.h"
53 
59 
60 #include "TMVA/PDEFoamKernelBase.h"
62 #include "TMVA/PDEFoamKernelLinN.h"
64 
65 #include <vector>
66 
67 namespace TMVA {
68 
69  class MethodPDEFoam : public MethodBase {
70 
71  public:
72 
73  // kernel types
74  typedef enum EKernel { kNone=0, kGaus=1, kLinN=2 } EKernel;
75 
76  MethodPDEFoam( const TString& jobName,
77  const TString& methodTitle,
78  DataSetInfo& dsi,
79  const TString& theOption = "PDEFoam");
80 
81  MethodPDEFoam( DataSetInfo& dsi,
82  const TString& theWeightFile);
83 
84  virtual ~MethodPDEFoam( void );
85 
86  virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
87 
88  // training methods
89  void Train( void );
90  void TrainMonoTargetRegression( void ); // Regression output: one value
91  void TrainMultiTargetRegression( void ); // Regression output: any number of values
92  void TrainSeparatedClassification( void ); // Classification: one foam for Sig, one for Bg
93  void TrainUnifiedClassification( void ); // Classification: one foam for Signal and Bg
94  void TrainMultiClassification(); // Classification: one foam for every class
95 
97 
98  // write weights to stream
99  void AddWeightsXMLTo( void* parent ) const;
100 
101  // read weights from stream
102  void ReadWeightsFromStream( std::istream & i );
103  void ReadWeightsFromXML ( void* wghtnode );
104 
105  // write/read pure foams to/from file
106  void WriteFoamsToFile() const;
107  void ReadFoamsFromFile();
109 
110  // calculate the MVA value
111  Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
112 
113  // calculate multiclass MVA values
114  const std::vector<Float_t>& GetMulticlassValues();
115 
116  // regression procedure
117  virtual const std::vector<Float_t>& GetRegressionValues();
118 
119  // reset the method
120  virtual void Reset();
121 
122  // ranking of input variables
123  const Ranking* CreateRanking();
124 
125  // get number of cuts in every dimension, starting at cell
126  void GetNCuts(PDEFoamCell *cell, std::vector<UInt_t> &nCuts);
127 
128  // helper functions to convert enum types to UInt_t and back
129  EKernel GetKernel( void ) { return fKernel; }
130  UInt_t KernelToUInt(EKernel ker) const { return UInt_t(ker); }
132  UInt_t TargetSelectionToUInt(ETargetSelection ts) const { return UInt_t(ts); }
133  ETargetSelection UIntToTargetSelection(UInt_t its);
134 
135  protected:
136 
137  // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
138  void MakeClassSpecific( std::ostream&, const TString& ) const;
139 
140  // get help message text
141  void GetHelpMessage() const;
142 
143  // calculate the error on the Mva value
145 
146  // calculate Xmin and Xmax for Foam
147  void CalcXminXmax();
148 
149  // Set Xmin, Xmax in foam with index 'foam_index'
150  void SetXminXmax(TMVA::PDEFoam*);
151 
152  // create foam and set foam options
153  PDEFoam* InitFoam(TString, EFoamType, UInt_t cls=0);
154 
155  // create pdefoam kernel
157 
158  // delete all trained foams
159  void DeleteFoams();
160 
161  // fill variable names into foam
162  void FillVariableNamesToFoam() const;
163 
164  private:
165 
166  // the option handling methods
167  void DeclareOptions();
169  void ProcessOptions();
170 
171  // nice output
172  void PrintCoefficients( void );
173 
174  // Square function (fastest implementation)
175  template<typename T> T Sqr(T x) const { return x*x; }
176 
177  // options to be used
178  Bool_t fSigBgSeparated; // Separate Sig and Bg, or not
179  Float_t fFrac; // Fraction used for calc of Xmin, Xmax
180  Float_t fDiscrErrCut; // cut on discriminant error
181  Float_t fVolFrac; // volume fraction (used for density calculation during buildup)
182  Int_t fnCells; // Number of Cells (1000)
183  Int_t fnActiveCells; // Number of active cells
184  Int_t fnSampl; // Number of MC events per cell in build-up (1000)
185  Int_t fnBin; // Number of bins in build-up (100)
186  Int_t fEvPerBin; // Maximum events (equiv.) per bin in build-up (1000)
187 
188  Bool_t fCompress; // compress foam output file
189  Bool_t fMultiTargetRegression; // do regression on multiple targets
190  UInt_t fNmin; // minimal number of events in cell necessary to split cell"
191  Bool_t fCutNmin; // Keep for bw compatibility: Grabbing cell with maximal RMS to split next (TFoam default)
192  UInt_t fMaxDepth; // maximum depth of cell tree
193 
194  TString fKernelStr; // Kernel for GetMvaValue() (option string)
195  EKernel fKernel; // Kernel for GetMvaValue()
196  PDEFoamKernelBase *fKernelEstimator;// Kernel estimator
197  TString fTargetSelectionStr; // method of selecting the target (only mulit target regr.)
198  ETargetSelection fTargetSelection; // method of selecting the target (only mulit target regr.)
199  Bool_t fFillFoamWithOrigWeights; // fill the foam with boost weights
200  Bool_t fUseYesNoCell; // return -1 or 1 for bg or signal like event
201  TString fDTLogic; // use DT algorithm to split cells
202  EDTSeparation fDTSeparation; // enum which specifies the separation to use for the DT logic
203  Bool_t fPeekMax; // BACKWARDS COMPATIBILITY: peek up cell with max. driver integral for split
204 
205  std::vector<Float_t> fXmin, fXmax; // range for histograms and foams
206 
207  std::vector<PDEFoam*> fFoam; // grown PDEFoams
208 
209  // default initialisation called by all constructors
210  void Init( void );
211 
212  ClassDef(MethodPDEFoam,0); // Multi-dimensional probability density estimator using TFoam (PDE-Foam)
213  };
214 
215 } // namespace TMVA
216 
217 #endif // MethodPDEFoam_H
TMVA::MethodPDEFoam::ReadWeightsFromStream
void ReadWeightsFromStream(std::istream &i)
read options and internal parameters
Definition: MethodPDEFoam.cxx:1227
PDEFoamKernelTrivial.h
TMVA::MethodPDEFoam::fnActiveCells
Int_t fnActiveCells
Definition: MethodPDEFoam.h:241
TMVA::MethodPDEFoam::Sqr
T Sqr(T x) const
Definition: MethodPDEFoam.h:233
TMVA::MethodPDEFoam::fCompress
Bool_t fCompress
Definition: MethodPDEFoam.h:246
TMVA::MethodPDEFoam::fDTLogic
TString fDTLogic
Definition: MethodPDEFoam.h:259
TMVA::MethodPDEFoam::GetHelpMessage
void GetHelpMessage() const
provide help message
Definition: MethodPDEFoam.cxx:1507
TMVA::MethodPDEFoam::CreatePDEFoamKernel
PDEFoamKernelBase * CreatePDEFoamKernel()
create a pdefoam kernel estimator, depending on the current value of fKernel
Definition: MethodPDEFoam.cxx:1102
PDEFoamKernelBase.h
TMVA::MethodBase::ReadWeightsFromStream
virtual void ReadWeightsFromStream(std::istream &)=0
TMVA::MethodPDEFoam::WriteFoamsToFile
void WriteFoamsToFile() const
Write PDEFoams to file.
Definition: MethodPDEFoam.cxx:1195
TMVA::MethodPDEFoam::kNone
@ kNone
Definition: MethodPDEFoam.h:161
TMVA::MethodPDEFoam::ReadFoamsFromFile
void ReadFoamsFromFile()
read foams from file
Definition: MethodPDEFoam.cxx:1400
TMVA::Ranking
Definition: Ranking.h:70
TMVA::PDEFoamKernelBase
Definition: PDEFoamKernelBase.h:62
TMVA::MethodPDEFoam::GetRegressionValues
virtual const std::vector< Float_t > & GetRegressionValues()
Return regression values for both multi- and mono-target regression.
Definition: MethodPDEFoam.cxx:1050
TMVA::MethodPDEFoam::Init
void Init(void)
default initialization called by all constructors
Definition: MethodPDEFoam.cxx:171
TMVA::MethodPDEFoam::fnSampl
Int_t fnSampl
Definition: MethodPDEFoam.h:242
TMVA::MethodPDEFoam::fUseYesNoCell
Bool_t fUseYesNoCell
Definition: MethodPDEFoam.h:258
TMVA::MethodPDEFoam::fKernelStr
TString fKernelStr
Definition: MethodPDEFoam.h:252
TMVA::MethodPDEFoam::ProcessOptions
void ProcessOptions()
process user options
Definition: MethodPDEFoam.cxx:252
TMVA::MethodPDEFoam::fKernelEstimator
PDEFoamKernelBase * fKernelEstimator
Definition: MethodPDEFoam.h:254
TMVA::MethodPDEFoam::fDTSeparation
EDTSeparation fDTSeparation
Definition: MethodPDEFoam.h:260
Float_t
float Float_t
Definition: RtypesCore.h:57
TMVA::MethodPDEFoam::fnBin
Int_t fnBin
Definition: MethodPDEFoam.h:243
PDEFoamDensityBase.h
TMVA::MethodPDEFoam::TargetSelectionToUInt
UInt_t TargetSelectionToUInt(ETargetSelection ts) const
Definition: MethodPDEFoam.h:190
TMVA::MethodPDEFoam::ReadWeightsFromXML
void ReadWeightsFromXML(void *wghtnode)
read PDEFoam variables from xml weight file
Definition: MethodPDEFoam.cxx:1283
x
Double_t x[n]
Definition: legend1.C:17
MethodBase.h
TMVA::MethodPDEFoam::kLinN
@ kLinN
Definition: MethodPDEFoam.h:161
TMVA::MethodPDEFoam::AddWeightsXMLTo
void AddWeightsXMLTo(void *parent) const
create XML output of PDEFoam method variables
Definition: MethodPDEFoam.cxx:1152
TMVA::MethodPDEFoam::UIntToKernel
EKernel UIntToKernel(UInt_t iker)
convert UInt_t to EKernel (used for reading weight files)
Definition: MethodPDEFoam.cxx:1453
TMVA::MethodPDEFoam::kGaus
@ kGaus
Definition: MethodPDEFoam.h:161
TMVA::MethodPDEFoam::fEvPerBin
Int_t fEvPerBin
Definition: MethodPDEFoam.h:244
TString
Definition: TString.h:136
TMVA::MethodPDEFoam::fSigBgSeparated
Bool_t fSigBgSeparated
Definition: MethodPDEFoam.h:236
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMVA::MethodPDEFoam::DeleteFoams
void DeleteFoams()
Deletes all trained foams.
Definition: MethodPDEFoam.cxx:1121
TMVA::MethodPDEFoam::GetMvaValue
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Return Mva-Value.
Definition: MethodPDEFoam.cxx:709
TMVA::MethodPDEFoam::CalculateMVAError
Double_t CalculateMVAError()
Calculate the error on the Mva value.
Definition: MethodPDEFoam.cxx:755
TMVA::MethodPDEFoam::DeclareOptions
void DeclareOptions()
Declare MethodPDEFoam options.
Definition: MethodPDEFoam.cxx:208
bool
TMVA::MethodPDEFoam::InitFoam
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...
Definition: MethodPDEFoam.cxx:934
TMVA::MethodPDEFoam::fnCells
Int_t fnCells
Definition: MethodPDEFoam.h:240
TMVA::MethodPDEFoam::PrintCoefficients
void PrintCoefficients(void)
Definition: MethodPDEFoam.cxx:1146
TMVA::MethodPDEFoam::FillVariableNamesToFoam
void FillVariableNamesToFoam() const
store the variable names in all foams
Definition: MethodPDEFoam.cxx:1484
PDEFoamDecisionTree.h
TMVA::MethodPDEFoam::fMultiTargetRegression
Bool_t fMultiTargetRegression
Definition: MethodPDEFoam.h:247
TMVA::PDEFoam
Definition: PDEFoam.h:79
PDEFoamDiscriminantDensity.h
TMVA::MethodPDEFoam::GetMulticlassValues
const std::vector< Float_t > & GetMulticlassValues()
Get the multiclass MVA response for the PDEFoam classifier.
Definition: MethodPDEFoam.cxx:789
TMVA::MethodPDEFoam::MakeClassSpecific
void MakeClassSpecific(std::ostream &, const TString &) const
write PDEFoam-specific classifier response NOT IMPLEMENTED YET!
Definition: MethodPDEFoam.cxx:1500
TMVA::MethodPDEFoam::fMaxDepth
UInt_t fMaxDepth
Definition: MethodPDEFoam.h:250
TMVA::MethodPDEFoam::UIntToTargetSelection
ETargetSelection UIntToTargetSelection(UInt_t its)
convert UInt_t to ETargetSelection (used for reading weight files)
Definition: MethodPDEFoam.cxx:1469
PDEFoamEvent.h
TMVA::Types::EAnalysisType
EAnalysisType
Definition: Types.h:150
TMVA::MethodPDEFoam::fTargetSelection
ETargetSelection fTargetSelection
Definition: MethodPDEFoam.h:256
TMVA::MethodPDEFoam::SetXminXmax
void SetXminXmax(TMVA::PDEFoam *)
Set Xmin, Xmax for every dimension in the given pdefoam object.
Definition: MethodPDEFoam.cxx:892
TMVA::MethodPDEFoam::GetNCuts
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'.
Definition: MethodPDEFoam.cxx:876
TMVA::MethodPDEFoam::fFoam
std::vector< PDEFoam * > fFoam
Definition: MethodPDEFoam.h:265
TMVA::MethodPDEFoam::HasAnalysisType
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...
Definition: MethodPDEFoam.cxx:160
PDEFoamKernelGauss.h
TMVA::MethodPDEFoam::DeclareCompatibilityOptions
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
Definition: MethodPDEFoam.cxx:243
TMVA::MethodPDEFoam::TrainMultiClassification
void TrainMultiClassification()
Create one unified foam (see TrainUnifiedClassification()) for each class, where the cells of foam i ...
Definition: MethodPDEFoam.cxx:556
TMVA::MethodPDEFoam::EKernel
EKernel
Definition: MethodPDEFoam.h:132
TMVA::MethodPDEFoam::fXmin
std::vector< Float_t > fXmin
Definition: MethodPDEFoam.h:263
PDEFoamTarget.h
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
PDEFoam.h
TMVA::MethodPDEFoam::GetKernel
EKernel GetKernel(void)
Definition: MethodPDEFoam.h:187
TMVA::MethodPDEFoam::Reset
virtual void Reset()
reset MethodPDEFoam:
Definition: MethodPDEFoam.cxx:1134
PDEFoamKernelLinN.h
TMVA::MethodPDEFoam::fFrac
Float_t fFrac
Definition: MethodPDEFoam.h:237
TMVA::MethodPDEFoam::ReadClonedFoamFromFile
PDEFoam * ReadClonedFoamFromFile(TFile *, const TString &)
Reads a foam with name 'foamname' from file, and returns a clone of the foam.
Definition: MethodPDEFoam.cxx:1374
TMVA::MethodPDEFoam::TrainSeparatedClassification
void TrainSeparatedClassification(void)
Creation of 2 separated foams: one for signal events, one for background events.
Definition: MethodPDEFoam.cxx:481
TFile
Definition: TFile.h:54
PDEFoamDiscriminant.h
TMVA::MethodPDEFoam::TrainUnifiedClassification
void TrainUnifiedClassification(void)
Create only one unified foam (fFoam[0]) whose cells contain the average discriminator (N_sig)/(N_sig ...
Definition: MethodPDEFoam.cxx:520
unsigned int
TMVA::MethodPDEFoam::TrainMultiTargetRegression
void TrainMultiTargetRegression(void)
Training one (multi target regression) foam, whose cells contain the average event density.
Definition: MethodPDEFoam.cxx:636
TMVA::MethodPDEFoam::fCutNmin
Bool_t fCutNmin
Definition: MethodPDEFoam.h:249
PDEFoamMultiTarget.h
TMVA::MethodPDEFoam::Train
void Train(void)
Train PDE-Foam depending on the set options.
Definition: MethodPDEFoam.cxx:430
TMVA::MethodPDEFoam::KernelToUInt
UInt_t KernelToUInt(EKernel ker) const
Definition: MethodPDEFoam.h:188
TMVA::MethodPDEFoam::CalcXminXmax
void CalcXminXmax()
Determine foam range [fXmin, fXmax] for all dimensions, such that a fraction of 'fFrac' events lie ou...
Definition: MethodPDEFoam.cxx:322
TMVA::MethodPDEFoam::fKernel
EKernel fKernel
Definition: MethodPDEFoam.h:253
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MethodPDEFoam::~MethodPDEFoam
virtual ~MethodPDEFoam(void)
destructor
Definition: MethodPDEFoam.cxx:310
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
TMVA::MethodPDEFoam::fXmax
std::vector< Float_t > fXmax
Definition: MethodPDEFoam.h:263
TMVA::MethodPDEFoam::fTargetSelectionStr
TString fTargetSelectionStr
Definition: MethodPDEFoam.h:255
TMVA::MethodPDEFoam::fFillFoamWithOrigWeights
Bool_t fFillFoamWithOrigWeights
Definition: MethodPDEFoam.h:257
TMVA::MethodPDEFoam
Definition: MethodPDEFoam.h:98
TMVA::MethodPDEFoam::fNmin
UInt_t fNmin
Definition: MethodPDEFoam.h:248
TMVA::MethodPDEFoam::TrainMonoTargetRegression
void TrainMonoTargetRegression(void)
Training one (mono target regression) foam, whose cells contain the average 0th target.
Definition: MethodPDEFoam.cxx:595
PDEFoamTargetDensity.h
type
int type
Definition: TGX11.cxx:121
TMVA::MethodPDEFoam::CreateRanking
const Ranking * CreateRanking()
Compute ranking of input variables from the number of cuts made in each PDEFoam dimension.
Definition: MethodPDEFoam.cxx:823
TMVA::MethodPDEFoam::fDiscrErrCut
Float_t fDiscrErrCut
Definition: MethodPDEFoam.h:238
TMVA::MethodPDEFoam::MethodPDEFoam
MethodPDEFoam(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="PDEFoam")
init PDEFoam objects
Definition: MethodPDEFoam.cxx:85
TMVA::MethodPDEFoam::fPeekMax
Bool_t fPeekMax
Definition: MethodPDEFoam.h:261
PDEFoamDecisionTreeDensity.h
TMVA::MethodPDEFoam::fVolFrac
Float_t fVolFrac
Definition: MethodPDEFoam.h:239
PDEFoamEventDensity.h
TMVA::PDEFoamCell
Definition: PDEFoamCell.h:66
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int