79#ifndef IClassifierReader__def
80#define IClassifierReader__def
82class IClassifierReader {
87 IClassifierReader() : fStatusIsClean(
true ) {}
88 virtual ~IClassifierReader() {}
91 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
94 bool IsStatusClean()
const {
return fStatusIsClean; }
103class ReadMLPBNN :
public IClassifierReader {
108 ReadMLPBNN( std::vector<std::string>& theInputVars )
109 : IClassifierReader(),
110 fClassName(
"ReadMLPBNN" ),
114 const char* inputVars[] = {
"var1+var2",
"var1-var2",
"var3",
"var4" };
117 if (theInputVars.size() <= 0) {
118 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
119 fStatusIsClean =
false;
122 if (theInputVars.size() != fNvars) {
123 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in number of input values: "
124 << theInputVars.size() <<
" != " << fNvars << std::endl;
125 fStatusIsClean =
false;
129 for (
size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
130 if (theInputVars[ivar] != inputVars[ivar]) {
131 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in input variable names" << std::endl
132 <<
" for variable [" << ivar <<
"]: " << theInputVars[ivar].c_str() <<
" != " << inputVars[ivar] << std::endl;
133 fStatusIsClean =
false;
145 fVmax[3] = 0.99999988079071;
161 virtual ~ReadMLPBNN() {
168 double GetMvaValue(
const std::vector<double>& inputValues )
const override;
178 double fScal_1[3][4];
179 void InitTransform_1();
180 void Transform_1( std::vector<double> & iv,
int sigOrBgd )
const;
181 void InitTransform();
182 void Transform( std::vector<double> & iv,
int sigOrBgd )
const;
185 const char* fClassName;
188 size_t GetNvar()
const {
return fNvars; }
194 double NormVariable(
double x,
double xmin,
double xmax )
const {
204 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
208 double ActivationFnc(
double x)
const;
209 double OutputActivationFnc(
double x)
const;
211 double fWeightMatrix0to1[10][5];
212 double fWeightMatrix1to2[1][10];
220 fWeightMatrix0to1[0][0] = 0.499339155868432;
221 fWeightMatrix0to1[1][0] = 1.97323370224732;
222 fWeightMatrix0to1[2][0] = 0.835850497820873;
223 fWeightMatrix0to1[3][0] = 0.370715139038071;
224 fWeightMatrix0to1[4][0] = -3.3244780544242;
225 fWeightMatrix0to1[5][0] = -1.00515616054487;
226 fWeightMatrix0to1[6][0] = -0.903517469691334;
227 fWeightMatrix0to1[7][0] = 1.68095300796643;
228 fWeightMatrix0to1[8][0] = -1.8086188219696;
229 fWeightMatrix0to1[0][1] = -0.469787533689036;
230 fWeightMatrix0to1[1][1] = -1.47308437821555;
231 fWeightMatrix0to1[2][1] = -0.548985376762871;
232 fWeightMatrix0to1[3][1] = -1.08352747767343;
233 fWeightMatrix0to1[4][1] = -0.706728846639731;
234 fWeightMatrix0to1[5][1] = -0.973391622880094;
235 fWeightMatrix0to1[6][1] = 0.659572707267351;
236 fWeightMatrix0to1[7][1] = -0.31695950236766;
237 fWeightMatrix0to1[8][1] = 2.4093761098387;
238 fWeightMatrix0to1[0][2] = 0.355913509480398;
239 fWeightMatrix0to1[1][2] = 1.40361366583309;
240 fWeightMatrix0to1[2][2] = -0.210743959789661;
241 fWeightMatrix0to1[3][2] = -0.978127205874705;
242 fWeightMatrix0to1[4][2] = -1.01949963347685;
243 fWeightMatrix0to1[5][2] = 0.897826904860834;
244 fWeightMatrix0to1[6][2] = -1.25600410498056;
245 fWeightMatrix0to1[7][2] = -0.743241454883446;
246 fWeightMatrix0to1[8][2] = 1.48931411037645;
247 fWeightMatrix0to1[0][3] = -2.17450079985913;
248 fWeightMatrix0to1[1][3] = -1.60207885420351;
249 fWeightMatrix0to1[2][3] = 0.552988361084977;
250 fWeightMatrix0to1[3][3] = 2.28075263985257;
251 fWeightMatrix0to1[4][3] = 4.00452196921293;
252 fWeightMatrix0to1[5][3] = 1.33661120213445;
253 fWeightMatrix0to1[6][3] = 0.0806551453627355;
254 fWeightMatrix0to1[7][3] = -0.523552944740624;
255 fWeightMatrix0to1[8][3] = 0.925130649598083;
256 fWeightMatrix0to1[0][4] = -0.565154618007088;
257 fWeightMatrix0to1[1][4] = 2.36601716651037;
258 fWeightMatrix0to1[2][4] = -1.05353132940242;
259 fWeightMatrix0to1[3][4] = -0.163502849122647;
260 fWeightMatrix0to1[4][4] = -0.194079160790969;
261 fWeightMatrix0to1[5][4] = 0.98449705780042;
262 fWeightMatrix0to1[6][4] = 1.9250180795564;
263 fWeightMatrix0to1[7][4] = 1.61703868436564;
264 fWeightMatrix0to1[8][4] = -0.686657299656178;
266 fWeightMatrix1to2[0][0] = -2.23742003371891;
267 fWeightMatrix1to2[0][1] = 0.277464222426375;
268 fWeightMatrix1to2[0][2] = -0.203363715034144;
269 fWeightMatrix1to2[0][3] = 1.57205142891781;
270 fWeightMatrix1to2[0][4] = 5.94689352294752;
271 fWeightMatrix1to2[0][5] = 1.15566920637399;
272 fWeightMatrix1to2[0][6] = 1.26453893993009;
273 fWeightMatrix1to2[0][7] = -1.34996651290595;
274 fWeightMatrix1to2[0][8] = 1.53068569815131;
275 fWeightMatrix1to2[0][9] = -1.7128873155142;
278inline double ReadMLPBNN::GetMvaValue__(
const std::vector<double>& inputValues )
const
280 if (inputValues.size() != (
unsigned int)4) {
281 std::cout <<
"Input vector needs to be of size " << 4 << std::endl;
285 std::array<double, 10> fWeights1 {{}};
286 std::array<double, 1> fWeights2 {{}};
287 fWeights1.back() = 1.;
290 for (
int o=0; o<9; o++) {
291 std::array<double, 5> buffer;
292 for (
int i = 0; i<5 - 1; i++) {
293 buffer[i] = fWeightMatrix0to1[o][i] * inputValues[i];
295 buffer.back() = fWeightMatrix0to1[o][4];
for (
int i=0; i<5; i++) {
296 fWeights1[o] += buffer[i];
299 for (
int o=0; o<9; o++) {
300 fWeights1[o] = ActivationFnc(fWeights1[o]);
303 for (
int o=0; o<1; o++) {
304 std::array<double, 10> buffer;
305 for (
int i=0; i<10; i++) {
306 buffer[i] = fWeightMatrix1to2[o][i] * fWeights1[i];
308 for (
int i=0; i<10; i++) {
309 fWeights2[o] += buffer[i];
312 for (
int o=0; o<1; o++) {
313 fWeights2[o] = OutputActivationFnc(fWeights2[o]);
319double ReadMLPBNN::ActivationFnc(
double x)
const {
323double ReadMLPBNN::OutputActivationFnc(
double x)
const {
325 return 1.0/(1.0+
exp(-
x));
329inline void ReadMLPBNN::Clear()
332 inline double ReadMLPBNN::GetMvaValue(
const std::vector<double>& inputValues )
const
338 if (!IsStatusClean()) {
339 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response"
340 <<
" because status is dirty" << std::endl;
344 std::vector<double> iV(inputValues);
346 retval = GetMvaValue__( iV );
353inline void ReadMLPBNN::InitTransform_1()
358 fMin_1[0][0] = -4.33593845367;
359 fMax_1[0][0] = 6.3994679451;
360 fScal_1[0][0] = 2.0/(fMax_1[0][0]-fMin_1[0][0]);
361 fOff_1[0][0] = fMin_1[0][0]*fScal_1[0][0]+1.;
362 fMin_1[1][0] = -9.33803939819;
363 fMax_1[1][0] = 7.69307804108;
364 fScal_1[1][0] = 2.0/(fMax_1[1][0]-fMin_1[1][0]);
365 fOff_1[1][0] = fMin_1[1][0]*fScal_1[1][0]+1.;
366 fMin_1[2][0] = -9.33803939819;
367 fMax_1[2][0] = 7.69307804108;
368 fScal_1[2][0] = 2.0/(fMax_1[2][0]-fMin_1[2][0]);
369 fOff_1[2][0] = fMin_1[2][0]*fScal_1[2][0]+1.;
370 fMin_1[0][1] = -3.20988440514;
371 fMax_1[0][1] = 4.02912044525;
372 fScal_1[0][1] = 2.0/(fMax_1[0][1]-fMin_1[0][1]);
373 fOff_1[0][1] = fMin_1[0][1]*fScal_1[0][1]+1.;
374 fMin_1[1][1] = -3.25508260727;
375 fMax_1[1][1] = 3.36500358582;
376 fScal_1[1][1] = 2.0/(fMax_1[1][1]-fMin_1[1][1]);
377 fOff_1[1][1] = fMin_1[1][1]*fScal_1[1][1]+1.;
378 fMin_1[2][1] = -3.25508260727;
379 fMax_1[2][1] = 4.02912044525;
380 fScal_1[2][1] = 2.0/(fMax_1[2][1]-fMin_1[2][1]);
381 fOff_1[2][1] = fMin_1[2][1]*fScal_1[2][1]+1.;
382 fMin_1[0][2] = -2.60635733604;
383 fMax_1[0][2] = 3.86989831924;
384 fScal_1[0][2] = 2.0/(fMax_1[0][2]-fMin_1[0][2]);
385 fOff_1[0][2] = fMin_1[0][2]*fScal_1[0][2]+1.;
386 fMin_1[1][2] = -5.2777428627;
387 fMax_1[1][2] = 4.64297914505;
388 fScal_1[1][2] = 2.0/(fMax_1[1][2]-fMin_1[1][2]);
389 fOff_1[1][2] = fMin_1[1][2]*fScal_1[1][2]+1.;
390 fMin_1[2][2] = -5.2777428627;
391 fMax_1[2][2] = 4.64297914505;
392 fScal_1[2][2] = 2.0/(fMax_1[2][2]-fMin_1[2][2]);
393 fOff_1[2][2] = fMin_1[2][2]*fScal_1[2][2]+1.;
394 fMin_1[0][3] = -2.1695792675;
395 fMax_1[0][3] = 4.5351858139;
396 fScal_1[0][3] = 2.0/(fMax_1[0][3]-fMin_1[0][3]);
397 fOff_1[0][3] = fMin_1[0][3]*fScal_1[0][3]+1.;
398 fMin_1[1][3] = -5.6007027626;
399 fMax_1[1][3] = 4.67435789108;
400 fScal_1[1][3] = 2.0/(fMax_1[1][3]-fMin_1[1][3]);
401 fOff_1[1][3] = fMin_1[1][3]*fScal_1[1][3]+1.;
402 fMin_1[2][3] = -5.6007027626;
403 fMax_1[2][3] = 4.67435789108;
404 fScal_1[2][3] = 2.0/(fMax_1[2][3]-fMin_1[2][3]);
405 fOff_1[2][3] = fMin_1[2][3]*fScal_1[2][3]+1.;
409inline void ReadMLPBNN::Transform_1( std::vector<double>& iv,
int cls)
const
412 if (cls < 0 || cls > 2) {
421 static std::vector<int> indicesGet;
422 static std::vector<int> indicesPut;
424 if ( indicesGet.empty() ) {
425 indicesGet.reserve(fNvars);
426 indicesGet.push_back( 0);
427 indicesGet.push_back( 1);
428 indicesGet.push_back( 2);
429 indicesGet.push_back( 3);
431 if ( indicesPut.empty() ) {
432 indicesPut.reserve(fNvars);
433 indicesPut.push_back( 0);
434 indicesPut.push_back( 1);
435 indicesPut.push_back( 2);
436 indicesPut.push_back( 3);
439 static std::vector<double> dv;
441 for (
int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];
442 for (
int ivar=0;ivar<4;ivar++) {
443 double offset = fOff_1[cls][ivar];
444 double scale = fScal_1[cls][ivar];
445 iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;
450inline void ReadMLPBNN::InitTransform()
456inline void ReadMLPBNN::Transform( std::vector<double>& iv,
int sigOrBgd )
const
458 Transform_1( iv, sigOrBgd );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)