Logo ROOT  
Reference Guide
TransformationHandler.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag, Eckhard von Toerne
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TransformationHandler *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Contains all the data information *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
19  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
20  * *
21  * Copyright (c) 2005-2011: *
22  * CERN, Switzerland *
23  * MPI-K Heidelberg, Germany *
24  * U. of Bonn, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://tmva.sourceforge.net/LICENSE) *
29  **********************************************************************************/
30 
31 #ifndef ROOT_TMVA_TransformationHandler
32 #define ROOT_TMVA_TransformationHandler
33 
34 //////////////////////////////////////////////////////////////////////////
35 // //
36 // TransformationHandler //
37 // //
38 // Class that contains all the data information //
39 // //
40 //////////////////////////////////////////////////////////////////////////
41 
42 #include "TList.h"
43 #include "TString.h"
44 #include <vector>
45 
46 #include "TMVA/DataSetInfo.h"
47 
48 namespace TMVA {
49 
50  class Event;
51  class DataSet;
52  class Ranking;
53  class VariableTransformBase;
54  class MsgLogger;
55 
56  class TransformationHandler {
57  public:
58 
59  struct VariableStat {
61  Double_t fRMS;
62  Double_t fMin;
63  Double_t fMax;
64  };
65 
66  TransformationHandler( DataSetInfo&, const TString& callerName );
68 
69  TString GetName() const;
70  TString GetVariableAxisTitle( const VariableInfo& info ) const;
71 
72  const Event* Transform(const Event*) const;
73  const Event* InverseTransform(const Event*, Bool_t suppressIfNoTargets=true ) const;
74 
75  // overrides the reference classes of all added transformations. Handle with care!!!
77 
78  VariableTransformBase* AddTransformation(VariableTransformBase*, Int_t cls );
79  const TList& GetTransformationList() const { return fTransformations; }
81  const std::vector<Event*>* CalcTransformations( const std::vector<Event*>&, Bool_t createNewVector = kFALSE );
82 
83  void CalcStats( const std::vector<Event*>& events );
84  void AddStats ( Int_t k, UInt_t ivar, Double_t mean, Double_t rms, Double_t min, Double_t max );
85  Double_t GetMean ( Int_t ivar, Int_t cls = -1 ) const;
86  Double_t GetRMS ( Int_t ivar, Int_t cls = -1 ) const;
87  Double_t GetMin ( Int_t ivar, Int_t cls = -1 ) const;
88  Double_t GetMax ( Int_t ivar, Int_t cls = -1 ) const;
89 
90  void WriteToStream ( std::ostream& o ) const;
91  void AddXMLTo ( void* parent=0 ) const;
92  void ReadFromStream( std::istream& istr );
93  void ReadFromXML ( void* trfsnode );
94 
95  // writer of function code
96  void MakeFunction(std::ostream& fout, const TString& fncName, Int_t part) const;
97 
98  // variable ranking
99  void PrintVariableRanking() const;
100 
101  // provides string vector giving explicit transformation (only last transform at present -> later show full chain)
102  std::vector<TString>* GetTransformationStringsOfLastTransform() const;
103  const char* GetNameOfLastTransform() const;
104 
105  // modify caller name for output
106  void SetCallerName( const TString& name );
107  const TString& GetCallerName() const { return fCallerName; }
108 
109  // setting file dir for histograms
110  TDirectory* GetRootDir() const { return fRootBaseDir; }
111  void SetRootDir( TDirectory *d ) { fRootBaseDir = d; }
112 
113  void PlotVariables( const std::vector<Event*>& events, TDirectory* theDirectory = 0 );
114 
115  private:
116 
117  // std::vector<TMVA::Event*>* TransformCollection( VariableTransformBase* trf,
118  // Int_t cls,
119  // std::vector<TMVA::Event*>* events,
120  // Bool_t replace ) const;
121 
122  const TMVA::VariableInfo& Variable(UInt_t ivar) const { return fDataSetInfo.GetVariableInfos().at(ivar); }
123  const TMVA::VariableInfo& Target (UInt_t itgt) const { return fDataSetInfo.GetTargetInfos()[itgt]; }
124 
125  DataSet* Data() { return fDataSetInfo.GetDataSet(); }
126 
127  DataSetInfo& fDataSetInfo; // pointer to the datasetinfo
128  TList fTransformations; //! list of transformations
129  std::vector< Int_t > fTransformationsReferenceClasses; //! reference classes for the transformations
130  std::vector<std::vector<TMVA::TransformationHandler::VariableStat> > fVariableStats; // first the variables, then the targets
131 
132  Int_t fNumC; // number of categories (#classes +1)
133 
134  std::vector<Ranking*> fRanking; //! ranking object
135  TDirectory* fRootBaseDir; //! if set put input var hists
136  TString fCallerName; //! name of the caller for output
137  mutable MsgLogger* fLogger; //! message logger
138  MsgLogger& Log() const { return *fLogger; }
139  };
140 }
141 
142 #endif
TMVA::TransformationHandler::fRanking
std::vector< Ranking * > fRanking
Definition: TransformationHandler.h:159
TMVA::TransformationHandler::TransformationHandler
TransformationHandler(DataSetInfo &, const TString &callerName)
constructor
Definition: TransformationHandler.cxx:69
TMVA::TransformationHandler::Target
const TMVA::VariableInfo & Target(UInt_t itgt) const
Definition: TransformationHandler.h:148
TMVA::TransformationHandler::CalcTransformations
const std::vector< Event * > * CalcTransformations(const std::vector< Event * > &, Bool_t createNewVector=kFALSE)
computation of transformation
Definition: TransformationHandler.cxx:211
TMVA::TransformationHandler::GetCallerName
const TString & GetCallerName() const
Definition: TransformationHandler.h:132
TMVA::TransformationHandler::fNumC
Int_t fNumC
Definition: TransformationHandler.h:157
TMVA::TransformationHandler::fVariableStats
std::vector< std::vector< TMVA::TransformationHandler::VariableStat > > fVariableStats
reference classes for the transformations
Definition: TransformationHandler.h:155
DataSetInfo.h
TMVA::DataSetInfo::GetDataSet
DataSet * GetDataSet() const
returns data set
Definition: DataSetInfo.cxx:480
TMVA::TransformationHandler::Data
DataSet * Data()
Definition: TransformationHandler.h:150
TMVA::TransformationHandler::AddXMLTo
void AddXMLTo(void *parent=0) const
XML node describing the transformation.
Definition: TransformationHandler.cxx:862
TMVA::TransformationHandler::Transform
const Event * Transform(const Event *) const
the transformation
Definition: TransformationHandler.cxx:152
Int_t
int Int_t
Definition: RtypesCore.h:45
TMVA::TransformationHandler::ReadFromStream
void ReadFromStream(std::istream &istr)
Definition: TransformationHandler.cxx:873
TMVA::TransformationHandler::fRootBaseDir
TDirectory * fRootBaseDir
ranking object
Definition: TransformationHandler.h:160
TList.h
TMVA::TransformationHandler::fTransformationsReferenceClasses
std::vector< Int_t > fTransformationsReferenceClasses
list of transformations
Definition: TransformationHandler.h:154
TMVA::TransformationHandler::SetCallerName
void SetCallerName(const TString &name)
Definition: TransformationHandler.cxx:97
TMVA::TransformationHandler::GetTransformationList
const TList & GetTransformationList() const
Definition: TransformationHandler.h:104
TMVA::TransformationHandler::GetMean
Double_t GetMean(Int_t ivar, Int_t cls=-1) const
Definition: TransformationHandler.cxx:934
TMVA::TransformationHandler::fTransformations
TList fTransformations
Definition: TransformationHandler.h:153
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMVA::TransformationHandler::PlotVariables
void PlotVariables(const std::vector< Event * > &events, TDirectory *theDirectory=0)
create histograms from the input variables
Definition: TransformationHandler.cxx:459
TMVA::TransformationHandler::GetVariableAxisTitle
TString GetVariableAxisTitle(const VariableInfo &info) const
incorporates transformation type into title axis (usually for histograms)
Definition: TransformationHandler.cxx:440
TMVA::TransformationHandler::GetRootDir
TDirectory * GetRootDir() const
Definition: TransformationHandler.h:135
TString.h
bool
TMVA::TransformationHandler::SetTransformationReferenceClass
void SetTransformationReferenceClass(Int_t cls)
overrides the setting for all classes! (this is put in basically for the likelihood-method) be carefu...
Definition: TransformationHandler.cxx:142
TMVA::TransformationHandler::InverseTransform
const Event * InverseTransform(const Event *, Bool_t suppressIfNoTargets=true) const
Definition: TransformationHandler.cxx:167
TMVA::TransformationHandler::VariableStat::fMax
Double_t fMax
Definition: TransformationHandler.h:88
TMVA::DataSetInfo::GetTargetInfos
std::vector< VariableInfo > & GetTargetInfos()
Definition: DataSetInfo.h:114
TMVA::TransformationHandler::CalcStats
void CalcStats(const std::vector< Event * > &events)
method to calculate minimum, maximum, mean, and RMS for all variables used in the MVA
Definition: TransformationHandler.cxx:257
TMVA::TransformationHandler::WriteToStream
void WriteToStream(std::ostream &o) const
write transformation to stream
Definition: TransformationHandler.cxx:837
TMVA::TransformationHandler::fCallerName
TString fCallerName
if set put input var hists
Definition: TransformationHandler.h:161
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::VariableInfo
Definition: VariableInfo.h:70
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TMVA::TransformationHandler::Log
MsgLogger & Log() const
message logger
Definition: TransformationHandler.h:163
TMVA::TransformationHandler::AddStats
void AddStats(Int_t k, UInt_t ivar, Double_t mean, Double_t rms, Double_t min, Double_t max)
Caches calculated summary statistics of transformed variables.
Definition: TransformationHandler.cxx:124
TMVA::TransformationHandler::~TransformationHandler
~TransformationHandler()
destructor
Definition: TransformationHandler.cxx:86
TMVA::TransformationHandler::GetName
TString GetName() const
return transformation name
Definition: TransformationHandler.cxx:425
unsigned int
TMVA::TransformationHandler::GetNameOfLastTransform
const char * GetNameOfLastTransform() const
returns string for transformation
Definition: TransformationHandler.cxx:827
TMVA::TransformationHandler::ReadFromXML
void ReadFromXML(void *trfsnode)
Definition: TransformationHandler.cxx:881
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
Definition: MsgLogger.h:83
TMVA::DataSetInfo::GetVariableInfos
std::vector< VariableInfo > & GetVariableInfos()
Definition: DataSetInfo.h:103
TMVA::TransformationHandler::MakeFunction
void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part) const
create transformation function
Definition: TransformationHandler.cxx:388
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TMVA::TransformationHandler::GetMin
Double_t GetMin(Int_t ivar, Int_t cls=-1) const
Definition: TransformationHandler.cxx:972
TMVA::TransformationHandler::fLogger
MsgLogger * fLogger
name of the caller for output
Definition: TransformationHandler.h:162
TMVA::TransformationHandler::VariableStat::fMin
Double_t fMin
Definition: TransformationHandler.h:87
name
char name[80]
Definition: TGX11.cxx:110
TMVA::TransformationHandler::GetRMS
Double_t GetRMS(Int_t ivar, Int_t cls=-1) const
Definition: TransformationHandler.cxx:953
d
#define d(i)
Definition: RSha256.hxx:120
TDirectory
Definition: TDirectory.h:40
TMVA::TransformationHandler::Variable
const TMVA::VariableInfo & Variable(UInt_t ivar) const
Definition: TransformationHandler.h:147
TMVA::TransformationHandler::VariableStat::fMean
Double_t fMean
Definition: TransformationHandler.h:85
TMVA::TransformationHandler::AddTransformation
VariableTransformBase * AddTransformation(VariableTransformBase *, Int_t cls)
Definition: TransformationHandler.cxx:105
TMVA::TransformationHandler::fDataSetInfo
DataSetInfo & fDataSetInfo
Definition: TransformationHandler.h:152
TMVA::TransformationHandler::GetTransformationStringsOfLastTransform
std::vector< TString > * GetTransformationStringsOfLastTransform() const
returns string for transformation
Definition: TransformationHandler.cxx:817
TMVA::TransformationHandler::GetMax
Double_t GetMax(Int_t ivar, Int_t cls=-1) const
Definition: TransformationHandler.cxx:991
TMVA::TransformationHandler::PrintVariableRanking
void PrintVariableRanking() const
prints ranking of input variables
Definition: TransformationHandler.cxx:924
TMVA::TransformationHandler::VariableStat::fRMS
Double_t fRMS
Definition: TransformationHandler.h:86
TMVA::TransformationHandler::GetNumOfTransformations
Int_t GetNumOfTransformations() const
Definition: TransformationHandler.h:105
TList
Definition: TList.h:44
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int
TMVA::TransformationHandler::SetRootDir
void SetRootDir(TDirectory *d)
Definition: TransformationHandler.h:136