Logo ROOT   6.18/05
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
64
65namespace TMVA {
66
67 class MethodPDEFoam : public MethodBase {
68
69 public:
70
71 // kernel types
72 typedef enum EKernel { kNone=0, kGaus=1, kLinN=2 } EKernel;
73
74 MethodPDEFoam( const TString& jobName,
75 const TString& methodTitle,
76 DataSetInfo& dsi,
77 const TString& theOption = "PDEFoam");
78
80 const TString& theWeightFile);
81
82 virtual ~MethodPDEFoam( void );
83
84 virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
85
86 // training methods
87 void Train( void );
88 void TrainMonoTargetRegression( void ); // Regression output: one value
89 void TrainMultiTargetRegression( void ); // Regression output: any number of values
90 void TrainSeparatedClassification( void ); // Classification: one foam for Sig, one for Bg
91 void TrainUnifiedClassification( void ); // Classification: one foam for Signal and Bg
92 void TrainMultiClassification(); // Classification: one foam for every class
93
95
96 // write weights to stream
97 void AddWeightsXMLTo( void* parent ) const;
98
99 // read weights from stream
100 void ReadWeightsFromStream( std::istream & i );
101 void ReadWeightsFromXML ( void* wghtnode );
102
103 // write/read pure foams to/from file
104 void WriteFoamsToFile() const;
105 void ReadFoamsFromFile();
107
108 // calculate the MVA value
109 Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
110
111 // calculate multiclass MVA values
112 const std::vector<Float_t>& GetMulticlassValues();
113
114 // regression procedure
115 virtual const std::vector<Float_t>& GetRegressionValues();
116
117 // reset the method
118 virtual void Reset();
119
120 // ranking of input variables
121 const Ranking* CreateRanking();
122
123 // get number of cuts in every dimension, starting at cell
124 void GetNCuts(PDEFoamCell *cell, std::vector<UInt_t> &nCuts);
125
126 // helper functions to convert enum types to UInt_t and back
127 EKernel GetKernel( void ) { return fKernel; }
128 UInt_t KernelToUInt(EKernel ker) const { return UInt_t(ker); }
130 UInt_t TargetSelectionToUInt(ETargetSelection ts) const { return UInt_t(ts); }
131 ETargetSelection UIntToTargetSelection(UInt_t its);
132
133 protected:
134
135 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
136 void MakeClassSpecific( std::ostream&, const TString& ) const;
137
138 // get help message text
139 void GetHelpMessage() const;
140
141 // calculate the error on the Mva value
143
144 // calculate Xmin and Xmax for Foam
145 void CalcXminXmax();
146
147 // Set Xmin, Xmax in foam with index 'foam_index'
149
150 // create foam and set foam options
151 PDEFoam* InitFoam(TString, EFoamType, UInt_t cls=0);
152
153 // create pdefoam kernel
155
156 // delete all trained foams
157 void DeleteFoams();
158
159 // fill variable names into foam
160 void FillVariableNamesToFoam() const;
161
162 private:
163
164 // the option handling methods
165 void DeclareOptions();
167 void ProcessOptions();
168
169 // nice output
170 void PrintCoefficients( void );
171
172 // Square function (fastest implementation)
173 template<typename T> T Sqr(T x) const { return x*x; }
174
175 // options to be used
176 Bool_t fSigBgSeparated; // Separate Sig and Bg, or not
177 Float_t fFrac; // Fraction used for calc of Xmin, Xmax
178 Float_t fDiscrErrCut; // cut on discriminant error
179 Float_t fVolFrac; // volume fraction (used for density calculation during buildup)
180 Int_t fnCells; // Number of Cells (1000)
181 Int_t fnActiveCells; // Number of active cells
182 Int_t fnSampl; // Number of MC events per cell in build-up (1000)
183 Int_t fnBin; // Number of bins in build-up (100)
184 Int_t fEvPerBin; // Maximum events (equiv.) per bin in build-up (1000)
185
186 Bool_t fCompress; // compress foam output file
187 Bool_t fMultiTargetRegression; // do regression on multiple targets
188 UInt_t fNmin; // minimal number of events in cell necessary to split cell"
189 Bool_t fCutNmin; // Keep for bw compatibility: Grabbing cell with maximal RMS to split next (TFoam default)
190 UInt_t fMaxDepth; // maximum depth of cell tree
191
192 TString fKernelStr; // Kernel for GetMvaValue() (option string)
193 EKernel fKernel; // Kernel for GetMvaValue()
195 TString fTargetSelectionStr; // method of selecting the target (only mulit target regr.)
196 ETargetSelection fTargetSelection; // method of selecting the target (only mulit target regr.)
197 Bool_t fFillFoamWithOrigWeights; // fill the foam with boost weights
198 Bool_t fUseYesNoCell; // return -1 or 1 for bg or signal like event
199 TString fDTLogic; // use DT algorithm to split cells
200 EDTSeparation fDTSeparation; // enum which specifies the separation to use for the DT logic
201 Bool_t fPeekMax; // BACKWARDS COMPATIBILITY: peek up cell with max. driver integral for split
202
203 std::vector<Float_t> fXmin, fXmax; // range for histograms and foams
204
205 std::vector<PDEFoam*> fFoam; // grown PDEFoams
206
207 // default initialisation called by all constructors
208 void Init( void );
209
210 ClassDef(MethodPDEFoam,0); // Multi-dimensional probability density estimator using TFoam (PDE-Foam)
211 };
212
213} // namespace TMVA
214
215#endif // MethodPDEFoam_H
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
#define ClassDef(name, id)
Definition: Rtypes.h:326
int type
Definition: TGX11.cxx:120
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
Class that contains all the data information.
Definition: DataSetInfo.h:60
Virtual base Class for all MVA method.
Definition: MethodBase.h:109
virtual void ReadWeightsFromStream(std::istream &)=0
The PDEFoam method is an extension of the PDERS method, which divides the multi-dimensional phase spa...
Definition: MethodPDEFoam.h:67
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 PrintCoefficients(void)
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.
Bool_t fFillFoamWithOrigWeights
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.
MethodPDEFoam(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="PDEFoam")
init PDEFoam objects
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:77
Ranking for variables in method (implementation)
Definition: Ranking.h:48
EAnalysisType
Definition: Types.h:127
Basic string class.
Definition: TString.h:131
Double_t x[n]
Definition: legend1.C:17
double T(double x)
Definition: ChebyshevPol.h:34
create variable transformations