Logo ROOT   6.10/09
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.10/09 [395785]
12 Creator : sftnight
13 Date : Thu May 31 12:04:23 2018
14 Host : Linux SFT-ubuntu-1710-1 4.13.0-31-generic #34-Ubuntu SMP Fri Jan 19 16:34:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /mnt/build/workspace/root-makedoc-v610/rootspi/rdoc/src/v6-10-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 <vector>
57 #include <cmath>
58 #include <string>
59 #include <iostream>
60 
61 #ifndef IClassifierReader__def
62 #define IClassifierReader__def
63 
64 class IClassifierReader {
65 
66  public:
67 
68  // constructor
69  IClassifierReader() : fStatusIsClean( true ) {}
70  virtual ~IClassifierReader() {}
71 
72  // return classifier response
73  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
74 
75  // returns classifier status
76  bool IsStatusClean() const { return fStatusIsClean; }
77 
78  protected:
79 
80  bool fStatusIsClean;
81 };
82 
83 #endif
84 
85 class ReadPDERS : public IClassifierReader {
86 
87  public:
88 
89  // constructor
90  ReadPDERS( std::vector<std::string>& theInputVars )
91  : IClassifierReader(),
92  fClassName( "ReadPDERS" ),
93  fNvars( 4 ),
94  fIsNormalised( false )
95  {
96  // the training input variables
97  const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
98 
99  // sanity checks
100  if (theInputVars.size() <= 0) {
101  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
102  fStatusIsClean = false;
103  }
104 
105  if (theInputVars.size() != fNvars) {
106  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
107  << theInputVars.size() << " != " << fNvars << std::endl;
108  fStatusIsClean = false;
109  }
110 
111  // validate input variables
112  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
113  if (theInputVars[ivar] != inputVars[ivar]) {
114  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
115  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
116  fStatusIsClean = false;
117  }
118  }
119 
120  // initialize min and max vectors (for normalisation)
121  fVmin[0] = 0;
122  fVmax[0] = 0;
123  fVmin[1] = 0;
124  fVmax[1] = 0;
125  fVmin[2] = 0;
126  fVmax[2] = 0;
127  fVmin[3] = 0;
128  fVmax[3] = 0;
129 
130  // initialize input variable types
131  fType[0] = 'F';
132  fType[1] = 'F';
133  fType[2] = 'F';
134  fType[3] = 'F';
135 
136  // initialize constants
137  Initialize();
138 
139  }
140 
141  // destructor
142  virtual ~ReadPDERS() {
143  Clear(); // method-specific
144  }
145 
146  // the classifier response
147  // "inputValues" is a vector of input values in the same order as the
148  // variables given to the constructor
149  double GetMvaValue( const std::vector<double>& inputValues ) const;
150 
151  private:
152 
153  // method-specific destructor
154  void Clear();
155 
156  // common member variables
157  const char* fClassName;
158 
159  const size_t fNvars;
160  size_t GetNvar() const { return fNvars; }
161  char GetType( int ivar ) const { return fType[ivar]; }
162 
163  // normalisation of input variables
164  const bool fIsNormalised;
165  bool IsNormalised() const { return fIsNormalised; }
166  double fVmin[4];
167  double fVmax[4];
168  double NormVariable( double x, double xmin, double xmax ) const {
169  // normalise to output range: [-1, 1]
170  return 2*(x - xmin)/(xmax - xmin) - 1.0;
171  }
172 
173  // type of input variable: 'F' or 'I'
174  char fType[4];
175 
176  // initialize internal variables
177  void Initialize();
178  double GetMvaValue__( const std::vector<double>& inputValues ) const;
179 
180  // private members (method specific)
181  // not implemented for class: "ReadPDERS"
182 };
183  inline double ReadPDERS::GetMvaValue( const std::vector<double>& inputValues ) const
184  {
185  // classifier response value
186  double retval = 0;
187 
188  // classifier response, sanity check first
189  if (!IsStatusClean()) {
190  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
191  << " because status is dirty" << std::endl;
192  retval = 0;
193  }
194  else {
195  if (IsNormalised()) {
196  // normalise variables
197  std::vector<double> iV;
198  iV.reserve(inputValues.size());
199  int ivar = 0;
200  for (std::vector<double>::const_iterator varIt = inputValues.begin();
201  varIt != inputValues.end(); varIt++, ivar++) {
202  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
203  }
204  retval = GetMvaValue__( iV );
205  }
206  else {
207  retval = GetMvaValue__( inputValues );
208  }
209  }
210 
211  return retval;
212  }
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