Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
VariableNormalizeTransform.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Peter Speckmayer, Eckhard von Toerne
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : VariableNormalizeTransform *
8 * *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16 * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
17 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18 * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
19 * *
20 * Copyright (c) 2005-2011: *
21 * CERN, Switzerland *
22 * MPI-K Heidelberg, Germany *
23 * U. of Bonn, Germany *
24 * *
25 * Redistribution and use in source and binary forms, with or without *
26 * modification, are permitted according to the terms listed in LICENSE *
27 * (see tmva/doc/LICENSE) *
28 **********************************************************************************/
29
30/*! \class TMVA::VariableNormalizeTransform
31\ingroup TMVA
32Linear interpolation class
33*/
34
36
37#include "TMVA/DataSet.h"
38#include "TMVA/DataSetInfo.h"
39#include "TMVA/Event.h"
40#include "TMVA/MsgLogger.h"
41#include "TMVA/Tools.h"
42#include "TMVA/Types.h"
43#include "TMVA/VariableInfo.h"
44
45#include "TMatrixD.h"
46#include "TMatrixDBase.h"
47#include "TVectorF.h"
48
49#include <iostream>
50#include <iomanip>
51#include <cfloat>
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// constructor
56
58: VariableTransformBase( dsi, Types::kNormalized, "Norm" ),
59 fNoOffset(kFALSE)
60{
61 if (strcor=="Scale") {fNoOffset = kTRUE;
62 SetName("Scale");
63 }
64}
65
66////////////////////////////////////////////////////////////////////////////////
67
70
71////////////////////////////////////////////////////////////////////////////////
72/// initialization of the normalization transformation
73
75{
76 UInt_t inputSize = fGet.size();
77 Int_t numC = GetNClasses()+1;
78 if (GetNClasses() <= 1 ) numC = 1;
79
80 fMin.resize( numC );
81 fMax.resize( numC );
82 for (Int_t i=0; i<numC; i++) {
83 fMin.at(i).resize(inputSize);
84 fMax.at(i).resize(inputSize);
85 fMin.at(i).assign(inputSize, 0);
86 fMax.at(i).assign(inputSize, 0);
87 }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// prepare transformation
92
94{
95 if (!IsEnabled() || IsCreated()) return kTRUE;
96
97 Log() << kDEBUG << "\tPreparing the transformation." << Endl;
98
99 Initialize();
100
101 CalcNormalizationParams( events );
102
103 SetCreated( kTRUE );
104
105 return kTRUE;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// apply the normalization transformation
110
112{
113 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
114
115 // if cls (the class chosen by the user) not existing,
116 // assume that he wants to have the matrix for all classes together.
117 // if (cls < 0 || cls > GetNClasses()) {
118 // if (GetNClasses() > 1 ) cls = GetNClasses();
119 // else cls = (fMin.size()==1?0:2);
120 // }
121 // EVT this is a workaround to address the reader problem with transforma and EvaluateMVA(std::vector<float/double> ,...)
122 if (cls < 0 || cls >= (int) fMin.size()) cls = fMin.size()-1;
123 // EVT workaround end
124
125 FloatVector input; // will be filled with the selected variables, targets, (spectators)
126 FloatVector output; // will be filled with the selected variables, targets, (spectators)
127 std::vector<Char_t> mask; // entries with kTRUE must not be transformed
128 GetInput( ev, input, mask );
129
130 if (fTransformedEvent==0) fTransformedEvent = new Event();
131
132 Float_t min,max;
133 const FloatVector& minVector = fMin.at(cls);
134 const FloatVector& maxVector = fMax.at(cls);
135
136 UInt_t iidx = 0;
137 std::vector<Char_t>::iterator itMask = mask.begin();
138 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
139 if( (*itMask) ){
140 ++iidx;
141 ++itMask;
142 // don't put any value into output if the value is masked
143 continue;
144 }
145
146 Float_t val = (*itInp);
147
148 min = minVector.at(iidx);
149 max = maxVector.at(iidx);
150
152 if (!fNoOffset) {
153 Float_t offset = min;
154 Float_t scale = 1.0/(max-min);
155 valnorm = (val-offset)*scale * 2 - 1;
156 } else {
157 fabs(max)>fabs(min) ? valnorm=val/fabs(max) : valnorm=val/fabs(min);
158 }
159
160 output.push_back( valnorm );
161
162 ++iidx;
163 ++itMask;
164 }
165
166 SetOutput( fTransformedEvent, output, mask, ev );
167 return fTransformedEvent;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// apply the inverse transformation
172
174{
175 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
176
177 // if cls (the class chosen by the user) not existing,
178 // assume that user wants to have the transformation for all classes together.
179 if (cls < 0 || cls > GetNClasses()) {
180 if (GetNClasses() > 1 ) cls = GetNClasses();
181 else cls = 0;
182 }
183
184 FloatVector input; // will be filled with the selected variables, targets, (spectators)
185 FloatVector output; // will be filled with the output
186 std::vector<Char_t> mask;
187 GetInput( ev, input, mask, kTRUE );
188
189 if (fBackTransformedEvent==0) fBackTransformedEvent = new Event( *ev );
190
191 Float_t min,max;
192 const FloatVector& minVector = fMin.at(cls);
193 const FloatVector& maxVector = fMax.at(cls);
194
195 UInt_t iidx = 0;
196 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
197 Float_t val = (*itInp);
198
199 min = minVector.at(iidx);
200 max = maxVector.at(iidx);
201
203 if (!fNoOffset) {
204 Float_t offset = min;
205 Float_t scale = 1.0/(max-min);
206 valnorm = offset+((val+1)/(scale * 2));
207 } else {
208 fabs(max)>fabs(min) ? valnorm=val*fabs(max) : valnorm=val*fabs(min);
209 }
210
211 output.push_back( valnorm );
212
213 ++iidx;
214 }
215
216 SetOutput( fBackTransformedEvent, output, mask, ev, kTRUE );
217
218 return fBackTransformedEvent;
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// compute offset and scale from min and max
223
224void TMVA::VariableNormalizeTransform::CalcNormalizationParams( const std::vector< Event*>& events )
225{
226 if (events.size() <= 1)
227 Log() << kFATAL << "Not enough events (found " << events.size() << ") to calculate the normalization" << Endl;
228
229 FloatVector input; // will be filled with the selected variables, targets, (spectators)
230 std::vector<Char_t> mask;
231
232 UInt_t inputSize = fGet.size(); // number of input variables
233
234 const UInt_t nCls = GetNClasses();
235 Int_t numC = nCls+1; // prepare the min and max values for each of the classes and additionally for all classes (if more than one)
236 Int_t all = nCls; // at idx the min and max values for "all" classes are stored
237 if (nCls <= 1 ) {
238 numC = 1;
239 all = 0;
240 }
241
242 for (UInt_t iinp=0; iinp<inputSize; ++iinp) {
243 for (Int_t ic = 0; ic < numC; ic++) {
244 fMin.at(ic).at(iinp) = FLT_MAX;
245 fMax.at(ic).at(iinp) = -FLT_MAX;
246 }
247 }
248
249 std::vector<Event*>::const_iterator evIt = events.begin();
250 for (;evIt!=events.end();++evIt) { // loop over all events
251 const TMVA::Event* event = (*evIt); // get the event
252
253 UInt_t cls = (*evIt)->GetClass(); // get the class of this event
254
255 FloatVector& minVector = fMin.at(cls);
256 FloatVector& maxVector = fMax.at(cls);
257
258 FloatVector& minVectorAll = fMin.at(all);
259 FloatVector& maxVectorAll = fMax.at(all);
260
261 GetInput(event,input,mask); // select the input variables for the transformation and get them from the event
262 UInt_t iidx = 0;
263 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
264 Float_t val = (*itInp);
265
266 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
267 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
268
269 if (nCls != 1) { // in case more than one class exists, compute min and max as well for all classes together
270 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
271 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
272 }
273
274 ++iidx;
275 }
276 }
277
278 return;
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// creates string with variable transformations applied
283
285{
286 // if cls (the class chosen by the user) not existing, assume that user wants to
287 // have the matrix for all classes together.
288 if (cls < 0 || cls > GetNClasses()) cls = GetNClasses();
289
290 Float_t min, max;
291 const UInt_t size = fGet.size();
292 std::vector<TString>* strVec = new std::vector<TString>(size);
293
294 UInt_t iinp = 0;
295 for( ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
296 min = fMin.at(cls).at(iinp);
297 max = fMax.at(cls).at(iinp);
298
299 Char_t type = (*itGet).first;
300 UInt_t idx = (*itGet).second;
303 if (!fNoOffset) {
304 offset = min;
305 scale = 1.0/(max-min);
306 } else {
307 offset = 0.;
308 fabs(max)>fabs(min) ? scale=.5/fabs(max) : scale=.5/fabs(min);
309 }
310 TString str("");
311 VariableInfo& varInfo = (type=='v'?fDsi.GetVariableInfo(idx):(type=='t'?fDsi.GetTargetInfo(idx):fDsi.GetSpectatorInfo(idx)));
312
313 if (offset < 0) str = TString::Format( "2*%g*([%s] + %g) - 1", scale, varInfo.GetLabel().Data(), -offset );
314 else str = TString::Format( "2*%g*([%s] - %g) - 1", scale, varInfo.GetLabel().Data(), offset );
315 (*strVec)[iinp] = str;
316
317 ++iinp;
318 }
319
320 return strVec;
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// write the transformation to the stream
325
327{
328 o << "# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
329
330 Int_t numC = GetNClasses()+1;
331 if (GetNClasses() <= 1 ) numC = 1;
332
333 UInt_t nvars = GetNVariables();
334 UInt_t ntgts = GetNTargets();
335
336 for (Int_t icls = 0; icls < numC; icls++ ) {
337 o << icls << std::endl;
338 for (UInt_t ivar=0; ivar<nvars; ivar++)
339 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(ivar) << " "
340 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(ivar) << std::endl;
341 for (UInt_t itgt=0; itgt<ntgts; itgt++)
342 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(nvars+itgt) << " "
343 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(nvars+itgt) << std::endl;
344 }
345 o << "##" << std::endl;
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// create XML description of Normalize transformation
350
352{
353 void* trfxml = gTools().AddChild(parent, "Transform");
354 gTools().AddAttr(trfxml, "Name", "Normalize");
355 gTools().AddAttr(trfxml, "UseOffsetOrNot", (fNoOffset?"NoOffset":"UseOffset") );
357
358 Int_t numC = (GetNClasses()<= 1)?1:GetNClasses()+1;
359
360 for( Int_t icls=0; icls<numC; icls++ ) {
361 void* clsxml = gTools().AddChild(trfxml, "Class");
362 gTools().AddAttr(clsxml, "ClassIndex", icls);
363 void* inpxml = gTools().AddChild(clsxml, "Ranges");
364 UInt_t iinp = 0;
365 for( ItVarTypeIdx itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
366 void* mmxml = gTools().AddChild(inpxml, "Range");
367 gTools().AddAttr(mmxml, "Index", iinp);
368 gTools().AddAttr(mmxml, "Min", fMin.at(icls).at(iinp) );
369 gTools().AddAttr(mmxml, "Max", fMax.at(icls).at(iinp) );
370 ++iinp;
371 }
372 }
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Read the transformation matrices from the xml node
377
379{
381
382 gTools().ReadAttr(trfnode, "UseOffsetOrNot", UseOffsetOrNot );
383
384 if (UseOffsetOrNot == "NoOffset") fNoOffset = kTRUE;
385 else fNoOffset = kFALSE;
386
388
389 void* inpnode = NULL;
390
391 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
392 if( inpnode != NULL )
394
395 if( newFormat ){
396 // ------------- new format --------------------
397 // read input
399
400 // read transformation information
401
402 UInt_t size = fGet.size();
403 UInt_t classindex, idx;
404
405 void* ch = gTools().GetChild( trfnode, "Class" );
406 while(ch) {
407 Int_t ci = 0;
408 gTools().ReadAttr(ch, "ClassIndex", ci);
410
411 fMin.resize(classindex+1);
412 fMax.resize(classindex+1);
413
414 fMin[classindex].resize(size,Float_t(0));
415 fMax[classindex].resize(size,Float_t(0));
416
417 void* clch = gTools().GetChild( ch );
418 while(clch) {
419 TString nodeName(gTools().GetName(clch));
420 if(nodeName=="Ranges") {
421 void* varch = gTools().GetChild( clch );
422 while(varch) {
423 gTools().ReadAttr(varch, "Index", idx);
424 gTools().ReadAttr(varch, "Min", fMin[classindex][idx]);
425 gTools().ReadAttr(varch, "Max", fMax[classindex][idx]);
427 }
428 }
430 }
431 ch = gTools().GetNextChild( ch );
432 }
433 SetCreated();
434 return;
435 }
436
437 // ------------- old format --------------------
439 // coverity[tainted_data_argument]
440 gTools().ReadAttr(trfnode, "NVariables", nvars);
441 // coverity[tainted_data_argument]
442 gTools().ReadAttr(trfnode, "NTargets", ntgts);
443 // coverity[tainted_data_argument]
444
445 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
446 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
447 }
448 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
449 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
450 }
451 void* ch = gTools().GetChild( trfnode );
452 while(ch) {
453 gTools().ReadAttr(ch, "ClassIndex", classindex);
454
455 fMin.resize(classindex+1);
456 fMax.resize(classindex+1);
457 fMin[classindex].resize(nvars+ntgts,Float_t(0));
458 fMax[classindex].resize(nvars+ntgts,Float_t(0));
459
460 void* clch = gTools().GetChild( ch );
461 while(clch) {
462 TString nodeName(gTools().GetName(clch));
463 if(nodeName=="Variables") {
464 void* varch = gTools().GetChild( clch );
465 while(varch) {
466 gTools().ReadAttr(varch, "VarIndex", varindex);
467 gTools().ReadAttr(varch, "Min", fMin[classindex][varindex]);
468 gTools().ReadAttr(varch, "Max", fMax[classindex][varindex]);
470 }
471 } else if (nodeName=="Targets") {
472 void* tgtch = gTools().GetChild( clch );
473 while(tgtch) {
474 gTools().ReadAttr(tgtch, "TargetIndex", tgtindex);
475 gTools().ReadAttr(tgtch, "Min", fMin[classindex][nvars+tgtindex]);
476 gTools().ReadAttr(tgtch, "Max", fMax[classindex][nvars+tgtindex]);
478 }
479 }
481 }
482 ch = gTools().GetNextChild( ch );
483 }
484 SetCreated();
485}
486
487////////////////////////////////////////////////////////////////////////////////
488/// this method is only used when building a normalization transformation
489/// from old text files
490/// in this case regression didn't exist and there were no targets
491
492void TMVA::VariableNormalizeTransform::BuildTransformationFromVarInfo( const std::vector<TMVA::VariableInfo>& var )
493{
494 UInt_t nvars = GetNVariables();
495
496 if(var.size() != nvars)
497 Log() << kFATAL << "<BuildTransformationFromVarInfo> can't build transformation,"
498 << " since the number of variables disagree" << Endl;
499
500 UInt_t numC = (GetNClasses()<=1)?1:GetNClasses()+1;
501 fMin.clear();fMin.resize( numC );
502 fMax.clear();fMax.resize( numC );
503
504
505 for(UInt_t cls=0; cls<numC; ++cls) {
506 fMin[cls].resize(nvars+GetNTargets(),0);
507 fMax[cls].resize(nvars+GetNTargets(),0);
508 UInt_t vidx(0);
509 for(std::vector<TMVA::VariableInfo>::const_iterator v = var.begin(); v!=var.end(); ++v, ++vidx) {
510 fMin[cls][vidx] = v->GetMin();
511 fMax[cls][vidx] = v->GetMax();
512 fGet.push_back(std::pair<Char_t,UInt_t>('v',vidx));
513 }
514 }
515 SetCreated();
516}
517
518////////////////////////////////////////////////////////////////////////////////
519/// Read the variable ranges from an input stream
520
522{
523 UInt_t nvars = GetNVariables();
524 UInt_t ntgts = GetNTargets();
525 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
526 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
527 }
528 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
529 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
530 }
531 char buf[512];
532 char buf2[512];
533 istr.getline(buf,512);
534 TString strvar, dummy;
535 Int_t icls;
537 while (!(buf[0]=='#'&& buf[1]=='#')) { // if line starts with ## return
538 char* p = buf;
539 while (*p==' ' || *p=='\t') p++; // 'remove' leading whitespace
540 if (*p=='#' || *p=='\0') {
541 istr.getline(buf,512);
542 continue; // if comment or empty line, read the next line
543 }
544 std::stringstream sstr(buf);
545 sstr >> icls;
546 for (UInt_t ivar=0;ivar<nvars;ivar++) {
547 istr.getline(buf2,512); // reading the next line
548 std::stringstream sstr2(buf2);
549 sstr2 >> fMin[icls][ivar] >> fMax[icls][ivar];
550 }
551 for (UInt_t itgt=0;itgt<ntgts;itgt++) {
552 istr.getline(buf2,512); // reading the next line
553 std::stringstream sstr2(buf2);
554 sstr2 >> fMin[icls][nvars+itgt] >> fMax[icls][nvars+itgt];
555 }
556 istr.getline(buf,512); // reading the next line
557 }
558 SetCreated();
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// prints the transformation ranges
563
565{
566 Int_t nCls = GetNClasses();
567 Int_t numC = nCls+1;
568 if (nCls <= 1 ) numC = 1;
569 for (Int_t icls = 0; icls < numC; icls++ ) {
570 if( icls == nCls )
571 Log() << kINFO << "Transformation for all classes based on these ranges:" << Endl;
572 else
573 Log() << kINFO << "Transformation for class " << icls << " based on these ranges:" << Endl;
574 for( ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ){
575 Char_t type = (*itGet).first;
576 UInt_t idx = (*itGet).second;
577
578 TString typeString = (type=='v'?"Variable: ": (type=='t'?"Target : ":"Spectator : ") );
579 Log() << typeString.Data() << std::setw(20) << fMin[icls][idx] << std::setw(20) << fMax[icls][idx] << Endl;
580
581 }
582 }
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// creates a normalizing function
587/// TODO include target-transformation into makefunction
588
591{
592 UInt_t nVar = fGet.size();
593 UInt_t numC = fMin.size();
594 if (part == 1) {
595 fout << std::endl;
596 fout << " double fOff_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
597 fout << " double fScal_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
598 }
599
600 if (part == 2) {
601 fout << std::endl;
602 fout << "//_______________________________________________________________________" << std::endl;
603 fout << "inline void " << fcncName << "::InitTransform_" << trCounter << "()" << std::endl;
604 fout << "{" << std::endl;
605 fout << " double fMin_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
606 fout << " double fMax_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
607 fout << " // Normalization transformation, initialisation" << std::endl;
608 for (UInt_t ivar = 0; ivar < nVar; ivar++) {
609 for (UInt_t icls = 0; icls < numC; icls++) {
610 Double_t min = TMath::Min(FLT_MAX, fMin.at(icls).at(ivar));
611 Double_t max = TMath::Max(-FLT_MAX, fMax.at(icls).at(ivar));
612 fout << " fMin_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << min
613 << ";" << std::endl;
614 fout << " fMax_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << max
615 << ";" << std::endl;
616 fout << " fScal_" << trCounter << "[" << icls << "][" << ivar << "] = 2.0/(fMax_" << trCounter << "["
617 << icls << "][" << ivar << "]-fMin_" << trCounter << "[" << icls << "][" << ivar << "]);" << std::endl;
618 fout << " fOff_" << trCounter << "[" << icls << "][" << ivar << "] = fMin_" << trCounter << "[" << icls
619 << "][" << ivar << "]*fScal_" << trCounter << "[" << icls << "][" << ivar << "]+1.;" << std::endl;
620 }
621 }
622 fout << "}" << std::endl;
623 fout << std::endl;
624 fout << "//_______________________________________________________________________" << std::endl;
625 fout << "inline void " << fcncName << "::Transform_" << trCounter << "( std::vector<double>& iv, int cls) const"
626 << std::endl;
627 fout << "{" << std::endl;
628 fout << " // Normalization transformation" << std::endl;
629 fout << " if (cls < 0 || cls > " << GetNClasses() << ") {" << std::endl;
630 fout << " if (" << GetNClasses() << " > 1 ) cls = " << GetNClasses() << ";" << std::endl;
631 fout << " else cls = " << (fMin.size() == 1 ? 0 : 2) << ";" << std::endl;
632 fout << " }" << std::endl;
633 fout << " const int nVar = " << nVar << ";" << std::endl << std::endl;
634 fout << " // get indices of used variables" << std::endl;
636 fout << " static std::vector<double> dv;"
637 << std::endl; // simply made it static so it doesn't need to be re-booked every time
638 fout << " dv.resize(nVar);" << std::endl;
639 fout << " for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
640
641 fout << " for (int ivar=0;ivar<" << nVar << ";ivar++) {" << std::endl;
642 fout << " double offset = fOff_" << trCounter << "[cls][ivar];" << std::endl;
643 fout << " double scale = fScal_" << trCounter << "[cls][ivar];" << std::endl;
644 fout << " iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;" << std::endl;
645 fout << " }" << std::endl;
646 fout << "}" << std::endl;
647 }
648}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
const_iterator begin() const
const_iterator end() const
Class that contains all the data information.
Definition DataSetInfo.h:62
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition Tools.h:329
void * GetChild(void *parent, const char *childname=nullptr)
get child node
Definition Tools.cxx:1150
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
void * AddChild(void *parent, const char *childname, const char *content=nullptr, bool isRootNode=false)
add child node
Definition Tools.cxx:1124
void * GetNextChild(void *prevchild, const char *childname=nullptr)
XML helpers.
Definition Tools.cxx:1162
Singleton class for Global types used by TMVA.
Definition Types.h:71
Class for type info of MVA input variable.
void Initialize() override
initialization of the normalization transformation
void ReadTransformationFromStream(std::istream &, const TString &) override
Read the variable ranges from an input stream.
void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls) override
creates a normalizing function TODO include target-transformation into makefunction
const Event * Transform(const Event *const, Int_t cls) const override
apply the normalization transformation
void CalcNormalizationParams(const std::vector< Event * > &events)
compute offset and scale from min and max
std::vector< TString > * GetTransformationStrings(Int_t cls) const override
creates string with variable transformations applied
void PrintTransformation(std::ostream &o) override
prints the transformation ranges
void WriteTransformationToStream(std::ostream &) const override
write the transformation to the stream
void AttachXMLTo(void *parent) override
create XML description of Normalize transformation
VariableNormalizeTransform(DataSetInfo &dsi, TString strcor="")
constructor
void ReadFromXML(void *trfnode) override
Read the transformation matrices from the xml node.
Bool_t PrepareTransformation(const std::vector< Event * > &) override
prepare transformation
void BuildTransformationFromVarInfo(const std::vector< TMVA::VariableInfo > &var)
this method is only used when building a normalization transformation from old text files in this cas...
const Event * InverseTransform(const Event *const, Int_t cls) const override
apply the inverse transformation
Linear interpolation class.
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)=0
getinput and setoutput equivalent
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
VectorOfCharAndInt::iterator ItVarTypeIdx
VectorOfCharAndInt::const_iterator ItVarTypeIdxConst
Basic string class.
Definition TString.h:138
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:251
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
static void output()