Logo ROOT   6.16/01
Reference Guide
TMVACrossValidation_Fisher_fold2.class.C
Go to the documentation of this file.
1// Class: ReadFisher_fold2
2// Automatically generated by MethodBase::MakeClass
3//
4
5/* configuration options =====================================================
6
7#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8
9Method : Fisher::Fisher_fold2
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:14:15 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: 999
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)]
24VarTransform: "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)"]
25H: "False" [Print method-specific help message]
26Method: "Fisher" [Discrimination method]
27# Default:
28VerbosityLevel: "Default" [Verbosity level]
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 2
37x x x x 'F' [-4.10750675201,4.09692668915]
38y y y y 'F' [-4.85200452805,4.07606744766]
39NSpec 1
40eventID eventID eventID I 'F' [1,1000]
41
42
43============================================================================ */
44
45#include <array>
46#include <vector>
47#include <cmath>
48#include <string>
49#include <iostream>
50
51#ifndef IClassifierReader__def
52#define IClassifierReader__def
53
54class IClassifierReader {
55
56 public:
57
58 // constructor
59 IClassifierReader() : fStatusIsClean( true ) {}
60 virtual ~IClassifierReader() {}
61
62 // return classifier response
63 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
64
65 // returns classifier status
66 bool IsStatusClean() const { return fStatusIsClean; }
67
68 protected:
69
70 bool fStatusIsClean;
71};
72
73#endif
74
75class ReadFisher_fold2 : public IClassifierReader {
76
77 public:
78
79 // constructor
80 ReadFisher_fold2( std::vector<std::string>& theInputVars )
81 : IClassifierReader(),
82 fClassName( "ReadFisher_fold2" ),
83 fNvars( 2 )
84 {
85 // the training input variables
86 const char* inputVars[] = { "x", "y" };
87
88 // sanity checks
89 if (theInputVars.size() <= 0) {
90 std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
91 fStatusIsClean = false;
92 }
93
94 if (theInputVars.size() != fNvars) {
95 std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
96 << theInputVars.size() << " != " << fNvars << std::endl;
97 fStatusIsClean = false;
98 }
99
100 // validate input variables
101 for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
102 if (theInputVars[ivar] != inputVars[ivar]) {
103 std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
104 << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
105 fStatusIsClean = false;
106 }
107 }
108
109 // initialize min and max vectors (for normalisation)
110 fVmin[0] = 0;
111 fVmax[0] = 0;
112 fVmin[1] = 0;
113 fVmax[1] = 0;
114
115 // initialize input variable types
116 fType[0] = 'F';
117 fType[1] = 'F';
118
119 // initialize constants
120 Initialize();
121
122 }
123
124 // destructor
125 virtual ~ReadFisher_fold2() {
126 Clear(); // method-specific
127 }
128
129 // the classifier response
130 // "inputValues" is a vector of input values in the same order as the
131 // variables given to the constructor
132 double GetMvaValue( const std::vector<double>& inputValues ) const override;
133
134 private:
135
136 // method-specific destructor
137 void Clear();
138
139 // common member variables
140 const char* fClassName;
141
142 const size_t fNvars;
143 size_t GetNvar() const { return fNvars; }
144 char GetType( int ivar ) const { return fType[ivar]; }
145
146 // normalisation of input variables
147 double fVmin[2];
148 double fVmax[2];
149 double NormVariable( double x, double xmin, double xmax ) const {
150 // normalise to output range: [-1, 1]
151 return 2*(x - xmin)/(xmax - xmin) - 1.0;
152 }
153
154 // type of input variable: 'F' or 'I'
155 char fType[2];
156
157 // initialize internal variables
158 void Initialize();
159 double GetMvaValue__( const std::vector<double>& inputValues ) const;
160
161 // private members (method specific)
162 double fFisher0;
163 std::vector<double> fFisherCoefficients;
164};
165
166inline void ReadFisher_fold2::Initialize()
167{
168 fFisher0 = 0.0198348381631;
169 fFisherCoefficients.push_back( 0.474701901633 );
170 fFisherCoefficients.push_back( 0.463442770417 );
171
172 // sanity check
173 if (fFisherCoefficients.size() != fNvars) {
174 std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
175 << fFisherCoefficients.size() << " != " << fNvars << std::endl;
176 fStatusIsClean = false;
177 }
178}
179
180inline double ReadFisher_fold2::GetMvaValue__( const std::vector<double>& inputValues ) const
181{
182 double retval = fFisher0;
183 for (size_t ivar = 0; ivar < fNvars; ivar++) {
184 retval += fFisherCoefficients[ivar]*inputValues[ivar];
185 }
186
187 return retval;
188}
189
190// Clean up
191inline void ReadFisher_fold2::Clear()
192{
193 // clear coefficients
194 fFisherCoefficients.clear();
195}
196 inline double ReadFisher_fold2::GetMvaValue( const std::vector<double>& inputValues ) const
197 {
198 // classifier response value
199 double retval = 0;
200
201 // classifier response, sanity check first
202 if (!IsStatusClean()) {
203 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
204 << " because status is dirty" << std::endl;
205 retval = 0;
206 }
207 else {
208 retval = GetMvaValue__( inputValues );
209 }
210
211 return retval;
212 }
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