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
52namespace TMVA {
53
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
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; }
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
117
118 protected:
119
120 void CalcNorm( const std::vector<const Event*>& );
121
123 void SetNVariables( UInt_t i ) { fNVars = i; }
124 void SetName( const TString& c ) { fTransformName = c; }
125
127 UInt_t GetNTargets() const { return fDsi.GetNTargets(); }
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
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
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
#define c(i)
Definition: RSha256.hxx:101
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassDef(name, id)
Definition: Rtypes.h:325
Class that contains all the data information.
Definition: DataSetInfo.h:62
UInt_t GetNVariables() const
Definition: DataSetInfo.h:127
UInt_t GetNSpectators(bool all=kTRUE) const
UInt_t GetNClasses() const
Definition: DataSetInfo.h:155
UInt_t GetNTargets() const
Definition: DataSetInfo.h:128
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
EVariableTransform
Definition: Types.h:116
Linear interpolation class.
virtual void ReadTransformationFromStream(std::istream &istr, const TString &classname="")=0
void ToggleInputSortOrder(Bool_t sortOrder)
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)=0
getinput and setoutput equivalent
virtual const Event * Transform(const Event *const, Int_t cls) const =0
virtual const Event * InverseTransform(const Event *const, Int_t cls) const =0
virtual Bool_t PrepareTransformation(const std::vector< Event * > &)=0
std::vector< TMVA::VariableInfo > & Spectators()
virtual void WriteTransformationToStream(std::ostream &o) const =0
Types::EVariableTransform GetVariableTransform() const
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 Initialize()=0
std::vector< TMVA::VariableInfo > & Targets()
void CalcNorm(const std::vector< const Event * > &)
TODO --> adapt to variable,target,spectator selection method to calculate minimum,...
Types::EVariableTransform fVariableTransform
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
std::vector< std::pair< Char_t, UInt_t > > VectorOfCharAndInt
virtual const char * GetName() const
Returns name of object.
void SetName(const TString &c)
void SetOutputDataSetInfo(DataSetInfo *outputDsi)
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
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 SetUseSignalTransform(Bool_t e=kTRUE)
std::vector< TMVA::VariableInfo > & Variables()
const std::vector< TMVA::VariableInfo > & Targets() const
std::vector< TMVA::VariableInfo > fVariables
VariableTransformBase(DataSetInfo &dsi, Types::EVariableTransform tf, const TString &trfName)
standard constructor
void UpdateNorm(Int_t ivar, Double_t x)
TODO --> adapt to variable,target,spectator selection update min and max of a given variable (target)...
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
const std::vector< TMVA::VariableInfo > & Variables() const
virtual std::vector< TString > * GetTransformationStrings(Int_t cls) const
TODO --> adapt to variable,target,spectator selection default transformation output --> only indicate...
virtual void SelectInput(const TString &inputVariables, Bool_t putIntoVariables=kFALSE)
select the variables/targets/spectators which serve as input to the transformation
VectorOfCharAndInt::iterator ItVarTypeIdx
virtual void PrintTransformation(std::ostream &)
std::vector< TMVA::VariableInfo > fSpectators
std::vector< TMVA::VariableInfo > fTargets
const std::vector< TMVA::VariableInfo > & Spectators() const
VectorOfCharAndInt::const_iterator ItVarTypeIdxConst
void SetTMVAVersion(TMVAVersion_t v)
UInt_t TMVAVersion_t
Definition: Types.h:51
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
create variable transformations
auto * a
Definition: textangle.C:12
static void output(int code)
Definition: gifencode.c:226