Logo ROOT   6.12/07
Reference Guide
TMVAClassification_PDEFoam.class.C
Go to the documentation of this file.
1 // Class: ReadPDEFoam
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : PDEFoam::PDEFoam
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.12/07 [396295]
12 Creator : sftnight
13 Date : Sat Sep 29 23:25:13 2018
14 Host : Linux ec-ubuntu-14-04-x86-64-2 3.13.0-157-generic #207-Ubuntu SMP Mon Aug 20 16:44:59 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /mnt/build/workspace/root-makedoc-v612/rootspi/rdoc/src/v6-12-00-patches/documentation/doxygen
16 Training events: 2000
17 Analysis type : [Classification]
18 
19 
20 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21 
22 # Set by User:
23 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
24 H: "False" [Print method-specific help message]
25 SigBgSeparate: "False" [Separate foams for signal and background]
26 TailCut: "1.000000e-03" [Fraction of outlier events that are excluded from the foam in each dimension]
27 VolFrac: "6.660000e-02" [Size of sampling box, used for density calculation during foam build-up (maximum value: 1.0 is equivalent to volume of entire foam)]
28 nActiveCells: "500" [Maximum number of active cells to be created by the foam]
29 nSampl: "2000" [Number of generated MC events per cell]
30 nBin: "5" [Number of bins in edge histograms]
31 Compress: "True" [Compress foam output file]
32 Nmin: "100" [Number of events in cell required to split cell]
33 Kernel: "None" [Kernel type used]
34 # Default:
35 VerbosityLevel: "Default" [Verbosity level]
36 VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
37 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
38 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
39 MultiTargetRegression: "False" [Do regression with multiple targets]
40 MaxDepth: "0" [Maximum depth of cell tree (0=unlimited)]
41 FillFoamWithOrigWeights: "False" [Fill foam with original or boost weights]
42 UseYesNoCell: "False" [Return -1 or 1 for bkg or signal like events]
43 DTLogic: "None" [Use decision tree algorithm to split cells]
44 TargetSelection: "Mean" [Target selection method]
45 ##
46 
47 
48 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
49 
50 NVar 4
51 var1+var2 myvar1 myvar1 myvar1 'F' [-8.14423561096,7.26972866058]
52 var1-var2 myvar2 myvar2 Expression 2 'F' [-3.96643972397,4.0258936882]
53 var3 var3 var3 Variable 3 units 'F' [-5.03730010986,4.27845287323]
54 var4 var4 var4 Variable 4 units 'F' [-5.95050764084,4.64035463333]
55 NSpec 2
56 var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.67800140381]
57 var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0170021057]
58 
59 
60 ============================================================================ */
61 
62 #include <array>
63 #include <vector>
64 #include <cmath>
65 #include <string>
66 #include <iostream>
67 
68 #ifndef IClassifierReader__def
69 #define IClassifierReader__def
70 
71 class IClassifierReader {
72 
73  public:
74 
75  // constructor
76  IClassifierReader() : fStatusIsClean( true ) {}
77  virtual ~IClassifierReader() {}
78 
79  // return classifier response
80  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
81 
82  // returns classifier status
83  bool IsStatusClean() const { return fStatusIsClean; }
84 
85  protected:
86 
87  bool fStatusIsClean;
88 };
89 
90 #endif
91 
92 class ReadPDEFoam : public IClassifierReader {
93 
94  public:
95 
96  // constructor
97  ReadPDEFoam( std::vector<std::string>& theInputVars )
98  : IClassifierReader(),
99  fClassName( "ReadPDEFoam" ),
100  fNvars( 4 ),
101  fIsNormalised( false )
102  {
103  // the training input variables
104  const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
105 
106  // sanity checks
107  if (theInputVars.size() <= 0) {
108  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
109  fStatusIsClean = false;
110  }
111 
112  if (theInputVars.size() != fNvars) {
113  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
114  << theInputVars.size() << " != " << fNvars << std::endl;
115  fStatusIsClean = false;
116  }
117 
118  // validate input variables
119  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
120  if (theInputVars[ivar] != inputVars[ivar]) {
121  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
122  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
123  fStatusIsClean = false;
124  }
125  }
126 
127  // initialize min and max vectors (for normalisation)
128  fVmin[0] = 0;
129  fVmax[0] = 0;
130  fVmin[1] = 0;
131  fVmax[1] = 0;
132  fVmin[2] = 0;
133  fVmax[2] = 0;
134  fVmin[3] = 0;
135  fVmax[3] = 0;
136 
137  // initialize input variable types
138  fType[0] = 'F';
139  fType[1] = 'F';
140  fType[2] = 'F';
141  fType[3] = 'F';
142 
143  // initialize constants
144  Initialize();
145 
146  }
147 
148  // destructor
149  virtual ~ReadPDEFoam() {
150  Clear(); // method-specific
151  }
152 
153  // the classifier response
154  // "inputValues" is a vector of input values in the same order as the
155  // variables given to the constructor
156  double GetMvaValue( const std::vector<double>& inputValues ) const;
157 
158  private:
159 
160  // method-specific destructor
161  void Clear();
162 
163  // common member variables
164  const char* fClassName;
165 
166  const size_t fNvars;
167  size_t GetNvar() const { return fNvars; }
168  char GetType( int ivar ) const { return fType[ivar]; }
169 
170  // normalisation of input variables
171  const bool fIsNormalised;
172  bool IsNormalised() const { return fIsNormalised; }
173  double fVmin[4];
174  double fVmax[4];
175  double NormVariable( double x, double xmin, double xmax ) const {
176  // normalise to output range: [-1, 1]
177  return 2*(x - xmin)/(xmax - xmin) - 1.0;
178  }
179 
180  // type of input variable: 'F' or 'I'
181  char fType[4];
182 
183  // initialize internal variables
184  void Initialize();
185  double GetMvaValue__( const std::vector<double>& inputValues ) const;
186 
187  // private members (method specific)
188  inline double ReadPDEFoam::GetMvaValue( const std::vector<double>& inputValues ) const
189  {
190  // classifier response value
191  double retval = 0;
192 
193  // classifier response, sanity check first
194  if (!IsStatusClean()) {
195  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
196  << " because status is dirty" << std::endl;
197  retval = 0;
198  }
199  else {
200  if (IsNormalised()) {
201  // normalise variables
202  std::vector<double> iV;
203  iV.reserve(inputValues.size());
204  int ivar = 0;
205  for (std::vector<double>::const_iterator varIt = inputValues.begin();
206  varIt != inputValues.end(); varIt++, ivar++) {
207  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
208  }
209  retval = GetMvaValue__( iV );
210  }
211  else {
212  retval = GetMvaValue__( inputValues );
213  }
214  }
215 
216  return retval;
217  }
float xmin
Definition: THbookFile.cxx:93
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
Double_t x[n]
Definition: legend1.C:17
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
float xmax
Definition: THbookFile.cxx:93
PyObject * fType