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 * Web : http://tmva.sourceforge.net *
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 * (http://tmva.sourceforge.net/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
54
55////////////////////////////////////////////////////////////////////////////////
56/// constructor
57
59: VariableTransformBase( dsi, Types::kNormalized, "Norm" )
60{
61}
62
63////////////////////////////////////////////////////////////////////////////////
64
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// initialization of the normalization transformation
70
72{
73 UInt_t inputSize = fGet.size();
74 Int_t numC = GetNClasses()+1;
75 if (GetNClasses() <= 1 ) numC = 1;
76
77 fMin.resize( numC );
78 fMax.resize( numC );
79 for (Int_t i=0; i<numC; i++) {
80 fMin.at(i).resize(inputSize);
81 fMax.at(i).resize(inputSize);
82 fMin.at(i).assign(inputSize, 0);
83 fMax.at(i).assign(inputSize, 0);
84 }
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// prepare transformation
89
91{
92 if (!IsEnabled() || IsCreated()) return kTRUE;
93
94 Log() << kDEBUG << "\tPreparing the transformation." << Endl;
95
96 Initialize();
97
98 CalcNormalizationParams( events );
99
100 SetCreated( kTRUE );
101
102 return kTRUE;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// apply the normalization transformation
107
109{
110 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
111
112 // if cls (the class chosen by the user) not existing,
113 // assume that he wants to have the matrix for all classes together.
114 // if (cls < 0 || cls > GetNClasses()) {
115 // if (GetNClasses() > 1 ) cls = GetNClasses();
116 // else cls = (fMin.size()==1?0:2);
117 // }
118 // EVT this is a workaround to address the reader problem with transforma and EvaluateMVA(std::vector<float/double> ,...)
119 if (cls < 0 || cls >= (int) fMin.size()) cls = fMin.size()-1;
120 // EVT workaround end
121
122 FloatVector input; // will be filled with the selected variables, targets, (spectators)
123 FloatVector output; // will be filled with the selected variables, targets, (spectators)
124 std::vector<Char_t> mask; // entries with kTRUE must not be transformed
125 GetInput( ev, input, mask );
126
127 if (fTransformedEvent==0) fTransformedEvent = new Event();
128
129 Float_t min,max;
130 const FloatVector& minVector = fMin.at(cls);
131 const FloatVector& maxVector = fMax.at(cls);
132
133 UInt_t iidx = 0;
134 std::vector<Char_t>::iterator itMask = mask.begin();
135 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
136 if( (*itMask) ){
137 ++iidx;
138 ++itMask;
139 // don't put any value into output if the value is masked
140 continue;
141 }
142
143 Float_t val = (*itInp);
144
145 min = minVector.at(iidx);
146 max = maxVector.at(iidx);
147 Float_t offset = min;
148 Float_t scale = 1.0/(max-min);
149
150 Float_t valnorm = (val-offset)*scale * 2 - 1;
151 output.push_back( valnorm );
152
153 ++iidx;
154 ++itMask;
155 }
156
157 SetOutput( fTransformedEvent, output, mask, ev );
158 return fTransformedEvent;
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// apply the inverse transformation
163
165{
166 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
167
168 // if cls (the class chosen by the user) not existing,
169 // assume that user wants to have the transformation for all classes together.
170 if (cls < 0 || cls > GetNClasses()) {
171 if (GetNClasses() > 1 ) cls = GetNClasses();
172 else cls = 0;
173 }
174
175 FloatVector input; // will be filled with the selected variables, targets, (spectators)
176 FloatVector output; // will be filled with the output
177 std::vector<Char_t> mask;
178 GetInput( ev, input, mask, kTRUE );
179
180 if (fBackTransformedEvent==0) fBackTransformedEvent = new Event( *ev );
181
182 Float_t min,max;
183 const FloatVector& minVector = fMin.at(cls);
184 const FloatVector& maxVector = fMax.at(cls);
185
186 UInt_t iidx = 0;
187 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
188 Float_t val = (*itInp);
189
190 min = minVector.at(iidx);
191 max = maxVector.at(iidx);
192 Float_t offset = min;
193 Float_t scale = 1.0/(max-min);
194
195 Float_t valnorm = offset+((val+1)/(scale * 2));
196 output.push_back( valnorm );
197
198 ++iidx;
199 }
200
201 SetOutput( fBackTransformedEvent, output, mask, ev, kTRUE );
202
203 return fBackTransformedEvent;
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// compute offset and scale from min and max
208
209void TMVA::VariableNormalizeTransform::CalcNormalizationParams( const std::vector< Event*>& events )
210{
211 if (events.size() <= 1)
212 Log() << kFATAL << "Not enough events (found " << events.size() << ") to calculate the normalization" << Endl;
213
214 FloatVector input; // will be filled with the selected variables, targets, (spectators)
215 std::vector<Char_t> mask;
216
217 UInt_t inputSize = fGet.size(); // number of input variables
218
219 const UInt_t nCls = GetNClasses();
220 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)
221 Int_t all = nCls; // at idx the min and max values for "all" classes are stored
222 if (nCls <= 1 ) {
223 numC = 1;
224 all = 0;
225 }
226
227 for (UInt_t iinp=0; iinp<inputSize; ++iinp) {
228 for (Int_t ic = 0; ic < numC; ic++) {
229 fMin.at(ic).at(iinp) = FLT_MAX;
230 fMax.at(ic).at(iinp) = -FLT_MAX;
231 }
232 }
233
234 std::vector<Event*>::const_iterator evIt = events.begin();
235 for (;evIt!=events.end();++evIt) { // loop over all events
236 const TMVA::Event* event = (*evIt); // get the event
237
238 UInt_t cls = (*evIt)->GetClass(); // get the class of this event
239
240 FloatVector& minVector = fMin.at(cls);
241 FloatVector& maxVector = fMax.at(cls);
242
243 FloatVector& minVectorAll = fMin.at(all);
244 FloatVector& maxVectorAll = fMax.at(all);
245
246 GetInput(event,input,mask); // select the input variables for the transformation and get them from the event
247 UInt_t iidx = 0;
248 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) { // loop over input variables
249 Float_t val = (*itInp);
250
251 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
252 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
253
254 if (nCls != 1) { // in case more than one class exists, compute min and max as well for all classes together
255 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
256 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
257 }
258
259 ++iidx;
260 }
261 }
262
263 return;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// creates string with variable transformations applied
268
270{
271 // if cls (the class chosen by the user) not existing, assume that user wants to
272 // have the matrix for all classes together.
273 if (cls < 0 || cls > GetNClasses()) cls = GetNClasses();
274
275 Float_t min, max;
276 const UInt_t size = fGet.size();
277 std::vector<TString>* strVec = new std::vector<TString>(size);
278
279 UInt_t iinp = 0;
280 for( ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
281 min = fMin.at(cls).at(iinp);
282 max = fMax.at(cls).at(iinp);
283
284 Char_t type = (*itGet).first;
285 UInt_t idx = (*itGet).second;
286 Float_t offset = min;
287 Float_t scale = 1.0/(max-min);
288 TString str("");
289 VariableInfo& varInfo = (type=='v'?fDsi.GetVariableInfo(idx):(type=='t'?fDsi.GetTargetInfo(idx):fDsi.GetSpectatorInfo(idx)));
290
291 if (offset < 0) str = Form( "2*%g*([%s] + %g) - 1", scale, varInfo.GetLabel().Data(), -offset );
292 else str = Form( "2*%g*([%s] - %g) - 1", scale, varInfo.GetLabel().Data(), offset );
293 (*strVec)[iinp] = str;
294
295 ++iinp;
296 }
297
298 return strVec;
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// write the transformation to the stream
303
305{
306 o << "# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
307
308 Int_t numC = GetNClasses()+1;
309 if (GetNClasses() <= 1 ) numC = 1;
310
311 UInt_t nvars = GetNVariables();
312 UInt_t ntgts = GetNTargets();
313
314 for (Int_t icls = 0; icls < numC; icls++ ) {
315 o << icls << std::endl;
316 for (UInt_t ivar=0; ivar<nvars; ivar++)
317 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(ivar) << " "
318 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(ivar) << std::endl;
319 for (UInt_t itgt=0; itgt<ntgts; itgt++)
320 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(nvars+itgt) << " "
321 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(nvars+itgt) << std::endl;
322 }
323 o << "##" << std::endl;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// create XML description of Normalize transformation
328
330{
331 void* trfxml = gTools().AddChild(parent, "Transform");
332 gTools().AddAttr(trfxml, "Name", "Normalize");
334
335 Int_t numC = (GetNClasses()<= 1)?1:GetNClasses()+1;
336
337 for( Int_t icls=0; icls<numC; icls++ ) {
338 void* clsxml = gTools().AddChild(trfxml, "Class");
339 gTools().AddAttr(clsxml, "ClassIndex", icls);
340 void* inpxml = gTools().AddChild(clsxml, "Ranges");
341 UInt_t iinp = 0;
342 for( ItVarTypeIdx itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
343 void* mmxml = gTools().AddChild(inpxml, "Range");
344 gTools().AddAttr(mmxml, "Index", iinp);
345 gTools().AddAttr(mmxml, "Min", fMin.at(icls).at(iinp) );
346 gTools().AddAttr(mmxml, "Max", fMax.at(icls).at(iinp) );
347 ++iinp;
348 }
349 }
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Read the transformation matrices from the xml node
354
356{
357 Bool_t newFormat = kFALSE;
358
359 void* inpnode = NULL;
360
361 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
362 if( inpnode != NULL )
363 newFormat = kTRUE;
364
365 if( newFormat ){
366 // ------------- new format --------------------
367 // read input
369
370 // read transformation information
371
372 UInt_t size = fGet.size();
373 UInt_t classindex, idx;
374
375 void* ch = gTools().GetChild( trfnode, "Class" );
376 while(ch) {
377 Int_t ci = 0;
378 gTools().ReadAttr(ch, "ClassIndex", ci);
379 classindex = UInt_t(ci);
380
381 fMin.resize(classindex+1);
382 fMax.resize(classindex+1);
383
384 fMin[classindex].resize(size,Float_t(0));
385 fMax[classindex].resize(size,Float_t(0));
386
387 void* clch = gTools().GetChild( ch );
388 while(clch) {
389 TString nodeName(gTools().GetName(clch));
390 if(nodeName=="Ranges") {
391 void* varch = gTools().GetChild( clch );
392 while(varch) {
393 gTools().ReadAttr(varch, "Index", idx);
394 gTools().ReadAttr(varch, "Min", fMin[classindex][idx]);
395 gTools().ReadAttr(varch, "Max", fMax[classindex][idx]);
396 varch = gTools().GetNextChild( varch );
397 }
398 }
399 clch = gTools().GetNextChild( clch );
400 }
401 ch = gTools().GetNextChild( ch );
402 }
403 SetCreated();
404 return;
405 }
406
407 // ------------- old format --------------------
408 UInt_t classindex, varindex, tgtindex, nvars, ntgts;
409 // coverity[tainted_data_argument]
410 gTools().ReadAttr(trfnode, "NVariables", nvars);
411 // coverity[tainted_data_argument]
412 gTools().ReadAttr(trfnode, "NTargets", ntgts);
413 // coverity[tainted_data_argument]
414
415 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
416 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
417 }
418 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
419 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
420 }
421 void* ch = gTools().GetChild( trfnode );
422 while(ch) {
423 gTools().ReadAttr(ch, "ClassIndex", classindex);
424
425 fMin.resize(classindex+1);
426 fMax.resize(classindex+1);
427 fMin[classindex].resize(nvars+ntgts,Float_t(0));
428 fMax[classindex].resize(nvars+ntgts,Float_t(0));
429
430 void* clch = gTools().GetChild( ch );
431 while(clch) {
432 TString nodeName(gTools().GetName(clch));
433 if(nodeName=="Variables") {
434 void* varch = gTools().GetChild( clch );
435 while(varch) {
436 gTools().ReadAttr(varch, "VarIndex", varindex);
437 gTools().ReadAttr(varch, "Min", fMin[classindex][varindex]);
438 gTools().ReadAttr(varch, "Max", fMax[classindex][varindex]);
439 varch = gTools().GetNextChild( varch );
440 }
441 } else if (nodeName=="Targets") {
442 void* tgtch = gTools().GetChild( clch );
443 while(tgtch) {
444 gTools().ReadAttr(tgtch, "TargetIndex", tgtindex);
445 gTools().ReadAttr(tgtch, "Min", fMin[classindex][nvars+tgtindex]);
446 gTools().ReadAttr(tgtch, "Max", fMax[classindex][nvars+tgtindex]);
447 tgtch = gTools().GetNextChild( tgtch );
448 }
449 }
450 clch = gTools().GetNextChild( clch );
451 }
452 ch = gTools().GetNextChild( ch );
453 }
454 SetCreated();
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// this method is only used when building a normalization transformation
459/// from old text files
460/// in this case regression didn't exist and there were no targets
461
462void TMVA::VariableNormalizeTransform::BuildTransformationFromVarInfo( const std::vector<TMVA::VariableInfo>& var )
463{
464 UInt_t nvars = GetNVariables();
465
466 if(var.size() != nvars)
467 Log() << kFATAL << "<BuildTransformationFromVarInfo> can't build transformation,"
468 << " since the number of variables disagree" << Endl;
469
470 UInt_t numC = (GetNClasses()<=1)?1:GetNClasses()+1;
471 fMin.clear();fMin.resize( numC );
472 fMax.clear();fMax.resize( numC );
473
474
475 for(UInt_t cls=0; cls<numC; ++cls) {
476 fMin[cls].resize(nvars+GetNTargets(),0);
477 fMax[cls].resize(nvars+GetNTargets(),0);
478 UInt_t vidx(0);
479 for(std::vector<TMVA::VariableInfo>::const_iterator v = var.begin(); v!=var.end(); ++v, ++vidx) {
480 fMin[cls][vidx] = v->GetMin();
481 fMax[cls][vidx] = v->GetMax();
482 fGet.push_back(std::pair<Char_t,UInt_t>('v',vidx));
483 }
484 }
485 SetCreated();
486}
487
488////////////////////////////////////////////////////////////////////////////////
489/// Read the variable ranges from an input stream
490
492{
493 UInt_t nvars = GetNVariables();
494 UInt_t ntgts = GetNTargets();
495 for( UInt_t ivar = 0; ivar < nvars; ++ivar ){
496 fGet.push_back(std::pair<Char_t,UInt_t>('v',ivar));
497 }
498 for( UInt_t itgt = 0; itgt < ntgts; ++itgt ){
499 fGet.push_back(std::pair<Char_t,UInt_t>('t',itgt));
500 }
501 char buf[512];
502 char buf2[512];
503 istr.getline(buf,512);
504 TString strvar, dummy;
505 Int_t icls;
507 while (!(buf[0]=='#'&& buf[1]=='#')) { // if line starts with ## return
508 char* p = buf;
509 while (*p==' ' || *p=='\t') p++; // 'remove' leading whitespace
510 if (*p=='#' || *p=='\0') {
511 istr.getline(buf,512);
512 continue; // if comment or empty line, read the next line
513 }
514 std::stringstream sstr(buf);
515 sstr >> icls;
516 for (UInt_t ivar=0;ivar<nvars;ivar++) {
517 istr.getline(buf2,512); // reading the next line
518 std::stringstream sstr2(buf2);
519 sstr2 >> fMin[icls][ivar] >> fMax[icls][ivar];
520 }
521 for (UInt_t itgt=0;itgt<ntgts;itgt++) {
522 istr.getline(buf2,512); // reading the next line
523 std::stringstream sstr2(buf2);
524 sstr2 >> fMin[icls][nvars+itgt] >> fMax[icls][nvars+itgt];
525 }
526 istr.getline(buf,512); // reading the next line
527 }
528 SetCreated();
529}
530
531////////////////////////////////////////////////////////////////////////////////
532/// prints the transformation ranges
533
535{
536 Int_t nCls = GetNClasses();
537 Int_t numC = nCls+1;
538 if (nCls <= 1 ) numC = 1;
539 for (Int_t icls = 0; icls < numC; icls++ ) {
540 if( icls == nCls )
541 Log() << kINFO << "Transformation for all classes based on these ranges:" << Endl;
542 else
543 Log() << kINFO << "Transformation for class " << icls << " based on these ranges:" << Endl;
544 UInt_t iinp = 0;
545 for( ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ){
546 Char_t type = (*itGet).first;
547 UInt_t idx = (*itGet).second;
548
549 TString typeString = (type=='v'?"Variable: ": (type=='t'?"Target : ":"Spectator : ") );
550 Log() << typeString.Data() << std::setw(20) << fMin[icls][idx] << std::setw(20) << fMax[icls][idx] << Endl;
551
552 ++iinp;
553 }
554 }
555}
556
557////////////////////////////////////////////////////////////////////////////////
558/// creates a normalizing function
559/// TODO include target-transformation into makefunction
560
561void TMVA::VariableNormalizeTransform::MakeFunction( std::ostream& fout, const TString& fcncName,
562 Int_t part, UInt_t trCounter, Int_t )
563{
564 UInt_t nVar = fGet.size();
565 UInt_t numC = fMin.size();
566 if (part == 1) {
567 fout << std::endl;
568 fout << " double fOff_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
569 fout << " double fScal_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
570 }
571
572 if (part == 2) {
573 fout << std::endl;
574 fout << "//_______________________________________________________________________" << std::endl;
575 fout << "inline void " << fcncName << "::InitTransform_" << trCounter << "()" << std::endl;
576 fout << "{" << std::endl;
577 fout << " double fMin_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
578 fout << " double fMax_" << trCounter << "[" << numC << "][" << nVar << "];" << std::endl;
579 fout << " // Normalization transformation, initialisation" << std::endl;
580 for (UInt_t ivar = 0; ivar < nVar; ivar++) {
581 for (UInt_t icls = 0; icls < numC; icls++) {
582 Double_t min = TMath::Min(FLT_MAX, fMin.at(icls).at(ivar));
583 Double_t max = TMath::Max(-FLT_MAX, fMax.at(icls).at(ivar));
584 fout << " fMin_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << min
585 << ";" << std::endl;
586 fout << " fMax_" << trCounter << "[" << icls << "][" << ivar << "] = " << std::setprecision(12) << max
587 << ";" << std::endl;
588 fout << " fScal_" << trCounter << "[" << icls << "][" << ivar << "] = 2.0/(fMax_" << trCounter << "["
589 << icls << "][" << ivar << "]-fMin_" << trCounter << "[" << icls << "][" << ivar << "]);" << std::endl;
590 fout << " fOff_" << trCounter << "[" << icls << "][" << ivar << "] = fMin_" << trCounter << "[" << icls
591 << "][" << ivar << "]*fScal_" << trCounter << "[" << icls << "][" << ivar << "]+1.;" << std::endl;
592 }
593 }
594 fout << "}" << std::endl;
595 fout << std::endl;
596 fout << "//_______________________________________________________________________" << std::endl;
597 fout << "inline void " << fcncName << "::Transform_" << trCounter << "( std::vector<double>& iv, int cls) const"
598 << std::endl;
599 fout << "{" << std::endl;
600 fout << " // Normalization transformation" << std::endl;
601 fout << " if (cls < 0 || cls > " << GetNClasses() << ") {" << std::endl;
602 fout << " if (" << GetNClasses() << " > 1 ) cls = " << GetNClasses() << ";" << std::endl;
603 fout << " else cls = " << (fMin.size() == 1 ? 0 : 2) << ";" << std::endl;
604 fout << " }" << std::endl;
605 fout << " const int nVar = " << nVar << ";" << std::endl << std::endl;
606 fout << " // get indices of used variables" << std::endl;
607 VariableTransformBase::MakeFunction(fout, fcncName, 0, trCounter, 0);
608 fout << " static std::vector<double> dv;"
609 << std::endl; // simply made it static so it doesn't need to be re-booked every time
610 fout << " dv.resize(nVar);" << std::endl;
611 fout << " for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
612
613 fout << " for (int ivar=0;ivar<" << nVar << ";ivar++) {" << std::endl;
614 fout << " double offset = fOff_" << trCounter << "[cls][ivar];" << std::endl;
615 fout << " double scale = fScal_" << trCounter << "[cls][ivar];" << std::endl;
616 fout << " iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;" << std::endl;
617 fout << " }" << std::endl;
618 fout << "}" << std::endl;
619 }
620}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char Char_t
Definition RtypesCore.h:37
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
int type
Definition TGX11.cxx:121
char * Form(const char *fmt,...)
Class that contains all the data information.
Definition DataSetInfo.h:62
void * GetNextChild(void *prevchild, const char *childname=0)
XML helpers.
Definition Tools.cxx:1162
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition Tools.cxx:1124
void * GetChild(void *parent, const char *childname=0)
get child node
Definition Tools.cxx:1150
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition Tools.h:329
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
Singleton class for Global types used by TMVA.
Definition Types.h:71
Class for type info of MVA input variable.
const TString & GetLabel() const
void CalcNormalizationParams(const std::vector< Event * > &events)
compute offset and scale from min and max
void Initialize()
initialization of the normalization transformation
virtual const Event * Transform(const Event *const, Int_t cls) const
apply the normalization transformation
Bool_t PrepareTransformation(const std::vector< Event * > &)
prepare transformation
virtual const Event * InverseTransform(const Event *const, Int_t cls) const
apply the inverse transformation
virtual void ReadFromXML(void *trfnode)
Read the transformation matrices from the xml node.
virtual void AttachXMLTo(void *parent)
create XML description of Normalize transformation
void WriteTransformationToStream(std::ostream &) const
write the transformation to the stream
void ReadTransformationFromStream(std::istream &, const TString &)
Read the variable ranges from an input stream.
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)
creates a normalizing function TODO include target-transformation into makefunction
VariableNormalizeTransform(DataSetInfo &dsi)
constructor
std::vector< TString > * GetTransformationStrings(Int_t cls) const
creates string with variable transformations applied
virtual void PrintTransformation(std::ostream &o)
prints the transformation ranges
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...
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:136
const char * Data() const
Definition TString.h:369
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:208
Short_t Min(Short_t a, Short_t b)
Definition TMathBase.h:176
Definition test.py:1
static void output(int code)
Definition gifencode.c:226