Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
VariableTransform.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Omar Zapata
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : VariableTransformBase *
8 * *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18 * *
19 * Copyright (c) 2005: *
20 * CERN, Switzerland *
21 * MPI-K Heidelberg, Germany *
22 * *
23 * Redistribution and use in source and binary forms, with or without *
24 * modification, are permitted according to the terms listed in LICENSE *
25 * (see tmva/doc/LICENSE) *
26 **********************************************************************************/
27
31#include "TMVA/VariableInfo.h"
35
36#include "TMVA/Config.h"
37#include "TMVA/DataSetInfo.h"
38#include "TMVA/MsgLogger.h"
39#include "TMVA/Ranking.h"
40#include "TMVA/Tools.h"
41#include "TMVA/Types.h"
42#include "TMVA/Version.h"
44
45#include "THashTable.h"
46#include "TList.h"
47#include "TObjString.h"
48
49#include <algorithm>
50#include <cassert>
51#include <exception>
52#include <stdexcept>
53#include <set>
54
55////////////////////////////////////////////////////////////////////////////////
56/// create variable transformations
57
58namespace TMVA {
62 TMVA::MsgLogger& log)
63{
65 if (trafoDefinition == "None") return; // no transformations
66
67 // workaround for transformations to complicated to be handled by makeclass
68 // count number of transformations with incomplete set of variables
70 int npartial = 0;
71 for (Int_t pos = 0, siz = trafoDefinition.Sizeof(); pos < siz; ++pos) {
72 TString ch = trafoDefinition(pos,1);
73 if ( ch == "(" ) npartial++;
74 }
75 if (npartial>1) {
76 log << kWARNING
77 << "The use of multiple partial variable transformations during the "
78 "application phase can be properly invoked via the \"Reader\", but "
79 "it is not yet implemented in \"MakeClass\", the creation mechanism "
80 "for standalone C++ application classes. The standalone C++ class "
81 "produced by this training job is thus INCOMPLETE AND MUST NOT BE USED! "
82 "The transformation in question is: " << trafoDefinitionIn << Endl;
83 // ToDo make info and do not write the standalone class
84 //
85 // this does not work since this function is static
86 // fDisableWriting=true; // disable creation of stand-alone class
87 // ToDo we need to tell the transformation that it cannot write itself
88 }
89 // workaround end
90
92 for (Int_t position = 0, size = trafoDefinition.Sizeof(); position < size; ++position) {
93 TString ch = trafoDefinition(position,1);
94 if (ch == "(") ++parenthesisCount;
95 else if (ch == ")") --parenthesisCount;
96 else if (ch == "," && parenthesisCount == 0) trafoDefinition.Replace(position,1,'+');
97 }
98
101 while (TObjString* os = (TObjString*)trIt()) {
102 TString tdef = os->GetString();
103 Int_t idxCls = -1;
104
105 TString variables = "";
106 if (tdef.Contains("(")) { // contains selection of variables
107 Ssiz_t parStart = tdef.Index( "(" );
108 Ssiz_t parLen = tdef.Index( ")", parStart )-parStart+1;
109
111 tdef.Remove(parStart,parLen);
112 variables.Remove(parLen-1,1);
113 variables.Remove(0,1);
114 }
115
116 TList* trClsList = gTools().ParseFormatLine( tdef, "_" ); // split entry to get trf-name and class-name
118 if (trClsList->GetSize() < 1)
119 log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Incorrect transformation string provided." << Endl;
120 const TString& trName = ((TObjString*)trClsList->At(0))->GetString();
121
122 if (trClsList->GetEntries() > 1) {
123 TString trCls = "AllClasses";
124 ClassInfo *ci = NULL;
125 trCls = ((TObjString*)trClsList->At(1))->GetString();
126 if (trCls != "AllClasses") {
127 ci = dataInfo.GetClassInfo( trCls );
128 if (ci == NULL)
129 log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Class " << trCls << " not known for variable transformation "
130 << trName << ", please check." << Endl;
131 else
132 idxCls = ci->GetNumber();
133 }
134 }
135
137 if (trName == "I" || trName == "Ident" || trName == "Identity") {
138 if (variables.Length() == 0) variables = "_V_";
140 }
141 else if (trName == "D" || trName == "Deco" || trName == "Decorrelate") {
142 if (variables.Length() == 0) variables = "_V_";
144 }
145 else if (trName == "P" || trName == "PCA") {
146 if (variables.Length() == 0) variables = "_V_";
148 }
149 else if (trName == "U" || trName == "Uniform") {
150 if (variables.Length() == 0) variables = "_V_,_T_";
152 }
153 else if (trName == "G" || trName == "Gauss") {
154 if (variables.Length() == 0) variables = "_V_";
156 }
157 else if (trName == "N" || trName == "Norm" || trName == "Normalise" || trName == "Normalize") {
158 if (variables.Length() == 0) variables = "_V_,_T_";
160 }
161 else
162 log << kFATAL << Form("Dataset[%s] : ",dataInfo.GetName())
163 << "<ProcessOptions> Variable transform '"
164 << trName << "' unknown." << Endl;
165
166
167 if (transformation) {
168 ClassInfo* clsInfo = dataInfo.GetClassInfo(idxCls);
169 if (clsInfo)
170 log << kHEADER << Form("[%s] : ",dataInfo.GetName())
171 << "Create Transformation \"" << trName << "\" with reference class "
172 << clsInfo->GetName() << "=("<< idxCls <<")" << Endl << Endl;
173 else
174 log << kHEADER << Form("[%s] : ",dataInfo.GetName())
175 << "Create Transformation \"" << trName << "\" with events from all classes."
176 << Endl << Endl;
177
178 transformation->SelectInput(variables);
179 transformationHandler.AddTransformation(transformation, idxCls);
180 }
181 }
182}
183
184}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
Iterator of linked list.
Definition TList.h:193
A doubly linked list.
Definition TList.h:38
Class that contains all the information of a class.
Definition ClassInfo.h:49
Class that contains all the data information.
Definition DataSetInfo.h:62
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
TList * ParseFormatLine(TString theString, const char *sep=":")
Parse the string and cut into labels separated by ":".
Definition Tools.cxx:401
Class that contains all the data information.
Linear interpolation class.
Gaussian Transformation of input variables.
Linear interpolation class.
Linear interpolation class.
Collectable string class.
Definition TObjString.h:28
Basic string class.
Definition TString.h:139
create variable transformations
Tools & gTools()
void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148