Logo ROOT   6.12/07
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
27 Rearrangement 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 
68 Bool_t TMVA::VariableRearrangeTransform::PrepareTransformation (const std::vector<Event*>& /*events*/)
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 
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 
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 
168 void TMVA::VariableRearrangeTransform::MakeFunction( std::ostream& /*fout*/, const TString& /*fcncName*/,
169  Int_t /*part*/, UInt_t /*trCounter*/, Int_t )
170 {
171 }
Rearrangement of input variables.
void Initialize()
initialization of the rearrangement transformation (nothing to do)
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Singleton class for Global types used by TMVA.
Definition: Types.h:73
virtual void MakeFunction(std::ostream &fout, const TString &fncName, Int_t part, UInt_t trCounter, Int_t cls)
creates a normalizing function
virtual void CountVariableTypes(UInt_t &nvars, UInt_t &ntgts, UInt_t &nspcts) const
count variables, targets and spectators
virtual void AttachXMLTo(void *parent)=0
create XML description the transformation (write out info of selected variables)
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition: Tools.h:308
virtual const Event * InverseTransform(const Event *const, Int_t cls) const
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition: Tools.cxx:1135
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 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
virtual void PrintTransformation(std::ostream &o)
prints the transformation ranges
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1161
virtual const Event * Transform(const Event *const, Int_t cls) const
Class that contains all the data information.
Definition: DataSetInfo.h:60
virtual void ReadFromXML(void *trfnode)=0
Read the input variables from the XML node.
Linear interpolation class.
virtual void ReadFromXML(void *trfnode)
Read the transformation matrices from the xml node.
std::vector< TString > * GetTransformationStrings(Int_t cls) const
creates string with variable transformations applied
unsigned int UInt_t
Definition: RtypesCore.h:42
Tools & gTools()
#define ClassImp(name)
Definition: Rtypes.h:359
VariableRearrangeTransform(DataSetInfo &dsi)
constructor
Bool_t PrepareTransformation(const std::vector< Event *> &)
prepare transformation –> (nothing to do)
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void AttachXMLTo(void *parent)
create XML description of Rearrange transformation