Logo ROOT  
Reference Guide
VariableRearrangeTransform.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Peter Speckmayer
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : VariableRearrangeTransform *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
15 * *
16 * Copyright (c) 2005: *
17 * CERN, Switzerland *
18 * MPI-K Heidelberg, Germany *
19 * *
20 * Redistribution and use in source and binary forms, with or without *
21 * modification, are permitted according to the terms listed in LICENSE *
22 * (http://tmva.sourceforge.net/LICENSE) *
23 **********************************************************************************/
24
25/*! \class TMVA::VariableRearrangeTransform
26\ingroup TMVA
27Rearrangement of input variables
28*/
29
31
32#include "TMVA/DataSet.h"
33#include "TMVA/Event.h"
34#include "TMVA/MsgLogger.h"
35#include "TMVA/Tools.h"
36#include "TMVA/Types.h"
37
38#include <iostream>
39#include <iomanip>
40#include <stdexcept>
41
43
44////////////////////////////////////////////////////////////////////////////////
45/// constructor
46
48: VariableTransformBase( dsi, Types::kRearranged, "Rearrange" )
49{
50}
51
52////////////////////////////////////////////////////////////////////////////////
53
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// initialization of the rearrangement transformation
59/// (nothing to do)
60
62{
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// prepare transformation --> (nothing to do)
67
69{
70 if (!IsEnabled() || IsCreated()) return kTRUE;
71
72 UInt_t nvars = 0, ntgts = 0, nspcts = 0;
73 CountVariableTypes( nvars, ntgts, nspcts );
74 if (ntgts>0) Log() << kFATAL << "Targets used in Rearrange-transformation." << Endl;
75
76 SetCreated( kTRUE );
77 return kTRUE;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81
83{
84 if (!IsEnabled()) return ev;
85
86 // apply the normalization transformation
87 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
88
89 if (fTransformedEvent==0) fTransformedEvent = new Event();
90
91 FloatVector input; // will be filled with the selected variables, (targets)
92 std::vector<Char_t> mask; // masked variables
93 GetInput( ev, input, mask );
94 SetOutput( fTransformedEvent, input, mask, ev );
95
96 return fTransformedEvent;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100
102{
103 if (!IsEnabled()) return ev;
104
105 // apply the inverse transformation
106 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
107
108 if (fBackTransformedEvent==0) fBackTransformedEvent = new Event( *ev );
109
110 FloatVector input; // will be filled with the selected variables, targets, (spectators)
111 std::vector<Char_t> mask; // masked variables
112 GetInput( ev, input, mask, kTRUE );
113 SetOutput( fBackTransformedEvent, input, mask, ev, kTRUE );
114
115 return fBackTransformedEvent;
116}
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// creates string with variable transformations applied
121
123{
124 const UInt_t size = fGet.size();
125 std::vector<TString>* strVec = new std::vector<TString>(size);
126
127 return strVec;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// create XML description of Rearrange transformation
132
134{
135 void* trfxml = gTools().AddChild(parent, "Transform");
136 gTools().AddAttr(trfxml, "Name", "Rearrange");
137
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Read the transformation matrices from the xml node
143
145{
146
147 void* inpnode = NULL;
148
149 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
150 if(inpnode == NULL)
151 Log() << kFATAL << "Unknown weight file format for transformations. (tried to read in 'rearrange' transform)" << Endl;
152
154
155 SetCreated();
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// prints the transformation ranges
160
162{
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// creates a normalizing function
167
168void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
169 Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
170{
171}
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
Class that contains all the data information.
Definition: DataSetInfo.h:60
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition: Tools.cxx:1136
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1162
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition: Tools.h:355
Singleton class for Global types used by TMVA.
Definition: Types.h:73
Rearrangement of input variables.
virtual void ReadFromXML(void *trfnode)
Read the transformation matrices from the xml node.
virtual void AttachXMLTo(void *parent)
create XML description of Rearrange transformation
virtual const Event * Transform(const Event *const, Int_t cls) const
virtual void PrintTransformation(std::ostream &o)
prints the transformation ranges
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)
creates a normalizing function
virtual const Event * InverseTransform(const Event *const, Int_t cls) const
VariableRearrangeTransform(DataSetInfo &dsi)
constructor
Bool_t PrepareTransformation(const std::vector< Event * > &)
prepare transformation --> (nothing to do)
std::vector< TString > * GetTransformationStrings(Int_t cls) const
creates string with variable transformations applied
void Initialize()
initialization of the rearrangement transformation (nothing to do)
Linear interpolation class.
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
Basic string class.
Definition: TString.h:131
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Double_t Log(Double_t x)
Definition: TMath.h:750