Logo ROOT   6.12/07
Reference Guide
TMVAClassification_PDERS.class.C
Go to the documentation of this file.
1 // Class: ReadPDERS
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : PDERS::PDERS
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 VolumeRangeMode: "Adaptive" [Method to determine volume size]
26 KernelEstimator: "Gauss" [Kernel estimation function]
27 NEventsMin: "4.000000e+02" [nEventsMin for adaptive volume range]
28 NEventsMax: "6.000000e+02" [nEventsMax for adaptive volume range]
29 GaussSigma: "3.000000e-01" [Width (wrt volume size) of Gaussian kernel estimator]
30 NormTree: "True" [Normalize binary search tree]
31 # Default:
32 VerbosityLevel: "Default" [Verbosity level]
33 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)"]
34 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
35 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
36 DeltaFrac: "3.000000e+00" [nEventsMin/Max for minmax and rms volume range]
37 MaxVIterations: "1.500000e+02" [MaxVIterations for adaptive volume range]
38 InitialScale: "9.900000e-01" [InitialScale for adaptive volume range]
39 ##
40 
41 
42 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
43 
44 NVar 4
45 var1+var2 myvar1 myvar1 myvar1 'F' [-8.14423561096,7.26972866058]
46 var1-var2 myvar2 myvar2 Expression 2 'F' [-3.96643972397,4.0258936882]
47 var3 var3 var3 Variable 3 units 'F' [-5.03730010986,4.27845287323]
48 var4 var4 var4 Variable 4 units 'F' [-5.95050764084,4.64035463333]
49 NSpec 2
50 var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.67800140381]
51 var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0170021057]
52 
53 
54 ============================================================================ */
55 
56 #include <array>
57 #include <vector>
58 #include <cmath>
59 #include <string>
60 #include <iostream>
61 
62 #ifndef IClassifierReader__def
63 #define IClassifierReader__def
64 
65 class IClassifierReader {
66 
67  public:
68 
69  // constructor
70  IClassifierReader() : fStatusIsClean( true ) {}
71  virtual ~IClassifierReader() {}
72 
73  // return classifier response
74  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
75 
76  // returns classifier status
77  bool IsStatusClean() const { return fStatusIsClean; }
78 
79  protected:
80 
81  bool fStatusIsClean;
82 };
83 
84 #endif
85 
86 class ReadPDERS : public IClassifierReader {
87 
88  public:
89 
90  // constructor
91  ReadPDERS( std::vector<std::string>& theInputVars )
92  : IClassifierReader(),
93  fClassName( "ReadPDERS" ),
94  fNvars( 4 ),
95  fIsNormalised( false )
96  {
97  // the training input variables
98  const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
99 
100  // sanity checks
101  if (theInputVars.size() <= 0) {
102  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
103  fStatusIsClean = false;
104  }
105 
106  if (theInputVars.size() != fNvars) {
107  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
108  << theInputVars.size() << " != " << fNvars << std::endl;
109  fStatusIsClean = false;
110  }
111 
112  // validate input variables
113  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
114  if (theInputVars[ivar] != inputVars[ivar]) {
115  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
116  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
117  fStatusIsClean = false;
118  }
119  }
120 
121  // initialize min and max vectors (for normalisation)
122  fVmin[0] = 0;
123  fVmax[0] = 0;
124  fVmin[1] = 0;
125  fVmax[1] = 0;
126  fVmin[2] = 0;
127  fVmax[2] = 0;
128  fVmin[3] = 0;
129  fVmax[3] = 0;
130 
131  // initialize input variable types
132  fType[0] = 'F';
133  fType[1] = 'F';
134  fType[2] = 'F';
135  fType[3] = 'F';
136 
137  // initialize constants
138  Initialize();
139 
140  }
141 
142  // destructor
143  virtual ~ReadPDERS() {
144  Clear(); // method-specific
145  }
146 
147  // the classifier response
148  // "inputValues" is a vector of input values in the same order as the
149  // variables given to the constructor
150  double GetMvaValue( const std::vector<double>& inputValues ) const;
151 
152  private:
153 
154  // method-specific destructor
155  void Clear();
156 
157  // common member variables
158  const char* fClassName;
159 
160  const size_t fNvars;
161  size_t GetNvar() const { return fNvars; }
162  char GetType( int ivar ) const { return fType[ivar]; }
163 
164  // normalisation of input variables
165  const bool fIsNormalised;
166  bool IsNormalised() const { return fIsNormalised; }
167  double fVmin[4];
168  double fVmax[4];
169  double NormVariable( double x, double xmin, double xmax ) const {
170  // normalise to output range: [-1, 1]
171  return 2*(x - xmin)/(xmax - xmin) - 1.0;
172  }
173 
174  // type of input variable: 'F' or 'I'
175  char fType[4];
176 
177  // initialize internal variables
178  void Initialize();
179  double GetMvaValue__( const std::vector<double>& inputValues ) const;
180 
181  // private members (method specific)
182  // not implemented for class: "ReadPDERS"
183 };
184  inline double ReadPDERS::GetMvaValue( const std::vector<double>& inputValues ) const
185  {
186  // classifier response value
187  double retval = 0;
188 
189  // classifier response, sanity check first
190  if (!IsStatusClean()) {
191  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
192  << " because status is dirty" << std::endl;
193  retval = 0;
194  }
195  else {
196  if (IsNormalised()) {
197  // normalise variables
198  std::vector<double> iV;
199  iV.reserve(inputValues.size());
200  int ivar = 0;
201  for (std::vector<double>::const_iterator varIt = inputValues.begin();
202  varIt != inputValues.end(); varIt++, ivar++) {
203  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
204  }
205  retval = GetMvaValue__( iV );
206  }
207  else {
208  retval = GetMvaValue__( inputValues );
209  }
210  }
211 
212  return retval;
213  }
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