Logo ROOT   6.08/07
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 
9 Method : FDA::FDA_GA
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.08/07 [395271]
12 Creator : sftnight
13 Date : Thu May 31 21:35:59 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-v608/rootspi/rdoc/src/v6-08-00-patches/documentation/doxygen
16 Training events: 2000
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: "True" [Print method-specific help message]
25 Formula: "(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3" [The discrimination formula]
26 ParRanges: "(-1,1);(-10,10);(-10,10);(-10,10);(-10,10)" [Parameter ranges]
27 FitMethod: "GA" [Optimisation Method]
28 # Default:
29 VerbosityLevel: "Default" [Verbosity level]
30 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)"]
31 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
32 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
33 Converger: "None" [FitMethod uses Converger to improve result]
34 ##
35 
36 
37 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
38 
39 NVar 4
40 var1+var2 myvar1 myvar1 myvar1 'F' [-8.14423561096,7.26972866058]
41 var1-var2 myvar2 myvar2 Expression 2 'F' [-3.96643972397,4.0258936882]
42 var3 var3 var3 Variable 3 units 'F' [-5.03730010986,4.27845287323]
43 var4 var4 var4 Variable 4 units 'F' [-5.95050764084,4.64035463333]
44 NSpec 2
45 var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.67800140381]
46 var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0170021057]
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 ReadFDA_GA : public IClassifierReader {
81 
82  public:
83 
84  // constructor
85  ReadFDA_GA( std::vector<std::string>& theInputVars )
86  : IClassifierReader(),
87  fClassName( "ReadFDA_GA" ),
88  fNvars( 4 ),
89  fIsNormalised( false )
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;
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 fParameter[5];
177 };
178 
179 inline void ReadFDA_GA::Initialize()
180 {
181  fParameter[0] = 0.388369514970016;
182  fParameter[1] = -0.325754963750384;
183  fParameter[2] = -0.0794257398582496;
184  fParameter[3] = -0.195619674556562;
185  fParameter[4] = 0.758560461256256;
186 }
187 
188 inline double ReadFDA_GA::GetMvaValue__( const std::vector<double>& inputValues ) const
189 {
190  // interpret the formula
191  double retval = fParameter[0]+fParameter[1]*inputValues[0]+fParameter[2]*inputValues[1]+fParameter[3]*inputValues[2]+fParameter[4]*inputValues[3];
192 
193  return retval;
194 }
195 
196 // Clean up
197 inline void ReadFDA_GA::Clear()
198 {
199  // nothing to clear
200 }
201  inline double ReadFDA_GA::GetMvaValue( const std::vector<double>& inputValues ) const
202  {
203  // classifier response value
204  double retval = 0;
205 
206  // classifier response, sanity check first
207  if (!IsStatusClean()) {
208  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
209  << " because status is dirty" << std::endl;
210  retval = 0;
211  }
212  else {
213  if (IsNormalised()) {
214  // normalise variables
215  std::vector<double> iV;
216  iV.reserve(inputValues.size());
217  int ivar = 0;
218  for (std::vector<double>::const_iterator varIt = inputValues.begin();
219  varIt != inputValues.end(); varIt++, ivar++) {
220  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
221  }
222  retval = GetMvaValue__( iV );
223  }
224  else {
225  retval = GetMvaValue__( inputValues );
226  }
227  }
228 
229  return retval;
230  }
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