Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <stdexcept>
40
42
43////////////////////////////////////////////////////////////////////////////////
44/// constructor
45
47: VariableTransformBase( dsi, Types::kRearranged, "Rearrange" )
48{
49}
50
51////////////////////////////////////////////////////////////////////////////////
52
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// initialization of the rearrangement transformation
58/// (nothing to do)
59
61{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// prepare transformation --> (nothing to do)
66
68{
69 if (!IsEnabled() || IsCreated()) return kTRUE;
70
71 UInt_t nvars = 0, ntgts = 0, nspcts = 0;
72 CountVariableTypes( nvars, ntgts, nspcts );
73 if (ntgts>0) Log() << kFATAL << "Targets used in Rearrange-transformation." << Endl;
74
75 SetCreated( kTRUE );
76 return kTRUE;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80
82{
83 if (!IsEnabled()) return ev;
84
85 // apply the normalization transformation
86 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
87
88 if (fTransformedEvent==0) fTransformedEvent = new Event();
89
90 FloatVector input; // will be filled with the selected variables, (targets)
91 std::vector<Char_t> mask; // masked variables
92 GetInput( ev, input, mask );
93 SetOutput( fTransformedEvent, input, mask, ev );
94
95 return fTransformedEvent;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
101{
102 if (!IsEnabled()) return ev;
103
104 // apply the inverse transformation
105 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
106
107 if (fBackTransformedEvent==0) fBackTransformedEvent = new Event( *ev );
108
109 FloatVector input; // will be filled with the selected variables, targets, (spectators)
110 std::vector<Char_t> mask; // masked variables
111 GetInput( ev, input, mask, kTRUE );
112 SetOutput( fBackTransformedEvent, input, mask, ev, kTRUE );
113
114 return fBackTransformedEvent;
115}
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// creates string with variable transformations applied
120
122{
123 const UInt_t size = fGet.size();
124 std::vector<TString>* strVec = new std::vector<TString>(size);
125
126 return strVec;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// create XML description of Rearrange transformation
131
133{
134 void* trfxml = gTools().AddChild(parent, "Transform");
135 gTools().AddAttr(trfxml, "Name", "Rearrange");
136
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Read the transformation matrices from the xml node
142
144{
145
146 void* inpnode = NULL;
147
148 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
149 if(inpnode == NULL)
150 Log() << kFATAL << "Unknown weight file format for transformations. (tried to read in 'rearrange' transform)" << Endl;
151
153
154 SetCreated();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// prints the transformation ranges
159
161{
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// creates a normalizing function
166
167void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
168 Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
169{
170}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
Class that contains all the data information.
Definition DataSetInfo.h:62
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition Tools.cxx:1124
void * GetChild(void *parent, const char *childname=0)
get child node
Definition Tools.cxx:1150
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
Singleton class for Global types used by TMVA.
Definition Types.h:71
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:136
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148