Logo ROOT   6.10/09
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.10/09 [395785]
12 Creator : sftnight
13 Date : Thu May 31 12:04:43 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: 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 <vector>
52 #include <cmath>
53 #include <string>
54 #include <iostream>
55 
56 #ifndef IClassifierReader__def
57 #define IClassifierReader__def
58 
59 class IClassifierReader {
60 
61  public:
62 
63  // constructor
64  IClassifierReader() : fStatusIsClean( true ) {}
65  virtual ~IClassifierReader() {}
66 
67  // return classifier response
68  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
69 
70  // returns classifier status
71  bool IsStatusClean() const { return fStatusIsClean; }
72 
73  protected:
74 
75  bool fStatusIsClean;
76 };
77 
78 #endif
79 
80 class ReadFisher : public IClassifierReader {
81 
82  public:
83 
84  // constructor
85  ReadFisher( std::vector<std::string>& theInputVars )
86  : IClassifierReader(),
87  fClassName( "ReadFisher" ),
88  fNvars( 4 ),
89  fIsNormalised( false )
90  {
91  // the training input variables
92  const char* inputVars[] = { "var1", "var2", "var3", "var4" };
93 
94  // sanity checks
95  if (theInputVars.size() <= 0) {
96  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
97  fStatusIsClean = false;
98  }
99 
100  if (theInputVars.size() != fNvars) {
101  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
102  << theInputVars.size() << " != " << fNvars << std::endl;
103  fStatusIsClean = false;
104  }
105 
106  // validate input variables
107  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
108  if (theInputVars[ivar] != inputVars[ivar]) {
109  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
110  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
111  fStatusIsClean = false;
112  }
113  }
114 
115  // initialize min and max vectors (for normalisation)
116  fVmin[0] = 0;
117  fVmax[0] = 0;
118  fVmin[1] = 0;
119  fVmax[1] = 0;
120  fVmin[2] = 0;
121  fVmax[2] = 0;
122  fVmin[3] = 0;
123  fVmax[3] = 0;
124 
125  // initialize input variable types
126  fType[0] = 'F';
127  fType[1] = 'F';
128  fType[2] = 'F';
129  fType[3] = 'F';
130 
131  // initialize constants
132  Initialize();
133 
134  }
135 
136  // destructor
137  virtual ~ReadFisher() {
138  Clear(); // method-specific
139  }
140 
141  // the classifier response
142  // "inputValues" is a vector of input values in the same order as the
143  // variables given to the constructor
144  double GetMvaValue( const std::vector<double>& inputValues ) const;
145 
146  private:
147 
148  // method-specific destructor
149  void Clear();
150 
151  // common member variables
152  const char* fClassName;
153 
154  const size_t fNvars;
155  size_t GetNvar() const { return fNvars; }
156  char GetType( int ivar ) const { return fType[ivar]; }
157 
158  // normalisation of input variables
159  const bool fIsNormalised;
160  bool IsNormalised() const { return fIsNormalised; }
161  double fVmin[4];
162  double fVmax[4];
163  double NormVariable( double x, double xmin, double xmax ) const {
164  // normalise to output range: [-1, 1]
165  return 2*(x - xmin)/(xmax - xmin) - 1.0;
166  }
167 
168  // type of input variable: 'F' or 'I'
169  char fType[4];
170 
171  // initialize internal variables
172  void Initialize();
173  double GetMvaValue__( const std::vector<double>& inputValues ) const;
174 
175  // private members (method specific)
176  double fFisher0;
177  std::vector<double> fFisherCoefficients;
178 };
179 
180 inline void ReadFisher::Initialize()
181 {
182  fFisher0 = -0.024433136605;
183  fFisherCoefficients.push_back( -0.0588850814086 );
184  fFisherCoefficients.push_back( -0.00612727901444 );
185  fFisherCoefficients.push_back( 0.0964243016268 );
186  fFisherCoefficients.push_back( 0.218679158219 );
187 
188  // sanity check
189  if (fFisherCoefficients.size() != fNvars) {
190  std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
191  << fFisherCoefficients.size() << " != " << fNvars << std::endl;
192  fStatusIsClean = false;
193  }
194 }
195 
196 inline double ReadFisher::GetMvaValue__( const std::vector<double>& inputValues ) const
197 {
198  double retval = fFisher0;
199  for (size_t ivar = 0; ivar < fNvars; ivar++) {
200  retval += fFisherCoefficients[ivar]*inputValues[ivar];
201  }
202 
203  return retval;
204 }
205 
206 // Clean up
207 inline void ReadFisher::Clear()
208 {
209  // clear coefficients
210  fFisherCoefficients.clear();
211 }
212  inline double ReadFisher::GetMvaValue( const std::vector<double>& inputValues ) const
213  {
214  // classifier response value
215  double retval = 0;
216 
217  // classifier response, sanity check first
218  if (!IsStatusClean()) {
219  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
220  << " because status is dirty" << std::endl;
221  retval = 0;
222  }
223  else {
224  if (IsNormalised()) {
225  // normalise variables
226  std::vector<double> iV;
227  iV.reserve(inputValues.size());
228  int ivar = 0;
229  for (std::vector<double>::const_iterator varIt = inputValues.begin();
230  varIt != inputValues.end(); varIt++, ivar++) {
231  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
232  }
233  retval = GetMvaValue__( iV );
234  }
235  else {
236  retval = GetMvaValue__( inputValues );
237  }
238  }
239 
240  return retval;
241  }
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