Logo ROOT   6.14/05
Reference Guide
TMVACrossValidation_Fisher_fold1.class.C
Go to the documentation of this file.
1 // Class: ReadFisher_fold1
2 // Automatically generated by MethodBase::MakeClass
3 //
4 
5 /* configuration options =====================================================
6 
7 #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8 
9 Method : Fisher::Fisher_fold1
10 TMVA Release : 4.2.1 [262657]
11 ROOT Release : 6.14/05 [396805]
12 Creator : sftnight
13 Date : Fri Nov 2 10:41:50 2018
14 Host : Linux ec-ubuntu-14-04-x86-64-2 3.13.0-157-generic #207-Ubuntu SMP Mon Aug 20 16:44:59 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Dir : /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/documentation/doxygen
16 Training events: 999
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 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)"]
25 H: "False" [Print method-specific help message]
26 Method: "Fisher" [Discrimination method]
27 # Default:
28 VerbosityLevel: "Default" [Verbosity level]
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 2
37 x x x x 'F' [-4.10750675201,4.09692668915]
38 y y y y 'F' [-4.85200452805,4.07606744766]
39 NSpec 1
40 eventID 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 
54 class 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 
75 class ReadFisher_fold1 : public IClassifierReader {
76 
77  public:
78 
79  // constructor
80  ReadFisher_fold1( std::vector<std::string>& theInputVars )
81  : IClassifierReader(),
82  fClassName( "ReadFisher_fold1" ),
83  fNvars( 2 ),
84  fIsNormalised( false )
85  {
86  // the training input variables
87  const char* inputVars[] = { "x", "y" };
88 
89  // sanity checks
90  if (theInputVars.size() <= 0) {
91  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
92  fStatusIsClean = false;
93  }
94 
95  if (theInputVars.size() != fNvars) {
96  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
97  << theInputVars.size() << " != " << fNvars << std::endl;
98  fStatusIsClean = false;
99  }
100 
101  // validate input variables
102  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
103  if (theInputVars[ivar] != inputVars[ivar]) {
104  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
105  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
106  fStatusIsClean = false;
107  }
108  }
109 
110  // initialize min and max vectors (for normalisation)
111  fVmin[0] = 0;
112  fVmax[0] = 0;
113  fVmin[1] = 0;
114  fVmax[1] = 0;
115 
116  // initialize input variable types
117  fType[0] = 'F';
118  fType[1] = 'F';
119 
120  // initialize constants
121  Initialize();
122 
123  }
124 
125  // destructor
126  virtual ~ReadFisher_fold1() {
127  Clear(); // method-specific
128  }
129 
130  // the classifier response
131  // "inputValues" is a vector of input values in the same order as the
132  // variables given to the constructor
133  double GetMvaValue( const std::vector<double>& inputValues ) const override;
134 
135  private:
136 
137  // method-specific destructor
138  void Clear();
139 
140  // common member variables
141  const char* fClassName;
142 
143  const size_t fNvars;
144  size_t GetNvar() const { return fNvars; }
145  char GetType( int ivar ) const { return fType[ivar]; }
146 
147  // normalisation of input variables
148  const bool fIsNormalised;
149  bool IsNormalised() const { return fIsNormalised; }
150  double fVmin[2];
151  double fVmax[2];
152  double NormVariable( double x, double xmin, double xmax ) const {
153  // normalise to output range: [-1, 1]
154  return 2*(x - xmin)/(xmax - xmin) - 1.0;
155  }
156 
157  // type of input variable: 'F' or 'I'
158  char fType[2];
159 
160  // initialize internal variables
161  void Initialize();
162  double GetMvaValue__( const std::vector<double>& inputValues ) const;
163 
164  // private members (method specific)
165  double fFisher0;
166  std::vector<double> fFisherCoefficients;
167 };
168 
169 inline void ReadFisher_fold1::Initialize()
170 {
171  fFisher0 = 0.00631248659825;
172  fFisherCoefficients.push_back( 0.505446705342 );
173  fFisherCoefficients.push_back( 0.430405371143 );
174 
175  // sanity check
176  if (fFisherCoefficients.size() != fNvars) {
177  std::cout << "Problem in class \"" << fClassName << "\"::Initialize: mismatch in number of input values"
178  << fFisherCoefficients.size() << " != " << fNvars << std::endl;
179  fStatusIsClean = false;
180  }
181 }
182 
183 inline double ReadFisher_fold1::GetMvaValue__( const std::vector<double>& inputValues ) const
184 {
185  double retval = fFisher0;
186  for (size_t ivar = 0; ivar < fNvars; ivar++) {
187  retval += fFisherCoefficients[ivar]*inputValues[ivar];
188  }
189 
190  return retval;
191 }
192 
193 // Clean up
194 inline void ReadFisher_fold1::Clear()
195 {
196  // clear coefficients
197  fFisherCoefficients.clear();
198 }
199  inline double ReadFisher_fold1::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  if (IsNormalised()) {
212  // normalise variables
213  std::vector<double> iV;
214  iV.reserve(inputValues.size());
215  int ivar = 0;
216  for (std::vector<double>::const_iterator varIt = inputValues.begin();
217  varIt != inputValues.end(); varIt++, ivar++) {
218  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
219  }
220  retval = GetMvaValue__( iV );
221  }
222  else {
223  retval = GetMvaValue__( inputValues );
224  }
225  }
226 
227  return retval;
228  }
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