Logo ROOT   6.08/07
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 
42 #ifndef ROOT_TH1
43 #include "TH1.h"
44 #endif
45 #ifndef ROOT_TDirectory
46 #include "TDirectory.h"
47 #endif
48 #ifndef ROOT_TString
49 #include "TString.h"
50 #endif
51 
52 #ifndef ROOT_TMVA_Types
53 #include "TMVA/Types.h"
54 #endif
55 #ifndef ROOT_TMVA_Event
56 #include "TMVA/Event.h"
57 #endif
58 #ifndef ROOT_TMVA_VariableInfo
59 #include "TMVA/VariableInfo.h"
60 #endif
61 #ifndef ROOT_TMVA_DataSetInfo
62 #include "TMVA/DataSetInfo.h"
63 #endif
64 
65 namespace TMVA {
66 
67  class VariableTransformBase : public TObject {
68 
69  public:
70 
71  typedef std::vector<std::pair<Char_t,UInt_t> > VectorOfCharAndInt;
72  typedef VectorOfCharAndInt::iterator ItVarTypeIdx;
73  typedef VectorOfCharAndInt::const_iterator ItVarTypeIdxConst;
74 
76  virtual ~VariableTransformBase( void );
77 
78  virtual void Initialize() = 0;
79  virtual Bool_t PrepareTransformation (const std::vector<Event*>& ) = 0;
80  virtual const Event* Transform ( const Event* const, Int_t cls ) const = 0;
81  virtual const Event* InverseTransform( const Event* const, Int_t cls ) const = 0;
82 
83  // accessors
84  void SetEnabled ( Bool_t e ) { fEnabled = e; }
85  void SetNormalise( Bool_t n ) { fNormalise = n; }
86  Bool_t IsEnabled() const { return fEnabled; }
87  Bool_t IsCreated() const { return fCreated; }
88  Bool_t IsNormalised() const { return fNormalise; }
89 
90  // variable selection
91  virtual void SelectInput( const TString& inputVariables, Bool_t putIntoVariables = kFALSE );
92  virtual Bool_t GetInput ( const Event* event, std::vector<Float_t>& input, std::vector<Char_t>& mask, Bool_t backTransform = kFALSE ) const;
93  virtual void SetOutput( Event* event, std::vector<Float_t>& output, std::vector<Char_t>& mask, const Event* oldEvent = 0, Bool_t backTransform = kFALSE ) const;
94  virtual void CountVariableTypes( UInt_t& nvars, UInt_t& ntgts, UInt_t& nspcts ) const;
95 
96  void ToggleInputSortOrder( Bool_t sortOrder ) { fSortGet = sortOrder; }
97  void SetOutputDataSetInfo( DataSetInfo* outputDsi ) { fDsiOutput = outputDsi; }
98 
99 
100 
103 
104  virtual const char* GetName() const { return fTransformName.Data(); }
105  TString GetShortName() const { TString a(fTransformName); a.ReplaceAll("Transform",""); return a; }
106 
107  virtual void WriteTransformationToStream ( std::ostream& o ) const = 0;
108  virtual void ReadTransformationFromStream( std::istream& istr, const TString& classname="" ) = 0;
109 
110  virtual void AttachXMLTo(void* parent) = 0;
111  virtual void ReadFromXML( void* trfnode ) = 0;
112 
114 
115  // writer of function code
116  virtual void MakeFunction( std::ostream& fout, const TString& fncName, Int_t part,
117  UInt_t trCounter, Int_t cls ) = 0;
118 
119  // provides string vector giving explicit transformation
120  virtual std::vector<TString>* GetTransformationStrings( Int_t cls ) const;
121  virtual void PrintTransformation( std::ostream & ) {}
122 
123  const std::vector<TMVA::VariableInfo>& Variables() const { return fVariables; }
124  const std::vector<TMVA::VariableInfo>& Targets() const { return fTargets; }
125  const std::vector<TMVA::VariableInfo>& Spectators() const { return fSpectators; }
126 
127  MsgLogger& Log() const { return *fLogger; }
128 
130 
131  protected:
132 
133  void CalcNorm( const std::vector<const Event*>& );
134 
135  void SetCreated( Bool_t c = kTRUE ) { fCreated = c; }
136  void SetNVariables( UInt_t i ) { fNVars = i; }
137  void SetName( const TString& c ) { fTransformName = c; }
138 
139  UInt_t GetNVariables() const { return fDsi.GetNVariables(); }
140  UInt_t GetNTargets() const { return fDsi.GetNTargets(); }
141  UInt_t GetNSpectators() const { return fDsi.GetNSpectators(); }
142 
145 
146  std::vector<TMVA::VariableInfo>& Variables() { return fVariables; }
147  std::vector<TMVA::VariableInfo>& Targets() { return fTargets; }
148  std::vector<TMVA::VariableInfo>& Spectators() { return fSpectators; }
149  Int_t GetNClasses() const { return fDsi.GetNClasses(); }
150 
151 
152  mutable Event* fTransformedEvent; // holds the current transformed event
153  mutable Event* fBackTransformedEvent; // holds the current back-transformed event
154 
155  // variable selection
156  VectorOfCharAndInt fGet; // get variables/targets/spectators
157  VectorOfCharAndInt fPut; // put variables/targets/spectators
158 
159  private:
160 
161  Types::EVariableTransform fVariableTransform; // Decorrelation, PCA, etc.
162 
163  void UpdateNorm( Int_t ivar, Double_t x );
164 
165  Bool_t fUseSignalTransform; // true if transformation bases on signal data
166  Bool_t fEnabled; // has been enabled
167  Bool_t fCreated; // has been created
168  Bool_t fNormalise; // normalise input variables
169  UInt_t fNVars; // number of variables
170  TString fTransformName; // name of transformation
171  std::vector<TMVA::VariableInfo> fVariables; // event variables [saved to weight file]
172  std::vector<TMVA::VariableInfo> fTargets; // event targets [saved to weight file --> TODO ]
173  std::vector<TMVA::VariableInfo> fSpectators; // event spectators [saved to weight file --> TODO ]
174 
175  mutable Bool_t fVariableTypesAreCounted; // true if variable types have been counted already
176  mutable UInt_t fNVariables; // number of variables to be transformed
177  mutable UInt_t fNTargets; // number of targets to be transformed
178  mutable UInt_t fNSpectators; // number of spectators to be transformed
179 
180  Bool_t fSortGet; // if true, sort the variables into the order as defined by the user at the var definition
181  // if false, sort the variables according to the order given for the var transformation
182 
183  protected:
184 
186 
187  mutable MsgLogger* fLogger; //! message logger
188 
189  ClassDef(VariableTransformBase,0); // Base class for variable transformations
190  };
191 
192 } // namespace TMVA
193 
194 #endif
std::vector< TMVA::VariableInfo > fTargets
virtual const Event * InverseTransform(const Event *const, Int_t cls) const =0
void SetTMVAVersion(TMVAVersion_t v)
UInt_t GetNVariables() const
Definition: DataSetInfo.h:128
return c
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
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 CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
UInt_t TMVAVersion_t
Definition: Types.h:55
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
std::vector< TMVA::VariableInfo > fVariables
Basic string class.
Definition: TString.h:137
std::vector< std::pair< Char_t, UInt_t > > VectorOfCharAndInt
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
UInt_t GetNClasses() const
Definition: DataSetInfo.h:154
Types::EVariableTransform fVariableTransform
virtual const char * GetName() const
Returns name of object.
const std::vector< TMVA::VariableInfo > & Targets() const
const std::vector< TMVA::VariableInfo > & Variables() const
void CalcNorm(const std::vector< const Event *> &)
TODO –> adapt to variable,target,spectator selection method to calculate minimum, maximum, mean, and RMS for all variables used in the MVA.
void SetOutputDataSetInfo(DataSetInfo *outputDsi)
const std::vector< TMVA::VariableInfo > & Spectators() const
std::vector< TMVA::VariableInfo > & Targets()
virtual std::vector< TString > * GetTransformationStrings(Int_t cls) const
TODO –> adapt to variable,target,spectator selection default transformation output –> only indicate...
void SetUseSignalTransform(Bool_t e=kTRUE)
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
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
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
VectorOfCharAndInt::iterator ItVarTypeIdx
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
UInt_t GetNTargets() const
Definition: DataSetInfo.h:129
VectorOfCharAndInt::const_iterator ItVarTypeIdxConst
SVector< double, 2 > v
Definition: Dict.h:5
virtual void ReadTransformationFromStream(std::istream &istr, const TString &classname="")=0
unsigned int UInt_t
Definition: RtypesCore.h:42
UInt_t GetNSpectators(bool all=kTRUE) const
void UpdateNorm(Int_t ivar, Double_t x)
TODO –> adapt to variable,target,spectator selection update min and max of a given variable (target)...
Types::EVariableTransform GetVariableTransform() const
virtual void PrintTransformation(std::ostream &)
VariableTransformBase(DataSetInfo &dsi, Types::EVariableTransform tf, const TString &trfName)
standard constructor
void SetName(const TString &c)
double Double_t
Definition: RtypesCore.h:55
std::vector< TMVA::VariableInfo > & Spectators()
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Mother of all ROOT objects.
Definition: TObject.h:37
std::vector< TMVA::VariableInfo > fSpectators
void ToggleInputSortOrder(Bool_t sortOrder)
Abstract ClassifierFactory template that handles arbitrary types.
virtual Bool_t PrepareTransformation(const std::vector< Event *> &)=0
virtual void Initialize()=0
EVariableTransform
Definition: Types.h:117
virtual void SelectInput(const TString &inputVariables, Bool_t putIntoVariables=kFALSE)
select the variables/targets/spectators which serve as input to the transformation ...
virtual const Event * Transform(const Event *const, Int_t cls) const =0
const Bool_t kTRUE
Definition: Rtypes.h:91
std::vector< TMVA::VariableInfo > & Variables()
const Int_t n
Definition: legend1.C:16
virtual void WriteTransformationToStream(std::ostream &o) const =0
const char * Data() const
Definition: TString.h:349