Logo ROOT   6.14/05
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 #include "TH1.h"
43 #include "TDirectory.h"
44 #include "TString.h"
45 
46 #include "TMVA/Types.h"
47 #include "TMVA/Event.h"
48 #include "TMVA/VariableInfo.h"
49 #include "TMVA/DataSetInfo.h"
50 
51 namespace TMVA {
52 
53  class VariableTransformBase : public TObject {
54 
55  public:
56 
57  typedef std::vector<std::pair<Char_t,UInt_t> > VectorOfCharAndInt;
58  typedef VectorOfCharAndInt::iterator ItVarTypeIdx;
59  typedef VectorOfCharAndInt::const_iterator ItVarTypeIdxConst;
60 
62  virtual ~VariableTransformBase( void );
63 
64  virtual void Initialize() = 0;
65  virtual Bool_t PrepareTransformation (const std::vector<Event*>& ) = 0;
66  virtual const Event* Transform ( const Event* const, Int_t cls ) const = 0;
67  virtual const Event* InverseTransform( const Event* const, Int_t cls ) const = 0;
68 
69  // accessors
70  void SetEnabled ( Bool_t e ) { fEnabled = e; }
71  void SetNormalise( Bool_t n ) { fNormalise = n; }
72  Bool_t IsEnabled() const { return fEnabled; }
73  Bool_t IsCreated() const { return fCreated; }
74  Bool_t IsNormalised() const { return fNormalise; }
75 
76  // variable selection
77  virtual void SelectInput( const TString& inputVariables, Bool_t putIntoVariables = kFALSE );
78  virtual Bool_t GetInput ( const Event* event, std::vector<Float_t>& input, std::vector<Char_t>& mask, Bool_t backTransform = kFALSE ) const;
79  virtual void SetOutput( Event* event, std::vector<Float_t>& output, std::vector<Char_t>& mask, const Event* oldEvent = 0, Bool_t backTransform = kFALSE ) const;
80  virtual void CountVariableTypes( UInt_t& nvars, UInt_t& ntgts, UInt_t& nspcts ) const;
81 
82  void ToggleInputSortOrder( Bool_t sortOrder ) { fSortGet = sortOrder; }
83  void SetOutputDataSetInfo( DataSetInfo* outputDsi ) { fDsiOutput = outputDsi; }
84 
85 
86 
89 
90  virtual const char* GetName() const { return fTransformName.Data(); }
91  TString GetShortName() const { TString a(fTransformName); a.ReplaceAll("Transform",""); return a; }
92 
93  virtual void WriteTransformationToStream ( std::ostream& o ) const = 0;
94  virtual void ReadTransformationFromStream( std::istream& istr, const TString& classname="" ) = 0;
95 
96  virtual void AttachXMLTo(void* parent) = 0;
97  virtual void ReadFromXML( void* trfnode ) = 0;
98 
100 
101  // writer of function code
102  virtual void MakeFunction( std::ostream& fout, const TString& fncName, Int_t part,
103  UInt_t trCounter, Int_t cls ) = 0;
104 
105  // provides string vector giving explicit transformation
106  virtual std::vector<TString>* GetTransformationStrings( Int_t cls ) const;
107  virtual void PrintTransformation( std::ostream & ) {}
108 
109  const std::vector<TMVA::VariableInfo>& Variables() const { return fVariables; }
110  const std::vector<TMVA::VariableInfo>& Targets() const { return fTargets; }
111  const std::vector<TMVA::VariableInfo>& Spectators() const { return fSpectators; }
112 
113  MsgLogger& Log() const { return *fLogger; }
114 
115  void SetTMVAVersion(TMVAVersion_t v) { fTMVAVersion = v; }
116 
117  protected:
118 
119  void CalcNorm( const std::vector<const Event*>& );
120 
121  void SetCreated( Bool_t c = kTRUE ) { fCreated = c; }
122  void SetNVariables( UInt_t i ) { fNVars = i; }
123  void SetName( const TString& c ) { fTransformName = c; }
124 
125  UInt_t GetNVariables() const { return fDsi.GetNVariables(); }
126  UInt_t GetNTargets() const { return fDsi.GetNTargets(); }
127  UInt_t GetNSpectators() const { return fDsi.GetNSpectators(); }
128 
131 
132  std::vector<TMVA::VariableInfo>& Variables() { return fVariables; }
133  std::vector<TMVA::VariableInfo>& Targets() { return fTargets; }
134  std::vector<TMVA::VariableInfo>& Spectators() { return fSpectators; }
135  Int_t GetNClasses() const { return fDsi.GetNClasses(); }
136 
137 
138  mutable Event* fTransformedEvent; // holds the current transformed event
139  mutable Event* fBackTransformedEvent; // holds the current back-transformed event
140 
141  // variable selection
142  VectorOfCharAndInt fGet; // get variables/targets/spectators
143  VectorOfCharAndInt fPut; // put variables/targets/spectators
144 
145  private:
146 
147  Types::EVariableTransform fVariableTransform; // Decorrelation, PCA, etc.
148 
149  void UpdateNorm( Int_t ivar, Double_t x );
150 
151  Bool_t fUseSignalTransform; // true if transformation bases on signal data
152  Bool_t fEnabled; // has been enabled
153  Bool_t fCreated; // has been created
154  Bool_t fNormalise; // normalise input variables
155  UInt_t fNVars; // number of variables
156  TString fTransformName; // name of transformation
157  std::vector<TMVA::VariableInfo> fVariables; // event variables [saved to weight file]
158  std::vector<TMVA::VariableInfo> fTargets; // event targets [saved to weight file --> TODO ]
159  std::vector<TMVA::VariableInfo> fSpectators; // event spectators [saved to weight file --> TODO ]
160 
161  mutable Bool_t fVariableTypesAreCounted; // true if variable types have been counted already
162  mutable UInt_t fNVariables; // number of variables to be transformed
163  mutable UInt_t fNTargets; // number of targets to be transformed
164  mutable UInt_t fNSpectators; // number of spectators to be transformed
165 
166  Bool_t fSortGet; // if true, sort the variables into the order as defined by the user at the var definition
167  // if false, sort the variables according to the order given for the var transformation
168 
169  protected:
170 
171  TMVAVersion_t fTMVAVersion;
172 
173  mutable MsgLogger* fLogger; //! message logger
174 
175  ClassDef(VariableTransformBase,0); // Base class for variable transformations
176  };
177 
178 } // namespace TMVA
179 
180 #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:110
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
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
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:131
std::vector< std::pair< Char_t, UInt_t > > VectorOfCharAndInt
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
UInt_t GetNClasses() const
Definition: DataSetInfo.h:136
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:320
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
Class that contains all the data information.
Definition: DataSetInfo.h:60
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
UInt_t GetNTargets() const
Definition: DataSetInfo.h:111
Linear interpolation class.
VectorOfCharAndInt::const_iterator ItVarTypeIdxConst
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
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
const Bool_t kFALSE
Definition: RtypesCore.h:88
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
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
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:115
#define c(i)
Definition: RSha256.hxx:101
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: RtypesCore.h:87
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:364