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 * *
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 * (see tmva/doc/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
41
42////////////////////////////////////////////////////////////////////////////////
43/// constructor
44
49
50////////////////////////////////////////////////////////////////////////////////
51
54
55////////////////////////////////////////////////////////////////////////////////
56/// initialization of the rearrangement transformation
57/// (nothing to do)
58
62
63////////////////////////////////////////////////////////////////////////////////
64/// prepare transformation --> (nothing to do)
65
67{
68 if (!IsEnabled() || IsCreated()) return kTRUE;
69
70 UInt_t nvars = 0, ntgts = 0, nspcts = 0;
71 CountVariableTypes( nvars, ntgts, nspcts );
72 if (ntgts>0) Log() << kFATAL << "Targets used in Rearrange-transformation." << Endl;
73
75 return kTRUE;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79
81{
82 if (!IsEnabled()) return ev;
83
84 // apply the normalization transformation
85 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
86
88
89 FloatVector input; // will be filled with the selected variables, (targets)
90 std::vector<Char_t> mask; // masked variables
91 GetInput( ev, input, mask );
92 SetOutput( fTransformedEvent, input, mask, ev );
93
94 return fTransformedEvent;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98
100{
101 if (!IsEnabled()) return ev;
102
103 // apply the inverse transformation
104 if (!IsCreated()) Log() << kFATAL << "Transformation not yet created" << Endl;
105
107
108 FloatVector input; // will be filled with the selected variables, targets, (spectators)
109 std::vector<Char_t> mask; // masked variables
110 GetInput( ev, input, mask, kTRUE );
111 SetOutput( fBackTransformedEvent, input, mask, ev, kTRUE );
112
114}
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// creates string with variable transformations applied
119
121{
122 const UInt_t size = fGet.size();
123 std::vector<TString>* strVec = new std::vector<TString>(size);
124
125 return strVec;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// create XML description of Rearrange transformation
130
132{
133 void* trfxml = gTools().AddChild(parent, "Transform");
134 gTools().AddAttr(trfxml, "Name", "Rearrange");
135
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Read the transformation matrices from the xml node
141
143{
144
145 void* inpnode = NULL;
146
147 inpnode = gTools().GetChild(trfnode, "Selection"); // new xml format
148 if(inpnode == NULL)
149 Log() << kFATAL << "Unknown weight file format for transformations. (tried to read in 'rearrange' transform)" << Endl;
150
152
153 SetCreated();
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// prints the transformation ranges
158
162
163////////////////////////////////////////////////////////////////////////////////
164/// creates a normalizing function
165
166void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
167 Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
168{
169}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
Class that contains all the data information.
Definition DataSetInfo.h:62
void * GetChild(void *parent, const char *childname=nullptr)
get child node
Definition Tools.cxx:1125
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
void * AddChild(void *parent, const char *childname, const char *content=nullptr, bool isRootNode=false)
add child node
Definition Tools.cxx:1099
Singleton class for Global types used by TMVA.
Definition Types.h:71
std::vector< TString > * GetTransformationStrings(Int_t cls) const override
creates string with variable transformations applied
void ReadFromXML(void *trfnode) override
Read the transformation matrices from the xml node.
void Initialize() override
initialization of the rearrangement transformation (nothing to do)
const Event * InverseTransform(const Event *const, Int_t cls) const override
void PrintTransformation(std::ostream &o) override
prints the transformation ranges
VariableRearrangeTransform(DataSetInfo &dsi)
constructor
void AttachXMLTo(void *parent) override
create XML description of Rearrange transformation
const Event * Transform(const Event *const, Int_t cls) const override
Bool_t PrepareTransformation(const std::vector< Event * > &) override
prepare transformation --> (nothing to do)
void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls) override
creates a normalizing function
virtual void SetOutput(Event *event, std::vector< Float_t > &output, std::vector< Char_t > &mask, const Event *oldEvent=nullptr, Bool_t backTransform=kFALSE) const
select the values from the event
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 ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
Event * fBackTransformedEvent
holds the current back-transformed event
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
Event * fTransformedEvent
holds the current transformed event
VariableTransformBase(DataSetInfo &dsi, Types::EVariableTransform tf, const TString &trfName)
standard constructor
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
VectorOfCharAndInt fGet
get variables/targets/spectators
Basic string class.
Definition TString.h:138
Tools & gTools()
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148