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