Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 #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 namespace 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 
79  MethodPDEFoam( DataSetInfo& dsi,
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 
94  using MethodBase::ReadWeightsFromStream;
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();
106  PDEFoam* ReadClonedFoamFromFile(TFile*, const TString&);
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); }
129  EKernel UIntToKernel(UInt_t iker);
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
142  Double_t CalculateMVAError();
143 
144  // calculate Xmin and Xmax for Foam
145  void CalcXminXmax();
146 
147  // Set Xmin, Xmax in foam with index 'foam_index'
148  void SetXminXmax(TMVA::PDEFoam*);
149 
150  // create foam and set foam options
151  PDEFoam* InitFoam(TString, EFoamType, UInt_t cls=0);
152 
153  // create pdefoam kernel
154  PDEFoamKernelBase* CreatePDEFoamKernel();
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();
166  void DeclareCompatibilityOptions();
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()
194  PDEFoamKernelBase *fKernelEstimator;// Kernel estimator
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