Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
64
65#include <vector>
66
67namespace 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
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'
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()
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
unsigned int UInt_t
Definition RtypesCore.h:46
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
#define ClassDef(name, id)
Definition Rtypes.h:325
int type
Definition TGX11.cxx:121
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
Class that contains all the data information.
Definition DataSetInfo.h:62
Virtual base Class for all MVA method.
Definition MethodBase.h:111
virtual void ReadWeightsFromStream(std::istream &)=0
The PDEFoam method is an extension of the PDERS method, which divides the multi-dimensional phase spa...
const Ranking * CreateRanking()
Compute ranking of input variables from the number of cuts made in each PDEFoam dimension.
void Init(void)
default initialization called by all constructors
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...
void Train(void)
Train PDE-Foam depending on the set options.
const std::vector< Float_t > & GetMulticlassValues()
Get the multiclass MVA response for the PDEFoam classifier.
Double_t CalculateMVAError()
Calculate the error on the Mva value.
void TrainMultiClassification()
Create one unified foam (see TrainUnifiedClassification()) for each class, where the cells of foam i ...
std::vector< PDEFoam * > fFoam
void TrainMultiTargetRegression(void)
Training one (multi target regression) foam, whose cells contain the average event density.
void ReadWeightsFromXML(void *wghtnode)
read PDEFoam variables from xml weight file
void DeleteFoams()
Deletes all trained foams.
void ReadWeightsFromStream(std::istream &i)
read options and internal parameters
virtual ~MethodPDEFoam(void)
destructor
void DeclareOptions()
Declare MethodPDEFoam options.
EKernel GetKernel(void)
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...
virtual const std::vector< Float_t > & GetRegressionValues()
Return regression values for both multi- and mono-target regression.
void FillVariableNamesToFoam() const
store the variable names in all foams
void TrainMonoTargetRegression(void)
Training one (mono target regression) foam, whose cells contain the average 0th target.
void TrainUnifiedClassification(void)
Create only one unified foam (fFoam[0]) whose cells contain the average discriminator (N_sig)/(N_sig ...
void ReadFoamsFromFile()
read foams from file
EKernel UIntToKernel(UInt_t iker)
convert UInt_t to EKernel (used for reading weight files)
PDEFoamKernelBase * CreatePDEFoamKernel()
create a pdefoam kernel estimator, depending on the current value of fKernel
void CalcXminXmax()
Determine foam range [fXmin, fXmax] for all dimensions, such that a fraction of 'fFrac' events lie ou...
void MakeClassSpecific(std::ostream &, const TString &) const
write PDEFoam-specific classifier response NOT IMPLEMENTED YET!
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'.
PDEFoam * ReadClonedFoamFromFile(TFile *, const TString &)
Reads a foam with name 'foamname' from file, and returns a clone of the foam.
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Return Mva-Value.
ETargetSelection UIntToTargetSelection(UInt_t its)
convert UInt_t to ETargetSelection (used for reading weight files)
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
UInt_t KernelToUInt(EKernel ker) const
PDEFoamKernelBase * fKernelEstimator
void GetHelpMessage() const
provide help message
void TrainSeparatedClassification(void)
Creation of 2 separated foams: one for signal events, one for background events.
EDTSeparation fDTSeparation
void SetXminXmax(TMVA::PDEFoam *)
Set Xmin, Xmax for every dimension in the given pdefoam object.
virtual void Reset()
reset MethodPDEFoam:
void WriteFoamsToFile() const
Write PDEFoams to file.
std::vector< Float_t > fXmin
std::vector< Float_t > fXmax
ETargetSelection fTargetSelection
UInt_t TargetSelectionToUInt(ETargetSelection ts) const
void AddWeightsXMLTo(void *parent) const
create XML output of PDEFoam method variables
void ProcessOptions()
process user options
This class is the abstract kernel interface for PDEFoam.
Implementation of PDEFoam.
Definition PDEFoam.h:79
Ranking for variables in method (implementation)
Definition Ranking.h:48
Basic string class.
Definition TString.h:136
Double_t x[n]
Definition legend1.C:17
create variable transformations