Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
42 ClassImp(TMVA::VariableRearrangeTransform);
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// constructor
46 
47 TMVA::VariableRearrangeTransform::VariableRearrangeTransform( DataSetInfo& dsi )
48 : VariableTransformBase( dsi, Types::kRearranged, "Rearrange" )
49 {
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 TMVA::VariableRearrangeTransform::~VariableRearrangeTransform() {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// initialization of the rearrangement transformation
59 /// (nothing to do)
60 
61 void TMVA::VariableRearrangeTransform::Initialize()
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 
82 const TMVA::Event* TMVA::VariableRearrangeTransform::Transform( const TMVA::Event* const ev, Int_t /*cls*/ ) const
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 
101 const TMVA::Event* TMVA::VariableRearrangeTransform::InverseTransform( const TMVA::Event* const ev, Int_t /*cls*/ ) const
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 
122 std::vector<TString>* TMVA::VariableRearrangeTransform::GetTransformationStrings( Int_t /*cls*/ ) const
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 
133 void TMVA::VariableRearrangeTransform::AttachXMLTo(void* parent)
134 {
135  void* trfxml = gTools().AddChild(parent, "Transform");
136  gTools().AddAttr(trfxml, "Name", "Rearrange");
137 
138  VariableTransformBase::AttachXMLTo( trfxml );
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Read the transformation matrices from the xml node
143 
144 void TMVA::VariableRearrangeTransform::ReadFromXML( void* trfnode )
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 
153  VariableTransformBase::ReadFromXML( inpnode );
154 
155  SetCreated();
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// prints the transformation ranges
160 
161 void TMVA::VariableRearrangeTransform::PrintTransformation( std::ostream& )
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 }