Logo ROOT   6.12/07
Reference Guide
TMVAClassificationCategory_Fisher.class.C
Go to the documentation of this file.
1 // Class: ReadFisher
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : Fisher::Fisher
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.12/07 [396295]
12 Creator : sftnight
13 Date : Sat Sep 29 23:25:45 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: 10000
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 Method: "Fisher" [Discrimination method]
26 # Default:
27 VerbosityLevel: "Default" [Verbosity level]
28 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)"]
29 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
30 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
31 ##
32 
33 
34 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
35 
36 NVar 4
37 var1 var1 var1 var1 'F' [-5.31190872192,4.21716070175]
38 var2 var2 var2 var2 'F' [-4.220682621,4.57174968719]
39 var3 var3 var3 var3 'F' [-4.58069658279,4.82019376755]
40 var4 var4 var4 var4 'F' [-5.10020828247,4.97665786743]
41 NSpec 5
42 eta eta eta eta 'F' [-2.49952101707,2.49999904633]
43 abs(eta)<=1.3 FisherCat_cat1 FisherCat_cat1 FisherCat:Category_Fisher_1 pass 'C' [0,1]
44 abs(eta)>1.3 FisherCat_cat2 FisherCat_cat2 FisherCat:Category_Fisher_2 pass 'C' [0,1]
45 abs(eta)<=1.3 LikelihoodCat_cat1 LikelihoodCat_cat1 LikelihoodCat:Category_Likelihood_1pass 'C' [0,1]
46 abs(eta)>1.3 LikelihoodCat_cat2 LikelihoodCat_cat2 LikelihoodCat:Category_Likelihood_2pass 'C' [0,1]
47 
48 
49 ============================================================================ */
50 
51 #include <array>
52 #include <vector>
53 #include <cmath>
54 #include <string>
55 #include <iostream>
56 
57 #ifndef IClassifierReader__def
58 #define IClassifierReader__def
59 
60 class IClassifierReader {
61 
62  public:
63 
64  // constructor
65  IClassifierReader() : fStatusIsClean( true ) {}
66  virtual ~IClassifierReader() {}
67 
68  // return classifier response
69  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
70 
71  // returns classifier status
72  bool IsStatusClean() const { return fStatusIsClean; }
73 
74  protected:
75 
76  bool fStatusIsClean;
77 };
78 
79 #endif
80 
81 class ReadFisher : public IClassifierReader {
82 
83  public:
84 
85  // constructor
86  ReadFisher( std::vector<std::string>& theInputVars )
87  : IClassifierReader(),
88  fClassName( "ReadFisher" ),
89  fNvars( 4 ),
90  fIsNormalised( false )
91  {
92  // the training input variables
93  const char* inputVars[] = { "var1", "var2", "var3", "var4" };
94 
95  // sanity checks
96  if (theInputVars.size() <= 0) {
97  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
98  fStatusIsClean = false;
99  }
100 
101  if (theInputVars.size() != fNvars) {
102  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
103  << theInputVars.size() << " != " << fNvars << std::endl;
104  fStatusIsClean = false;
105  }
106 
107  // validate input variables
108  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
109  if (theInputVars[ivar] != inputVars[ivar]) {
110  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
111  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
112  fStatusIsClean = false;
113  }
114  }
115 
116  // initialize min and max vectors (for normalisation)
117  fVmin[0] = 0;
118  fVmax[0] = 0;
119  fVmin[1] = 0;
120  fVmax[1] = 0;
121  fVmin[2] = 0;
122  fVmax[2] = 0;
123  fVmin[3] = 0;
124  fVmax[3] = 0;
125 
126  // initialize input variable types
127  fType[0] = 'F';
128  fType[1] = 'F';
129  fType[2] = 'F';
130  fType[3] = 'F';
131 
132  // initialize constants
133  Initialize();
134 
135  }
136 
137  // destructor
138  virtual ~ReadFisher() {
139  Clear(); // method-specific
140  }
141 
142  // the classifier response
143  // "inputValues" is a vector of input values in the same order as the
144  // variables given to the constructor
145  double GetMvaValue( const std::vector<double>& inputValues ) const;
146 
147  private:
148 
149  // method-specific destructor
150  void Clear();
151 
152  // common member variables
153  const char* fClassName;
154 
155  const size_t fNvars;
156  size_t GetNvar() const { return fNvars; }
157  char GetType( int ivar ) const { return fType[ivar]; }
158 
159  // normalisation of input variables
160  const bool fIsNormalised;
161  bool IsNormalised() const { return fIsNormalised; }
162  double fVmin[4];
163  double fVmax[4];
164  double NormVariable( double x, double xmin, double xmax ) const {
165  // normalise to output range: [-1, 1]
166  return 2*(x - xmin)/(xmax - xmin) - 1.0;
167  }
168 
169  // type of input variable: 'F' or 'I'
170  char fType[4];
171 
172  // initialize internal variables
173  void Initialize();
174  double GetMvaValue__( const std::vector<double>& inputValues ) const;
175 
176  // private members (method specific)
177  double fFisher0;
178  std::vector<double> fFisherCoefficients;
179 };
180 
181 inline void ReadFisher::Initialize()
182 {
183  fFisher0 = -0.0242809098936;
184  fFisherCoefficients.push_back( -0.0589191040706 );
185  fFisherCoefficients.push_back( -0.0071916715741 );
186  fFisherCoefficients.push_back( 0.0968408275092 );
187  fFisherCoefficients.push_back( 0.219092209175 );
188 
189  // sanity check
190  if (fFisherCoefficients.size() != fNvars) {
191  std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
192  << fFisherCoefficients.size() << " != " << fNvars << std::endl;
193  fStatusIsClean = false;
194  }
195 }
196 
197 inline double ReadFisher::GetMvaValue__( const std::vector<double>& inputValues ) const
198 {
199  double retval = fFisher0;
200  for (size_t ivar = 0; ivar < fNvars; ivar++) {
201  retval += fFisherCoefficients[ivar]*inputValues[ivar];
202  }
203 
204  return retval;
205 }
206 
207 // Clean up
208 inline void ReadFisher::Clear()
209 {
210  // clear coefficients
211  fFisherCoefficients.clear();
212 }
213  inline double ReadFisher::GetMvaValue( const std::vector<double>& inputValues ) const
214  {
215  // classifier response value
216  double retval = 0;
217 
218  // classifier response, sanity check first
219  if (!IsStatusClean()) {
220  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
221  << " because status is dirty" << std::endl;
222  retval = 0;
223  }
224  else {
225  if (IsNormalised()) {
226  // normalise variables
227  std::vector<double> iV;
228  iV.reserve(inputValues.size());
229  int ivar = 0;
230  for (std::vector<double>::const_iterator varIt = inputValues.begin();
231  varIt != inputValues.end(); varIt++, ivar++) {
232  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
233  }
234  retval = GetMvaValue__( iV );
235  }
236  else {
237  retval = GetMvaValue__( inputValues );
238  }
239  }
240 
241  return retval;
242  }
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