Logo ROOT   6.16/01
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
9Method : Fisher::Fisher
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:14:01 2021
14Host : Linux root-ubuntu-2004-3 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
15Dir : /home/sftnight/build/workspace/root-makedoc-v616/rootspi/rdoc/src/v6-16-00-patches/documentation/doxygen
16Training events: 10000
17Analysis type : [Classification]
18
19
20#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21
22# Set by User:
23V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
24H: "False" [Print method-specific help message]
25Method: "Fisher" [Discrimination method]
26# Default:
27VerbosityLevel: "Default" [Verbosity level]
28VarTransform: "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)"]
29CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
30IgnoreNegWeightsInTraining: "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
36NVar 4
37var1 var1 var1 var1 'F' [-4.16552305222,4.20716428757]
38var2 var2 var2 var2 'F' [-4.220682621,4.51537322998]
39var3 var3 var3 var3 'F' [-4.52968788147,4.82019376755]
40var4 var4 var4 var4 'F' [-4.64965724945,5.14146757126]
41NSpec 5
42eta eta eta eta 'F' [-2.49952101707,2.49992322922]
43abs(eta)<=1.3 FisherCat_cat1 FisherCat_cat1 FisherCat:Category_Fisher_1 pass 'C' [0,1]
44abs(eta)>1.3 FisherCat_cat2 FisherCat_cat2 FisherCat:Category_Fisher_2 pass 'C' [0,1]
45abs(eta)<=1.3 LikelihoodCat_cat1 LikelihoodCat_cat1 LikelihoodCat:Category_Likelihood_1pass 'C' [0,1]
46abs(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
60class 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
81class 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 {
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 override;
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 double fVmin[4];
160 double fVmax[4];
161 double NormVariable( double x, double xmin, double xmax ) const {
162 // normalise to output range: [-1, 1]
163 return 2*(x - xmin)/(xmax - xmin) - 1.0;
164 }
165
166 // type of input variable: 'F' or 'I'
167 char fType[4];
168
169 // initialize internal variables
170 void Initialize();
171 double GetMvaValue__( const std::vector<double>& inputValues ) const;
172
173 // private members (method specific)
174 double fFisher0;
175 std::vector<double> fFisherCoefficients;
176};
177
178inline void ReadFisher::Initialize()
179{
180 fFisher0 = -0.0233784980026;
181 fFisherCoefficients.push_back( -0.0529463889001 );
182 fFisherCoefficients.push_back( -0.0136473747837 );
183 fFisherCoefficients.push_back( 0.0960349295198 );
184 fFisherCoefficients.push_back( 0.21637932158 );
185
186 // sanity check
187 if (fFisherCoefficients.size() != fNvars) {
188 std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
189 << fFisherCoefficients.size() << " != " << fNvars << std::endl;
190 fStatusIsClean = false;
191 }
192}
193
194inline double ReadFisher::GetMvaValue__( const std::vector<double>& inputValues ) const
195{
196 double retval = fFisher0;
197 for (size_t ivar = 0; ivar < fNvars; ivar++) {
198 retval += fFisherCoefficients[ivar]*inputValues[ivar];
199 }
200
201 return retval;
202}
203
204// Clean up
205inline void ReadFisher::Clear()
206{
207 // clear coefficients
208 fFisherCoefficients.clear();
209}
210 inline double ReadFisher::GetMvaValue( const std::vector<double>& inputValues ) const
211 {
212 // classifier response value
213 double retval = 0;
214
215 // classifier response, sanity check first
216 if (!IsStatusClean()) {
217 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
218 << " because status is dirty" << std::endl;
219 retval = 0;
220 }
221 else {
222 retval = GetMvaValue__( inputValues );
223 }
224
225 return retval;
226 }
PyObject * fType
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
Double_t x[n]
Definition: legend1.C:17
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176