Logo ROOT   6.16/01
Reference Guide
TMVAClassification_RuleFit.class.C
Go to the documentation of this file.
1// Class: ReadRuleFit
2// Automatically generated by MethodBase::MakeClass
3//
4
5/* configuration options =====================================================
6
7#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-
8
9Method : RuleFit::RuleFit
10TMVA Release : 4.2.1 [262657]
11ROOT Release : 6.16/01 [397313]
12Creator : sftnight
13Date : Sun Dec 19 22:13:40 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]
25GDTau: "-1.000000e+00" [Gradient-directed (GD) path: default fit cut-off]
26GDTauPrec: "1.000000e-02" [GD path: precision of tau]
27GDStep: "1.000000e-02" [GD path: step size]
28GDNSteps: "10000" [GD path: number of steps]
29GDErrScale: "1.020000e+00" [Stop scan when error > scale*errmin]
30fEventsMin: "1.000000e-02" [Minimum fraction of events in a splittable node]
31fEventsMax: "5.000000e-01" [Maximum fraction of events in a splittable node]
32nTrees: "20" [Number of trees in forest.]
33RuleMinDist: "1.000000e-03" [Minimum distance between rules]
34MinImp: "1.000000e-03" [Minimum rule importance accepted]
35Model: "modrulelinear" [Model to be used]
36RuleFitModule: "rftmva" [Which RuleFit module to use]
37# Default:
38VerbosityLevel: "Default" [Verbosity level]
39VarTransform: "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)"]
40CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
41IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
42LinQuantile: "2.500000e-02" [Quantile of linear terms (removes outliers)]
43GDPathEveFrac: "5.000000e-01" [Fraction of events used for the path search]
44GDValidEveFrac: "5.000000e-01" [Fraction of events used for the validation]
45ForestType: "adaboost" [Method to use for forest generation (AdaBoost or RandomForest)]
46RFWorkDir: "./rulefit" [Friedman's RuleFit module (RFF): working dir]
47RFNrules: "2000" [RFF: Mximum number of rules]
48RFNendnodes: "4" [RFF: Average number of end nodes]
49##
50
51
52#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-
53
54NVar 4
55var1+var2 myvar1 myvar1 myvar1 'F' [-9.33803939819,7.69307804108]
56var1-var2 myvar2 myvar2 Expression 2 'F' [-3.25508260727,4.02912044525]
57var3 var3 var3 Variable 3 units 'F' [-5.2777428627,4.64297914505]
58var4 var4 var4 Variable 4 units 'F' [-5.6007027626,4.67435789108]
59NSpec 2
60var1*2 spec1 spec1 Spectator 1 units 'F' [-9.91655540466,8.7030172348]
61var1*3 spec2 spec2 Spectator 2 units 'F' [-14.874833107,13.0545253754]
62
63
64============================================================================ */
65
66#include <array>
67#include <vector>
68#include <cmath>
69#include <string>
70#include <iostream>
71
72#ifndef IClassifierReader__def
73#define IClassifierReader__def
74
75class IClassifierReader {
76
77 public:
78
79 // constructor
80 IClassifierReader() : fStatusIsClean( true ) {}
81 virtual ~IClassifierReader() {}
82
83 // return classifier response
84 virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;
85
86 // returns classifier status
87 bool IsStatusClean() const { return fStatusIsClean; }
88
89 protected:
90
91 bool fStatusIsClean;
92};
93
94#endif
95
96class ReadRuleFit : public IClassifierReader {
97
98 public:
99
100 // constructor
101 ReadRuleFit( std::vector<std::string>& theInputVars )
102 : IClassifierReader(),
103 fClassName( "ReadRuleFit" ),
104 fNvars( 4 )
105 {
106 // the training input variables
107 const char* inputVars[] = { "var1+var2", "var1-var2", "var3", "var4" };
108
109 // sanity checks
110 if (theInputVars.size() <= 0) {
111 std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl;
112 fStatusIsClean = false;
113 }
114
115 if (theInputVars.size() != fNvars) {
116 std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: "
117 << theInputVars.size() << " != " << fNvars << std::endl;
118 fStatusIsClean = false;
119 }
120
121 // validate input variables
122 for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
123 if (theInputVars[ivar] != inputVars[ivar]) {
124 std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl
125 << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl;
126 fStatusIsClean = false;
127 }
128 }
129
130 // initialize min and max vectors (for normalisation)
131 fVmin[0] = 0;
132 fVmax[0] = 0;
133 fVmin[1] = 0;
134 fVmax[1] = 0;
135 fVmin[2] = 0;
136 fVmax[2] = 0;
137 fVmin[3] = 0;
138 fVmax[3] = 0;
139
140 // initialize input variable types
141 fType[0] = 'F';
142 fType[1] = 'F';
143 fType[2] = 'F';
144 fType[3] = 'F';
145
146 // initialize constants
147 Initialize();
148
149 }
150
151 // destructor
152 virtual ~ReadRuleFit() {
153 Clear(); // method-specific
154 }
155
156 // the classifier response
157 // "inputValues" is a vector of input values in the same order as the
158 // variables given to the constructor
159 double GetMvaValue( const std::vector<double>& inputValues ) const override;
160
161 private:
162
163 // method-specific destructor
164 void Clear();
165
166 // common member variables
167 const char* fClassName;
168
169 const size_t fNvars;
170 size_t GetNvar() const { return fNvars; }
171 char GetType( int ivar ) const { return fType[ivar]; }
172
173 // normalisation of input variables
174 double fVmin[4];
175 double fVmax[4];
176 double NormVariable( double x, double xmin, double xmax ) const {
177 // normalise to output range: [-1, 1]
178 return 2*(x - xmin)/(xmax - xmin) - 1.0;
179 }
180
181 // type of input variable: 'F' or 'I'
182 char fType[4];
183
184 // initialize internal variables
185 void Initialize();
186 double GetMvaValue__( const std::vector<double>& inputValues ) const;
187
188 // private members (method specific)
189 // not implemented for class: "ReadRuleFit"
190};
192void ReadRuleFit::Clear(){}
193double ReadRuleFit::GetMvaValue__( const std::vector<double>& inputValues ) const {
194 double rval=9.468034304;
195 //
196 // here follows all rules ordered in importance (most important first)
197 // at the end of each line, the relative importance of the rule is given
198 //
199 if ((-0.70781672<inputValues[3])) rval+=-2.091079549; // importance = 0.429
200 if ((inputValues[2]<-0.08117419481)) rval+=-1.576325233; // importance = 0.368
201 if ((-0.08117419481<inputValues[2])) rval+=-1.442072296; // importance = 0.336
202 if ((-0.8769411445<inputValues[2])&&(0.2707604766<inputValues[3])) rval+=-1.260829168; // importance = 0.293
203 if ((inputValues[0]<2.827044487)&&(-1.668748856<inputValues[2])) rval+=-1.795034421; // importance = 0.271
204 if ((inputValues[0]<1.45515871)&&(inputValues[3]<0.2707604766)) rval+=-1.024584403; // importance = 0.239
205 if ((inputValues[3]<-0.70781672)) rval+=-0.9273179807; // importance = 0.190
206 if ((inputValues[2]<0.2560286522)&&(inputValues[3]<-0.70781672)) rval+=-0.9273179807; // importance = 0.190
207 if ((inputValues[0]<-2.849994659)) rval+=-1.532530451; // importance = 0.169
208 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)) rval+=-1.091577898; // importance = 0.161
209 if ((inputValues[1]<-0.4801481068)) rval+=-0.7241598431; // importance = 0.156
210 if ((-0.8270149231<inputValues[1])) rval+=-0.8220294808; // importance = 0.156
211 if ((-1.288185716<inputValues[0])&&(-0.8270149231<inputValues[1])) rval+=0.6224654513; // importance = 0.143
212 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)&&(inputValues[3]<1.365207195)) rval+=-0.7262142926; // importance = 0.142
213 if ((-1.227983475<inputValues[0])) rval+=-0.6233421574; // importance = 0.126
214 if ((inputValues[0]<2.827044487)&&(inputValues[2]<-1.668748856)&&(inputValues[3]<1.055167794)) rval+=-0.9595582911; // importance = 0.115
215 if ((inputValues[0]<2.827044487)&&(inputValues[2]<-1.668748856)) rval+=-0.9595582911; // importance = 0.115
216 if ((-0.4801481068<inputValues[1])&&(inputValues[2]<1.026640177)&&(inputValues[3]<0.1015381813)) rval+=-0.4813952666; // importance = 0.106
217 if ((-0.4832004011<inputValues[0])&&(-1.173881769<inputValues[1])&&(inputValues[1]<0.333245039)&&(inputValues[3]<0.3934768736)) rval+=0.6412101521; // importance = 0.082
218 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)&&(-0.8270149231<inputValues[1])&&(0.639572084<inputValues[2])&&(1.365207195<inputValues[3])) rval+=-0.5241224191; // importance = 0.065
219 if ((-1.173881769<inputValues[1])&&(inputValues[3]<0.7600490451)) rval+=-0.2753584246; // importance = 0.063
220 if ((0.1851498783<inputValues[0])&&(inputValues[1]<0.560452342)) rval+=-0.287826213; // importance = 0.062
221 if ((inputValues[0]<0.402831614)&&(-0.8270149231<inputValues[1])) rval+=0.2529612326; // importance = 0.059
222 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)&&(-0.8270149231<inputValues[1])&&(1.365207195<inputValues[3])) rval+=-0.4020894256; // importance = 0.054
223 if ((-0.4832004011<inputValues[0])&&(-1.173881769<inputValues[1])&&(0.3934768736<inputValues[3])) rval+=-0.1649581607; // importance = 0.037
224 if ((-0.4832004011<inputValues[0])&&(-1.173881769<inputValues[1])&&(inputValues[3]<0.3934768736)) rval+=-0.2097252133; // importance = 0.036
225 if ((inputValues[0]<0.39402771)&&(inputValues[1]<-0.07898536325)) rval+=-0.1711831296; // importance = 0.036
226 if ((-0.4832004011<inputValues[0])&&(inputValues[0]<1.440462112)&&(-1.173881769<inputValues[1])&&(inputValues[3]<0.3934768736)) rval+=-0.2097252133; // importance = 0.035
227 if ((inputValues[1]<-0.4801481068)&&(0.7600490451<inputValues[3])) rval+=0.2628324415; // importance = 0.035
228 if ((inputValues[1]<0.4341939986)&&(inputValues[3]<0.2707604766)) rval+=-0.1536235098; // importance = 0.034
229 if ((1.255346656<inputValues[1])&&(inputValues[1]<1.667604685)) rval+=0.2576251168; // importance = 0.031
230 if ((inputValues[2]<-0.08117419481)&&(-1.143110514<inputValues[3])) rval+=0.1298085529; // importance = 0.028
231 if ((inputValues[0]<-0.4832004011)&&(-1.173881769<inputValues[1])&&(inputValues[3]<-0.5545815229)) rval+=0.1237706907; // importance = 0.025
232 if ((-0.04954601452<inputValues[0])&&(inputValues[0]<0.4785142541)&&(0.6734923124<inputValues[3])) rval+=0.2769769595; // importance = 0.020
233 if ((-1.173881769<inputValues[1])&&(-1.03785038<inputValues[2])&&(0.7600490451<inputValues[3])) rval+=-0.09475895678; // importance = 0.020
234 if ((-1.173881769<inputValues[1])&&(0.7600490451<inputValues[3])) rval+=-0.09475895678; // importance = 0.020
235 if ((inputValues[0]<-0.4832004011)&&(-1.173881769<inputValues[1])&&(inputValues[1]<0.009230102412)&&(-0.5545815229<inputValues[3])) rval+=0.1850187744; // importance = 0.019
236 if ((inputValues[0]<-0.4832004011)&&(-1.173881769<inputValues[1])&&(-0.5545815229<inputValues[3])) rval+=-0.1192046981; // importance = 0.018
237 if ((inputValues[0]<-0.04954601452)&&(inputValues[1]<-0.4050141275)&&(-1.073310018<inputValues[3])) rval+=0.1165014314; // importance = 0.017
238 if ((1.255346656<inputValues[1])&&(inputValues[1]<1.667604685)&&(inputValues[2]<-0.00680893939)) rval+=0.184618271; // importance = 0.017
239 if ((inputValues[0]<1.878756404)&&(1.255346656<inputValues[1])&&(inputValues[1]<1.667604685)&&(inputValues[2]<-0.00680893939)) rval+=0.184618271; // importance = 0.016
240 if ((-0.04954601452<inputValues[0])&&(0.6734923124<inputValues[3])) rval+=-0.05217549148; // importance = 0.011
241 if ((0.01624130271<inputValues[1])&&(inputValues[1]<1.667604685)&&(-0.00680893939<inputValues[2])) rval+=-0.05902541412; // importance = 0.011
242 if ((0.6471375823<inputValues[0])&&(inputValues[0]<1.878756404)&&(1.255346656<inputValues[1])&&(inputValues[1]<1.667604685)&&(inputValues[2]<-0.00680893939)) rval+=-0.3327916655; // importance = 0.010
243 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)&&(-0.8270149231<inputValues[1])&&(inputValues[2]<0.639572084)&&(1.365207195<inputValues[3])) rval+=0.1220329935; // importance = 0.007
244 if ((1.20957303<inputValues[0])&&(inputValues[1]<0.4341939986)&&(inputValues[3]<0.2707604766)) rval+=-0.1511810893; // importance = 0.005
245 if ((-1.173881769<inputValues[1])&&(-1.03785038<inputValues[2])&&(inputValues[2]<-0.1674731225)&&(0.7600490451<inputValues[3])) rval+=-0.08947314749; // importance = 0.004
246 if ((-0.08117419481<inputValues[2])&&(inputValues[2]<1.270822406)) rval+=-0.01472221915; // importance = 0.003
247 if ((-1.61920917<inputValues[0])&&(inputValues[0]<2.827044487)&&(inputValues[1]<0.2844472229)&&(inputValues[2]<-1.668748856)&&(0.05907710269<inputValues[3])) rval+=-0.1511810893; // importance = 0.003
248 if ((inputValues[0]<2.827044487)&&(inputValues[1]<0.2844472229)&&(inputValues[2]<-1.668748856)&&(0.05907710269<inputValues[3])) rval+=-0.1511810893; // importance = 0.003
249 if ((-0.7362146974<inputValues[0])&&(inputValues[0]<2.827044487)&&(inputValues[2]<-1.668748856)&&(0.05907710269<inputValues[3])) rval+=-0.1511810893; // importance = 0.003
250 if ((-2.849994659<inputValues[0])&&(inputValues[0]<2.677224874)&&(inputValues[1]<-0.8270149231)&&(1.365207195<inputValues[3])) rval+=0.03672581977; // importance = 0.002
251 //
252 // here follows all linear terms
253 // at the end of each line, the relative importance of the term is given
254 //
255 rval+=-0.6337562808*std::min( double(3.274564505), std::max( double(inputValues[0]), double(-3.351432562))); // importance = 0.472
256 rval+=-0.4487935322*std::min( double(2.157360792), std::max( double(inputValues[1]), double(-2.052939415))); // importance = 0.209
257 rval+=-0.2809793072*std::min( double(1.966724753), std::max( double(inputValues[2]), double(-2.075380087))); // importance = 0.129
258 rval+=1.84962748*std::min( double(2.508529902), std::max( double(inputValues[3]), double(-2.35084939))); // importance = 1.000
259 return rval;
260}
261 inline double ReadRuleFit::GetMvaValue( const std::vector<double>& inputValues ) const
262 {
263 // classifier response value
264 double retval = 0;
265
266 // classifier response, sanity check first
267 if (!IsStatusClean()) {
268 std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response"
269 << " because status is dirty" << std::endl;
270 retval = 0;
271 }
272 else {
273 retval = GetMvaValue__( inputValues );
274 }
275
276 return retval;
277 }
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