Logo ROOT  
Reference Guide
VariableTransformBase.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer,Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : VariableTransformBase *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Pre-transformation of input variables (base class) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * *
19  * Copyright (c) 2005: *
20  * CERN, Switzerland *
21  * U. of Victoria, Canada *
22  * MPI-K Heidelberg, Germany *
23  * *
24  * Redistribution and use in source and binary forms, with or without *
25  * modification, are permitted according to the terms listed in LICENSE *
26  * (http://tmva.sourceforge.net/LICENSE) *
27  **********************************************************************************/
28 
29 #ifndef ROOT_TMVA_VariableTransformBase
30 #define ROOT_TMVA_VariableTransformBase
31 
32 //////////////////////////////////////////////////////////////////////////
33 // //
34 // VariableTransformBase //
35 // //
36 // Linear interpolation class //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 
40 #include <vector>
41 #include <utility>
42 
43 #include "TH1.h"
44 #include "TDirectory.h"
45 #include "TString.h"
46 
47 #include "TMVA/Types.h"
48 #include "TMVA/Event.h"
49 #include "TMVA/VariableInfo.h"
50 #include "TMVA/DataSetInfo.h"
51 
52 namespace TMVA {
53 
54  class VariableTransformBase : public TObject {
55 
56  public:
57 
58  typedef std::vector<std::pair<Char_t,UInt_t> > VectorOfCharAndInt;
59  typedef VectorOfCharAndInt::iterator ItVarTypeIdx;
60  typedef VectorOfCharAndInt::const_iterator ItVarTypeIdxConst;
61 
62  VariableTransformBase( DataSetInfo& dsi, Types::EVariableTransform tf, const TString& trfName );
63  virtual ~VariableTransformBase( void );
64 
65  virtual void Initialize() = 0;
66  virtual Bool_t PrepareTransformation (const std::vector<Event*>& ) = 0;
67  virtual const Event* Transform ( const Event* const, Int_t cls ) const = 0;
68  virtual const Event* InverseTransform( const Event* const, Int_t cls ) const = 0;
69 
70  // accessors
71  void SetEnabled ( Bool_t e ) { fEnabled = e; }
72  void SetNormalise( Bool_t n ) { fNormalise = n; }
73  Bool_t IsEnabled() const { return fEnabled; }
74  Bool_t IsCreated() const { return fCreated; }
75  Bool_t IsNormalised() const { return fNormalise; }
76 
77  // variable selection
78  virtual void SelectInput( const TString& inputVariables, Bool_t putIntoVariables = kFALSE );
79  virtual Bool_t GetInput ( const Event* event, std::vector<Float_t>& input, std::vector<Char_t>& mask, Bool_t backTransform = kFALSE ) const;
80  virtual void SetOutput( Event* event, std::vector<Float_t>& output, std::vector<Char_t>& mask, const Event* oldEvent = 0, Bool_t backTransform = kFALSE ) const;
81  virtual void CountVariableTypes( UInt_t& nvars, UInt_t& ntgts, UInt_t& nspcts ) const;
82 
83  void ToggleInputSortOrder( Bool_t sortOrder ) { fSortGet = sortOrder; }
84  void SetOutputDataSetInfo( DataSetInfo* outputDsi ) { fDsiOutput = outputDsi; }
85 
86 
87 
90 
91  virtual const char* GetName() const { return fTransformName.Data(); }
92  TString GetShortName() const { TString a(fTransformName); a.ReplaceAll("Transform",""); return a; }
93 
94  virtual void WriteTransformationToStream ( std::ostream& o ) const = 0;
95  virtual void ReadTransformationFromStream( std::istream& istr, const TString& classname="" ) = 0;
96 
97  virtual void AttachXMLTo(void* parent) = 0;
98  virtual void ReadFromXML( void* trfnode ) = 0;
99 
101 
102  // writer of function code
103  virtual void MakeFunction( std::ostream& fout, const TString& fncName, Int_t part,
104  UInt_t trCounter, Int_t cls ) = 0;
105 
106  // provides string vector giving explicit transformation
107  virtual std::vector<TString>* GetTransformationStrings( Int_t cls ) const;
108  virtual void PrintTransformation( std::ostream & ) {}
109 
110  const std::vector<TMVA::VariableInfo>& Variables() const { return fVariables; }
111  const std::vector<TMVA::VariableInfo>& Targets() const { return fTargets; }
112  const std::vector<TMVA::VariableInfo>& Spectators() const { return fSpectators; }
113 
114  MsgLogger& Log() const { return *fLogger; }
115 
116  void SetTMVAVersion(TMVAVersion_t v) { fTMVAVersion = v; }
117 
118  protected:
119 
120  void CalcNorm( const std::vector<const Event*>& );
121 
122  void SetCreated( Bool_t c = kTRUE ) { fCreated = c; }
123  void SetNVariables( UInt_t i ) { fNVars = i; }
124  void SetName( const TString& c ) { fTransformName = c; }
125 
126  UInt_t GetNVariables() const { return fDsi.GetNVariables(); }
127  UInt_t GetNTargets() const { return fDsi.GetNTargets(); }
128  UInt_t GetNSpectators() const { return fDsi.GetNSpectators(); }
129 
132 
133  std::vector<TMVA::VariableInfo>& Variables() { return fVariables; }
134  std::vector<TMVA::VariableInfo>& Targets() { return fTargets; }
135  std::vector<TMVA::VariableInfo>& Spectators() { return fSpectators; }
136  Int_t GetNClasses() const { return fDsi.GetNClasses(); }
137 
138 
139  mutable Event* fTransformedEvent; // holds the current transformed event
140  mutable Event* fBackTransformedEvent; // holds the current back-transformed event
141 
142  // variable selection
143  VectorOfCharAndInt fGet; // get variables/targets/spectators
144  VectorOfCharAndInt fPut; // put variables/targets/spectators
145 
146  private:
147 
148  Types::EVariableTransform fVariableTransform; // Decorrelation, PCA, etc.
149 
150  void UpdateNorm( Int_t ivar, Double_t x );
151 
152  Bool_t fUseSignalTransform; // true if transformation bases on signal data
153  Bool_t fEnabled; // has been enabled
154  Bool_t fCreated; // has been created
155  Bool_t fNormalise; // normalise input variables
156  UInt_t fNVars; // number of variables
157  TString fTransformName; // name of transformation
158  std::vector<TMVA::VariableInfo> fVariables; // event variables [saved to weight file]
159  std::vector<TMVA::VariableInfo> fTargets; // event targets [saved to weight file --> TODO ]
160  std::vector<TMVA::VariableInfo> fSpectators; // event spectators [saved to weight file --> TODO ]
161 
162  mutable Bool_t fVariableTypesAreCounted; // true if variable types have been counted already
163  mutable UInt_t fNVariables; // number of variables to be transformed
164  mutable UInt_t fNTargets; // number of targets to be transformed
165  mutable UInt_t fNSpectators; // number of spectators to be transformed
166 
167  Bool_t fSortGet; // if true, sort the variables into the order as defined by the user at the var definition
168  // if false, sort the variables according to the order given for the var transformation
169 
170  protected:
171 
172  TMVAVersion_t fTMVAVersion;
173 
174  mutable MsgLogger* fLogger; //! message logger
175 
176  ClassDef(VariableTransformBase,0); // Base class for variable transformations
177  };
178 
179 } // namespace TMVA
180 
181 #endif
c
#define c(i)
Definition: RSha256.hxx:119
TMVA::VariableTransformBase::CountVariableTypes
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
Definition: VariableTransformBase.cxx:429
TMVA::VariableTransformBase::Transform
virtual const Event * Transform(const Event *const, Int_t cls) const =0
n
const Int_t n
Definition: legend1.C:16
TMVA::VariableTransformBase::SetCreated
void SetCreated(Bool_t c=kTRUE)
Definition: VariableTransformBase.h:168
TMVA::VariableTransformBase::fDsi
DataSetInfo & fDsi
Definition: VariableTransformBase.h:176
TMVA::VariableTransformBase::Initialize
virtual void Initialize()=0
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
e
#define e(i)
Definition: RSha256.hxx:121
TMVA::VariableTransformBase::VectorOfCharAndInt
std::vector< std::pair< Char_t, UInt_t > > VectorOfCharAndInt
Definition: VariableTransformBase.h:104
TMVA::VariableTransformBase::MakeFunction
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)=0
getinput and setoutput equivalent
Definition: VariableTransformBase.cxx:817
TDirectory.h
TMVA::VariableTransformBase::WriteTransformationToStream
virtual void WriteTransformationToStream(std::ostream &o) const =0
TMVA::VariableTransformBase::GetNVariables
UInt_t GetNVariables() const
Definition: VariableTransformBase.h:172
TMVA::VariableTransformBase::fTargets
std::vector< TMVA::VariableInfo > fTargets
Definition: VariableTransformBase.h:205
TString::Data
const char * Data() const
Definition: TString.h:369
TMVA::VariableTransformBase::AttachXMLTo
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
Definition: VariableTransformBase.cxx:620
DataSetInfo.h
TMVA::VariableTransformBase::SetUseSignalTransform
void SetUseSignalTransform(Bool_t e=kTRUE)
Definition: VariableTransformBase.h:134
output
static void output(int code)
Definition: gifencode.c:226
TMVA::VariableTransformBase::GetNClasses
Int_t GetNClasses() const
Definition: VariableTransformBase.h:182
TMVA::VariableTransformBase::ItVarTypeIdx
VectorOfCharAndInt::iterator ItVarTypeIdx
Definition: VariableTransformBase.h:105
TMVA::DataSetInfo::GetNVariables
UInt_t GetNVariables() const
Definition: DataSetInfo.h:127
TMVA::DataSetInfo::GetNSpectators
UInt_t GetNSpectators(bool all=kTRUE) const
Definition: DataSetInfo.cxx:496
TMVA::VariableTransformBase::Variables
const std::vector< TMVA::VariableInfo > & Variables() const
Definition: VariableTransformBase.h:156
TMVA::VariableTransformBase::SetOutput
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
Definition: VariableTransformBase.cxx:368
VariableInfo.h
TMVA::VariableTransformBase::SetTMVAVersion
void SetTMVAVersion(TMVAVersion_t v)
Definition: VariableTransformBase.h:162
Int_t
int Int_t
Definition: RtypesCore.h:45
TMVA::VariableTransformBase::Targets
const std::vector< TMVA::VariableInfo > & Targets() const
Definition: VariableTransformBase.h:157
TMVA::VariableTransformBase::SetOutputDataSetInfo
void SetOutputDataSetInfo(DataSetInfo *outputDsi)
Definition: VariableTransformBase.h:130
x
Double_t x[n]
Definition: legend1.C:17
TMVA::VariableTransformBase::GetTransformationStrings
virtual std::vector< TString > * GetTransformationStrings(Int_t cls) const
TODO --> adapt to variable,target,spectator selection default transformation output --> only indicate...
Definition: VariableTransformBase.cxx:591
TMVA::VariableTransformBase::GetName
virtual const char * GetName() const
Returns name of object.
Definition: VariableTransformBase.h:137
TMVA::VariableTransformBase
Definition: VariableTransformBase.h:77
TMVA::VariableTransformBase::fNormalise
Bool_t fNormalise
Definition: VariableTransformBase.h:201
TString
Definition: TString.h:136
TMVA::VariableTransformBase::Log
MsgLogger & Log() const
Definition: VariableTransformBase.h:160
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMVA::VariableTransformBase::fVariableTransform
Types::EVariableTransform fVariableTransform
Definition: VariableTransformBase.h:194
TMVA::VariableTransformBase::Spectators
const std::vector< TMVA::VariableInfo > & Spectators() const
Definition: VariableTransformBase.h:158
v
@ v
Definition: rootcling_impl.cxx:3635
TString.h
bool
TMVA::VariableTransformBase::fVariables
std::vector< TMVA::VariableInfo > fVariables
Definition: VariableTransformBase.h:204
TMVA::DataSetInfo::GetNClasses
UInt_t GetNClasses() const
Definition: DataSetInfo.h:155
TMVA::VariableTransformBase::GetInput
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
Definition: VariableTransformBase.cxx:315
TMVA::VariableTransformBase::ItVarTypeIdxConst
VectorOfCharAndInt::const_iterator ItVarTypeIdxConst
Definition: VariableTransformBase.h:106
TMVA::DataSetInfo
Definition: DataSetInfo.h:62
TMVA::VariableTransformBase::IsCreated
Bool_t IsCreated() const
Definition: VariableTransformBase.h:120
TMVA::VariableTransformBase::fEnabled
Bool_t fEnabled
Definition: VariableTransformBase.h:199
TMVA::VariableTransformBase::IsNormalised
Bool_t IsNormalised() const
Definition: VariableTransformBase.h:121
TMVA::VariableTransformBase::fBackTransformedEvent
Event * fBackTransformedEvent
Definition: VariableTransformBase.h:186
TMVA::VariableTransformBase::ReadFromXML
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
Definition: VariableTransformBase.cxx:708
TMVA::VariableTransformBase::fLogger
MsgLogger * fLogger
Definition: VariableTransformBase.h:220
TMVA::VariableTransformBase::fTransformName
TString fTransformName
Definition: VariableTransformBase.h:203
TMVA::VariableTransformBase::GetNTargets
UInt_t GetNTargets() const
Definition: VariableTransformBase.h:173
TMVA::VariableTransformBase::fPut
VectorOfCharAndInt fPut
Definition: VariableTransformBase.h:190
a
auto * a
Definition: textangle.C:12
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::VariableTransformBase::SetNormalise
void SetNormalise(Bool_t n)
Definition: VariableTransformBase.h:118
TMVA::VariableTransformBase::PrintTransformation
virtual void PrintTransformation(std::ostream &)
Definition: VariableTransformBase.h:154
TMVA::VariableTransformBase::SetName
void SetName(const TString &c)
Definition: VariableTransformBase.h:170
Event.h
TMVA::VariableTransformBase::GetShortName
TString GetShortName() const
Definition: VariableTransformBase.h:138
TMVA::VariableTransformBase::fCreated
Bool_t fCreated
Definition: VariableTransformBase.h:200
TMVA::VariableTransformBase::SetNVariables
void SetNVariables(UInt_t i)
Definition: VariableTransformBase.h:169
TMVA::VariableTransformBase::VariableTransformBase
VariableTransformBase(DataSetInfo &dsi, Types::EVariableTransform tf, const TString &trfName)
standard constructor
Definition: VariableTransformBase.cxx:64
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TMVA::VariableTransformBase::IsEnabled
Bool_t IsEnabled() const
Definition: VariableTransformBase.h:119
TMVA::VariableTransformBase::UseSignalTransform
Bool_t UseSignalTransform() const
Definition: VariableTransformBase.h:135
Types.h
TMVA::VariableTransformBase::ReadTransformationFromStream
virtual void ReadTransformationFromStream(std::istream &istr, const TString &classname="")=0
TMVA::VariableTransformBase::fSortGet
Bool_t fSortGet
Definition: VariableTransformBase.h:213
unsigned int
TMVA::VariableTransformBase::GetVariableTransform
Types::EVariableTransform GetVariableTransform() const
Definition: VariableTransformBase.h:146
TMVA::VariableTransformBase::fTMVAVersion
TMVAVersion_t fTMVAVersion
Definition: VariableTransformBase.h:218
TMVA::DataSetInfo::GetNTargets
UInt_t GetNTargets() const
Definition: DataSetInfo.h:128
TMVA::VariableTransformBase::fVariableTypesAreCounted
Bool_t fVariableTypesAreCounted
Definition: VariableTransformBase.h:208
TMVA::VariableTransformBase::fGet
VectorOfCharAndInt fGet
Definition: VariableTransformBase.h:189
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
Definition: MsgLogger.h:83
TMVA::VariableTransformBase::~VariableTransformBase
virtual ~VariableTransformBase(void)
Definition: VariableTransformBase.cxx:99
TMVA::VariableTransformBase::fNTargets
UInt_t fNTargets
Definition: VariableTransformBase.h:210
TMVA::VariableTransformBase::UpdateNorm
void UpdateNorm(Int_t ivar, Double_t x)
TODO --> adapt to variable,target,spectator selection update min and max of a given variable (target)...
Definition: VariableTransformBase.cxx:605
TMVA::VariableTransformBase::SelectInput
virtual void SelectInput(const TString &inputVariables, Bool_t putIntoVariables=kFALSE)
select the variables/targets/spectators which serve as input to the transformation
Definition: VariableTransformBase.cxx:110
TMVA::VariableTransformBase::SetEnabled
void SetEnabled(Bool_t e)
Definition: VariableTransformBase.h:117
TMVA::VariableTransformBase::CalcNorm
void CalcNorm(const std::vector< const Event * > &)
TODO --> adapt to variable,target,spectator selection method to calculate minimum,...
Definition: VariableTransformBase.cxx:470
TMVA::VariableTransformBase::fNSpectators
UInt_t fNSpectators
Definition: VariableTransformBase.h:211
TObject
Definition: TObject.h:37
TMVA::Event
Definition: Event.h:51
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::VariableTransformBase::fDsiOutput
DataSetInfo * fDsiOutput
Definition: VariableTransformBase.h:177
TMVA::VariableTransformBase::PrepareTransformation
virtual Bool_t PrepareTransformation(const std::vector< Event * > &)=0
TMVA::VariableTransformBase::InverseTransform
virtual const Event * InverseTransform(const Event *const, Int_t cls) const =0
TMVA::VariableTransformBase::fNVariables
UInt_t fNVariables
Definition: VariableTransformBase.h:209
TMVA::VariableTransformBase::fUseSignalTransform
Bool_t fUseSignalTransform
Definition: VariableTransformBase.h:198
TMVA::VariableTransformBase::ToggleInputSortOrder
void ToggleInputSortOrder(Bool_t sortOrder)
Definition: VariableTransformBase.h:129
TMVA::VariableTransformBase::fTransformedEvent
Event * fTransformedEvent
Definition: VariableTransformBase.h:185
TMVA::VariableTransformBase::fSpectators
std::vector< TMVA::VariableInfo > fSpectators
Definition: VariableTransformBase.h:206
TMVA::VariableTransformBase::GetNSpectators
UInt_t GetNSpectators() const
Definition: VariableTransformBase.h:174
TMVA::VariableTransformBase::fNVars
UInt_t fNVars
Definition: VariableTransformBase.h:202
TH1.h
TMVA::Types::EVariableTransform
EVariableTransform
Definition: Types.h:138
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int