Logo ROOT   6.16/01
Reference Guide
TMVAClassification_FDA_GA.class.C
Go to the documentation of this file.
1// Class: ReadFDA_GA
2// Automatically generated by MethodBase::MakeClass
3//
4
5/* configuration options =====================================================
6
7#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8
9Method : FDA::FDA_GA
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:13:32 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: 2000
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: "True" [Print method-specific help message]
25Formula: "(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3" [The discrimination formula]
26ParRanges: "(-1,1);(-10,10);(-10,10);(-10,10);(-10,10)" [Parameter ranges]
27FitMethod: "GA" [Optimisation Method]
28# Default:
29VerbosityLevel: "Default" [Verbosity level]
30VarTransform: "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)"]
31CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
32IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
33Converger: "None" [FitMethod uses Converger to improve result]
34##
35
36
37#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
38
39NVar 4
40var1+var2 myvar1 myvar1 myvar1 'F' [-9.33803939819,7.69307804108]
41var1-var2 myvar2 myvar2 Expression 2 'F' [-3.25508260727,4.02912044525]
42var3 var3 var3 Variable 3 units 'F' [-5.2777428627,4.64297914505]
43var4 var4 var4 Variable 4 units 'F' [-5.6007027626,4.67435789108]
44NSpec 2
45var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.7030172348]
46var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0545253754]
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 ReadFDA_GA : public IClassifierReader {
82
83 public:
84
85 // constructor
86 ReadFDA_GA( std::vector<std::string>& theInputVars )
87 : IClassifierReader(),
88 fClassName( "ReadFDA_GA" ),
89 fNvars( 4 )
90 {
91 // the training input variables
92 const char* inputVars[] = { "var1+var2", "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 ~ReadFDA_GA() {
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 fParameter[5];
175};
176
177inline void ReadFDA_GA::Initialize()
178{
179 fParameter[0] = 0.516172096466999;
180 fParameter[1] = -0.223975889384747;
181 fParameter[2] = 0;
182 fParameter[3] = -0.0484458589926362;
183 fParameter[4] = 0.519118621014059;
184}
185
186inline double ReadFDA_GA::GetMvaValue__( const std::vector<double>& inputValues ) const
187{
188 // interpret the formula
189 double retval = fParameter[0]+fParameter[1]*inputValues[0]+fParameter[2]*inputValues[1]+fParameter[3]*inputValues[2]+fParameter[4]*inputValues[3];
190
191 return retval;
192}
193
194// Clean up
195inline void ReadFDA_GA::Clear()
196{
197 // nothing to clear
198}
199 inline double ReadFDA_GA::GetMvaValue( const std::vector<double>& inputValues ) const
200 {
201 // classifier response value
202 double retval = 0;
203
204 // classifier response, sanity check first
205 if (!IsStatusClean()) {
206 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
207 << " because status is dirty" << std::endl;
208 retval = 0;
209 }
210 else {
211 retval = GetMvaValue__( inputValues );
212 }
213
214 return retval;
215 }
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