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{
380 fNoOffset = kFALSE;
381 if (gTools().HasAttr(trfnode, "UseOffsetOrNot")) {
383
384 gTools().ReadAttr(trfnode, "UseOffsetOrNot", UseOffsetOrNot);
385
386 if (UseOffsetOrNot == "NoOffset")
387 fNoOffset = kTRUE;
388 else
389 fNoOffset = kFALSE;
390 }
392
393 void* inpnode = NULL;
394
395 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
396 if( inpnode != NULL )
398
399 if( newFormat ){
400 // ------------- new format --------------------
401 // read input
403
404 // read transformation information
405
406 UInt_t size = fGet.size();
407 UInt_t classindex, idx;
408
409 void* ch = gTools().GetChild( trfnode, "Class" );
410 while(ch) {
411 Int_t ci = 0;
412 gTools().ReadAttr(ch, "ClassIndex", ci);
414
415 fMin.resize(classindex+1);
416 fMax.resize(classindex+1);
417
418 fMin[classindex].resize(size,Float_t(0));
419 fMax[classindex].resize(size,Float_t(0));
420
421 void* clch = gTools().GetChild( ch );
422 while(clch) {
423 TString nodeName(gTools().GetName(clch));
424 if(nodeName=="Ranges") {
425 void* varch = gTools().GetChild( clch );
426 while(varch) {
427 gTools().ReadAttr(varch, "Index", idx);
428 gTools().ReadAttr(varch, "Min", fMin[classindex][idx]);
429 gTools().ReadAttr(varch, "Max", fMax[classindex][idx]);
431 }
432 }
434 }
435 ch = gTools().GetNextChild( ch );
436 }
437 SetCreated();
438 return;
439 }
440
441 // ------------- old format --------------------
443 // coverity[tainted_data_argument]
444 gTools().ReadAttr(trfnode, "NVariables", nvars);
445 // coverity[tainted_data_argument]
446 gTools().ReadAttr(trfnode, "NTargets", ntgts);
447 // coverity[tainted_data_argument]
448
449 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
450 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
451 }
452 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
453 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
454 }
455 void* ch = gTools().GetChild( trfnode );
456 while(ch) {
457 gTools().ReadAttr(ch, "ClassIndex", classindex);
458
459 fMin.resize(classindex+1);
460 fMax.resize(classindex+1);
461 fMin[classindex].resize(nvars+ntgts,Float_t(0));
462 fMax[classindex].resize(nvars+ntgts,Float_t(0));
463
464 void* clch = gTools().GetChild( ch );
465 while(clch) {
466 TString nodeName(gTools().GetName(clch));
467 if(nodeName=="Variables") {
468 void* varch = gTools().GetChild( clch );
469 while(varch) {
470 gTools().ReadAttr(varch, "VarIndex", varindex);
471 gTools().ReadAttr(varch, "Min", fMin[classindex][varindex]);
472 gTools().ReadAttr(varch, "Max", fMax[classindex][varindex]);
474 }
475 } else if (nodeName=="Targets") {
476 void* tgtch = gTools().GetChild( clch );
477 while(tgtch) {
478 gTools().ReadAttr(tgtch, "TargetIndex", tgtindex);
479 gTools().ReadAttr(tgtch, "Min", fMin[classindex][nvars+tgtindex]);
480 gTools().ReadAttr(tgtch, "Max", fMax[classindex][nvars+tgtindex]);
482 }
483 }
485 }
486 ch = gTools().GetNextChild( ch );
487 }
488 SetCreated();
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// this method is only used when building a normalization transformation
493/// from old text files
494/// in this case regression didn't exist and there were no targets
495
496void TMVA::VariableNormalizeTransform::BuildTransformationFromVarInfo( const std::vector<TMVA::VariableInfo>& var )
497{
498 UInt_t nvars = GetNVariables();
499
500 if(var.size() != nvars)
501 Log() << kFATAL << "<BuildTransformationFromVarInfo> can't build transformation,"
502 << " since the number of variables disagree" << Endl;
503
504 UInt_t numC = (GetNClasses()<=1)?1:GetNClasses()+1;
505 fMin.clear();fMin.resize( numC );
506 fMax.clear();fMax.resize( numC );
507
508
509 for(UInt_t cls=0; cls<numC; ++cls) {
510 fMin[cls].resize(nvars+GetNTargets(),0);
511 fMax[cls].resize(nvars+GetNTargets(),0);
512 UInt_t vidx(0);
513 for(std::vector<TMVA::VariableInfo>::const_iterator v = var.begin(); v!=var.end(); ++v, ++vidx) {
514 fMin[cls][vidx] = v->GetMin();
515 fMax[cls][vidx] = v->GetMax();
516 fGet.push_back(std::pair<Char_t,UInt_t>('v',vidx));
517 }
518 }
519 SetCreated();
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Read the variable ranges from an input stream
524
526{
527 UInt_t nvars = GetNVariables();
528 UInt_t ntgts = GetNTargets();
529 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
530 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
531 }
532 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
533 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
534 }
535 char buf[512];
536 char buf2[512];
537 istr.getline(buf,512);
538 TString strvar, dummy;
539 Int_t icls;
541 while (!(buf[0]=='#'&& buf[1]=='#')) { // if line starts with ## return
542 char* p = buf;
543 while (*p==' ' || *p=='\t') p++; // 'remove' leading whitespace
544 if (*p=='#' || *p=='\0') {
545 istr.getline(buf,512);
546 continue; // if comment or empty line, read the next line
547 }
548 std::stringstream sstr(buf);
549 sstr >> icls;
550 for (UInt_t ivar=0;ivar<nvars;ivar++) {
551 istr.getline(buf2,512); // reading the next line
552 std::stringstream sstr2(buf2);
553 sstr2 >> fMin[icls][ivar] >> fMax[icls][ivar];
554 }
555 for (UInt_t itgt=0;itgt<ntgts;itgt++) {
556 istr.getline(buf2,512); // reading the next line
557 std::stringstream sstr2(buf2);
558 sstr2 >> fMin[icls][nvars+itgt] >> fMax[icls][nvars+itgt];
559 }
560 istr.getline(buf,512); // reading the next line
561 }
562 SetCreated();
563}
564
565////////////////////////////////////////////////////////////////////////////////
566/// prints the transformation ranges
567
569{
570 Int_t nCls = GetNClasses();
571 Int_t numC = nCls+1;
572 if (nCls <= 1 ) numC = 1;
573 for (Int_t icls = 0; icls < numC; icls++ ) {
574 if( icls == nCls )
575 Log() << kINFO << "Transformation for all classes based on these ranges:" << Endl;
576 else
577 Log() << kINFO << "Transformation for class " << icls << " based on these ranges:" << Endl;
578 for( ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ){
579 Char_t type = (*itGet).first;
580 UInt_t idx = (*itGet).second;
581
582 TString typeString = (type=='v'?"Variable: ": (type=='t'?"Target : ":"Spectator : ") );
583 Log() << typeString.Data() << std::setw(20) << fMin[icls][idx] << std::setw(20) << fMax[icls][idx] << Endl;
584
585 }
586 }
587}
588
589////////////////////////////////////////////////////////////////////////////////
590/// creates a normalizing function
591/// TODO include target-transformation into makefunction
592
595{
596 UInt_t nVar = fGet.size();
597 UInt_t numC = fMin.size();
598 if (part == 1) {
599 fout << std::endl;
600 fout << " double fOff_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
601 fout << " double fScal_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
602 }
603
604 if (part == 2) {
605 fout << std::endl;
606 fout << "//_______________________________________________________________________" << std::endl;
607 fout << "inline void " << fcncName << "::InitTransform_" << trCounter << "()" << std::endl;
608 fout << "{" << std::endl;
609 fout << " double fMin_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
610 fout << " double fMax_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
611 fout << " // Normalization transformation, initialisation" << std::endl;
612 for (UInt_t ivar = 0; ivar < nVar; ivar++) {
613 for (UInt_t icls = 0; icls < numC; icls++) {
614 Double_t min = TMath::Min(FLT_MAX, fMin.at(icls).at(ivar));
615 Double_t max = TMath::Max(-FLT_MAX, fMax.at(icls).at(ivar));
616 fout << " fMin_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << min
617 << ";" << std::endl;
618 fout << " fMax_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << max
619 << ";" << std::endl;
620 fout << " fScal_" << trCounter << "[" << icls << "][" << ivar << "] = 2.0/(fMax_" << trCounter << "["
621 << icls << "][" << ivar << "]-fMin_" << trCounter << "[" << icls << "][" << ivar << "]);" << std::endl;
622 fout << " fOff_" << trCounter << "[" << icls << "][" << ivar << "] = fMin_" << trCounter << "[" << icls
623 << "][" << ivar << "]*fScal_" << trCounter << "[" << icls << "][" << ivar << "]+1.;" << std::endl;
624 }
625 }
626 fout << "}" << std::endl;
627 fout << std::endl;
628 fout << "//_______________________________________________________________________" << std::endl;
629 fout << "inline void " << fcncName << "::Transform_" << trCounter << "( std::vector<double>& iv, int cls) const"
630 << std::endl;
631 fout << "{" << std::endl;
632 fout << " // Normalization transformation" << std::endl;
633 fout << " if (cls < 0 || cls > " << GetNClasses() << ") {" << std::endl;
634 fout << " if (" << GetNClasses() << " > 1 ) cls = " << GetNClasses() << ";" << std::endl;
635 fout << " else cls = " << (fMin.size() == 1 ? 0 : 2) << ";" << std::endl;
636 fout << " }" << std::endl;
637 fout << " const int nVar = " << nVar << ";" << std::endl << std::endl;
638 fout << " // get indices of used variables" << std::endl;
640 fout << " static std::vector<double> dv;"
641 << std::endl; // simply made it static so it doesn't need to be re-booked every time
642 fout << " dv.resize(nVar);" << std::endl;
643 fout << " for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
644
645 fout << " for (int ivar=0;ivar<" << nVar << ";ivar++) {" << std::endl;
646 fout << " double offset = fOff_" << trCounter << "[cls][ivar];" << std::endl;
647 fout << " double scale = fScal_" << trCounter << "[cls][ivar];" << std::endl;
648 fout << " iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;" << std::endl;
649 fout << " }" << std::endl;
650 fout << "}" << std::endl;
651 }
652}
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:1125
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:1099
void * GetNextChild(void *prevchild, const char *childname=nullptr)
XML helpers.
Definition Tools.cxx:1137
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:249
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
static void output()