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