Logo ROOT   6.14/05
Reference Guide
TMVACrossValidation_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 
9 Method : CrossValidation::Fisher
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: 1998
17 Analysis type : [Classification]
18 
19 
20 #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-
21 
22 # Set by User:
23 EncapsulatedMethodName: "Fisher" []
24 EncapsulatedMethodTypeName: "Fisher" []
25 NumFolds: "2" [Number of folds to generate]
26 OutputEnsembling: "None" [Combines output from contained methods. If None, no combination is performed. (default None)]
27 SplitExpr: "" [The expression used to assign events to folds]
28 # Default:
29 V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
30 VerbosityLevel: "Default" [Verbosity level]
31 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)"]
32 H: "False" [Print method-specific help message]
33 CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
34 IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
35 ##
36 
37 
38 #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
39 
40 NVar 2
41 x x x x 'F' [-4.10750675201,4.09692668915]
42 y y y y 'F' [-4.85200452805,4.07606744766]
43 NSpec 1
44 eventID eventID eventID I 'F' [1,1000]
45 
46 
47 ============================================================================ */
48 
49 #include <array>
50 #include <vector>
51 #include <cmath>
52 #include <string>
53 #include <iostream>
54 
55 #ifndef IClassifierReader__def
56 #define IClassifierReader__def
57 
58 class IClassifierReader {
59 
60  public:
61 
62  // constructor
63  IClassifierReader() : fStatusIsClean( true ) {}
64  virtual ~IClassifierReader() {}
65 
66  // return classifier response
67  virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
68 
69  // returns classifier status
70  bool IsStatusClean() const { return fStatusIsClean; }
71 
72  protected:
73 
74  bool fStatusIsClean;
75 };
76 
77 #endif
78 
79 class ReadFisher : public IClassifierReader {
80 
81  public:
82 
83  // constructor
84  ReadFisher( std::vector<std::string>& theInputVars )
85  : IClassifierReader(),
86  fClassName( "ReadFisher" ),
87  fNvars( 2 ),
88  fIsNormalised( false )
89  {
90  // the training input variables
91  const char* inputVars[] = { "x", "y" };
92 
93  // sanity checks
94  if (theInputVars.size() <= 0) {
95  std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
96  fStatusIsClean = false;
97  }
98 
99  if (theInputVars.size() != fNvars) {
100  std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
101  << theInputVars.size() << " != " << fNvars << std::endl;
102  fStatusIsClean = false;
103  }
104 
105  // validate input variables
106  for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
107  if (theInputVars[ivar] != inputVars[ivar]) {
108  std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
109  << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
110  fStatusIsClean = false;
111  }
112  }
113 
114  // initialize min and max vectors (for normalisation)
115  fVmin[0] = 0;
116  fVmax[0] = 0;
117  fVmin[1] = 0;
118  fVmax[1] = 0;
119 
120  // initialize input variable types
121  fType[0] = 'F';
122  fType[1] = 'F';
123 
124  // initialize constants
125  Initialize();
126 
127  }
128 
129  // destructor
130  virtual ~ReadFisher() {
131  Clear(); // method-specific
132  }
133 
134  // the classifier response
135  // "inputValues" is a vector of input values in the same order as the
136  // variables given to the constructor
137  double GetMvaValue( const std::vector<double>& inputValues ) const override;
138 
139  private:
140 
141  // method-specific destructor
142  void Clear();
143 
144  // common member variables
145  const char* fClassName;
146 
147  const size_t fNvars;
148  size_t GetNvar() const { return fNvars; }
149  char GetType( int ivar ) const { return fType[ivar]; }
150 
151  // normalisation of input variables
152  const bool fIsNormalised;
153  bool IsNormalised() const { return fIsNormalised; }
154  double fVmin[2];
155  double fVmax[2];
156  double NormVariable( double x, double xmin, double xmax ) const {
157  // normalise to output range: [-1, 1]
158  return 2*(x - xmin)/(xmax - xmin) - 1.0;
159  }
160 
161  // type of input variable: 'F' or 'I'
162  char fType[2];
163 
164  // initialize internal variables
165  void Initialize();
166  double GetMvaValue__( const std::vector<double>& inputValues ) const;
167 
168  // private members (method specific)
169  inline double ReadFisher::GetMvaValue( const std::vector<double>& inputValues ) const
170  {
171  // classifier response value
172  double retval = 0;
173 
174  // classifier response, sanity check first
175  if (!IsStatusClean()) {
176  std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
177  << " because status is dirty" << std::endl;
178  retval = 0;
179  }
180  else {
181  if (IsNormalised()) {
182  // normalise variables
183  std::vector<double> iV;
184  iV.reserve(inputValues.size());
185  int ivar = 0;
186  for (std::vector<double>::const_iterator varIt = inputValues.begin();
187  varIt != inputValues.end(); varIt++, ivar++) {
188  iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
189  }
190  retval = GetMvaValue__( iV );
191  }
192  else {
193  retval = GetMvaValue__( inputValues );
194  }
195  }
196 
197  return retval;
198  }
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