Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
VariableInfo.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : VariableInfo *
8 * *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
17 * *
18 * Copyright (c) 2005: *
19 * CERN, Switzerland *
20 * U. of Victoria, Canada *
21 * MPI-K Heidelberg, Germany *
22 * LAPP, Annecy, France *
23 * *
24 * Redistribution and use in source and binary forms, with or without *
25 * modification, are permitted according to the terms listed in LICENSE *
26 * (http://mva.sourceforge.net/license.txt) *
27 **********************************************************************************/
28
29/*! \class TMVA::VariableInfo
30\ingroup TMVA
31Class for type info of MVA input variable
32*/
33
34#include "TMVA/VariableInfo.h"
35#include "TMVA/DataSetInfo.h"
36
37#include "TMVA/Tools.h"
38
39#include "TMath.h"
40#include "TNamed.h"
41
42#include <iomanip>
43#include <sstream>
44
45////////////////////////////////////////////////////////////////////////////////
46/// constructor
47
48TMVA::VariableInfo::VariableInfo( const TString& expression, const TString& title, const TString& unit,
49 Int_t varCounter,
50 char varType, void* external,
51 Double_t min, Double_t max, Bool_t normalized )
52 : TNamed(title.Data(),title.Data()),
53 fExpression ( expression ),
54 fUnit ( unit ),
55 fVarType ( varType ),
56 fXmeanNorm ( 0 ),
57 fXrmsNorm ( 0 ),
58 fXvarianceNorm( 0 ),
59 fNormalized ( normalized ),
60 fExternalData ( external ),
61 fVarCounter ( varCounter )
62{
63 if ( TMath::Abs(max - min) <= FLT_MIN ) {
64 fXminNorm = FLT_MAX;
65 fXmaxNorm = -FLT_MAX;
66 }
67 else {
68 fXminNorm = min;
69 fXmaxNorm = max;
70 }
71 // if a label is set, than retrieve the label and the
72 if (expression.Contains(":=")) {
73 Ssiz_t index = expression.Index(":=");
74 fExpression = expression(index+2,expression.Sizeof()-index-2);
75 fLabel = expression(0,index);
76 fLabel = fLabel.ReplaceAll(" ","");
77 }
78 else fLabel = GetExpression();
79
80 if (fTitle == "") fTitle = fLabel;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// default constructor
86
88 : TNamed(),
89 fExpression (""),
90 fVarType ('\0'),
91 fXmeanNorm ( 0 ),
92 fXrmsNorm ( 0 ),
93 fXvarianceNorm( 0 ),
94 fNormalized ( kFALSE ),
95 fExternalData ( 0 ),
96 fVarCounter ( 0 )
97{
98 fXminNorm = 1e30;
99 fXmaxNorm = -1e30;
101 fTitle = fLabel;
102 fName = fTitle;
103 fUnit = "";
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// copy constructor
109
111 : TNamed(other),
112 fExpression ( other.fExpression ),
113 fInternalName ( other.fInternalName ),
114 fLabel ( other.fLabel ),
115 fUnit ( other.fUnit ),
116 fVarType ( other.fVarType ),
117 fXminNorm ( other.fXminNorm ),
118 fXmaxNorm ( other.fXmaxNorm ),
119 fXmeanNorm ( other.fXmeanNorm ),
120 fXrmsNorm ( other.fXrmsNorm ),
121 fXvarianceNorm( other.fXvarianceNorm ),
122 fNormalized ( other.fNormalized ),
123 fExternalData ( other.fExternalData ),
124 fVarCounter ( other.fVarCounter )
125{
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// comparison operator
130
132{
133 if (this !=& rhs) {
134 fExpression = rhs.fExpression;
135 fInternalName = rhs.fInternalName;
136 fVarType = rhs.fVarType;
137 fXminNorm = rhs.fXminNorm;
138 fXmaxNorm = rhs.fXmaxNorm;
139 fTitle = rhs.fTitle;
140 fName = rhs.fName;
141 }
142 return *this;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// write VariableInfo to stream
147
148void TMVA::VariableInfo::WriteToStream( std::ostream& o ) const
149{
150 UInt_t nc = TMath::Max( 30, TMath::Max( GetExpression().Length()+1, GetInternalName().Length()+1 ) );
151 TString expBr = TString::Format("\'%s\'",GetExpression().Data());
152 o << std::setw(nc) << GetExpression();
153 o << std::setw(nc) << GetInternalName();
154 o << std::setw(nc) << GetLabel();
155 o << std::setw(nc) << GetTitle();
156 o << std::setw(nc) << GetUnit();
157 o << " \'" << fVarType << "\' ";
158 o << "[" << std::setprecision(12) << GetMin() << "," << std::setprecision(12) << GetMax() << "]" << std::endl;
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// read VariableInfo from stream
163
164void TMVA::VariableInfo::ReadFromStream( std::istream& istr )
165{
166 // PLEASE do not modify this, it does not have to correspond to WriteToStream
167 // this is needed to stay like this in 397 for backward compatibility
168 TString exp, varname, vartype, minmax, minstr, maxstr;
169 istr >> exp >> varname >> vartype >> minmax;
170 exp.Strip(TString::kBoth, '\'');
171 minmax = minmax.Strip(TString::kLeading, '[');
172 minmax = minmax.Strip(TString::kTrailing, ']');
173 minstr = minmax(0,minmax.First(','));
174 maxstr = minmax(1+minmax.First(','),minmax.Length());
175 Double_t min, max;
176 std::stringstream strmin(minstr.Data());
177 std::stringstream strmax(maxstr.Data());
178 strmin >> min;
179 strmax >> max;
180 SetExpression ( exp );
181 SetInternalVarName( varname );
182 SetLabel ( varname );
183 SetTitle ( varname );
184 SetUnit ( "" );
185 SetVarType ( vartype[1] );
186 SetMin ( min );
187 SetMax ( max );
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// write class to XML
192
193void TMVA::VariableInfo::AddToXML( void* varnode )
194{
195 gTools().AddAttr( varnode, "Expression", GetExpression() );
196 gTools().AddAttr( varnode, "Label", GetLabel() );
197 gTools().AddAttr( varnode, "Title", GetTitle() );
198 gTools().AddAttr( varnode, "Unit", GetUnit() );
199 gTools().AddAttr( varnode, "Internal", GetInternalName() );
200
201 TString typeStr(" ");
202 typeStr[0] = GetVarType();
203 // in case of array variables, add "[]" to the type string: e.g. F[]
205 typeStr += "[]";
206 gTools().AddAttr(varnode, "Type", typeStr);
207 gTools().AddAttr( varnode, "Min", gTools().StringFromDouble(GetMin()) );
208 gTools().AddAttr( varnode, "Max", gTools().StringFromDouble(GetMax()) );
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// read VariableInfo from stream
213
215{
217 gTools().ReadAttr( varnode, "Expression", fExpression );
218 gTools().ReadAttr( varnode, "Label", fLabel );
219 gTools().ReadAttr( varnode, "Title", fTitle );
220 gTools().ReadAttr( varnode, "Unit", fUnit );
221 gTools().ReadAttr( varnode, "Internal", fInternalName );
222 gTools().ReadAttr( varnode, "Type", type );
223 gTools().ReadAttr( varnode, "Min", fXminNorm );
224 gTools().ReadAttr( varnode, "Max", fXmaxNorm );
225
226 SetVarType(type[0]);
227 // detect variables from array
228 if (type.Contains("[]"))
230}
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TString ReplaceRegularExpressions(const TString &s, const TString &replace="+")
replace regular expressions helper function to remove all occurrences "$!%^&()'<>?...
Definition Tools.cxx:798
void ReadAttr(void *node, const char *, T &value)
read attribute from xml
Definition Tools.h:329
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
add attribute to xml
Definition Tools.h:347
Class for type info of MVA input variable.
void ReadFromXML(void *varnode)
read VariableInfo from stream
VariableInfo & operator=(const TMVA::VariableInfo &rhs)
comparison operator
Double_t fXminNorm
minimum value for correlated/decorrelated/PCA variable
const TString & GetExpression() const
Double_t fXmaxNorm
maximum value for correlated/decorrelated/PCA variable
VariableInfo()
default constructor
void ReadFromStream(std::istream &istr)
read VariableInfo from stream
void AddToXML(void *varnode)
write class to XML
TString fLabel
variable label, set by "mylabel := var1 + var2", this is a shortcut
Char_t fVarType
the variable type to be used internally ('F'-default or 'I')
TString fUnit
unit for axis labels in plots; set by third string in AddVariable
TString fInternalName
internal variable name (needs to be regular expression)
TString fExpression
original variable expression (can be a formula)
void WriteToStream(std::ostream &o) const
write VariableInfo to stream
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1163
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
@ kLeading
Definition TString.h:276
@ kTrailing
Definition TString.h:276
@ kBoth
Definition TString.h:276
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
Definition TString.cxx:1401
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
Tools & gTools()
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123