|
64 | 64 | /// create variable transformations
|
65 | 65 |
|
66 | 66 | namespace TMVA {
|
67 |
| -void CreateVariableTransforms( const TString& trafoDefinitionIn, |
68 |
| - TMVA::DataSetInfo& dataInfo, |
69 |
| - TMVA::TransformationHandler& transformationHandler, |
70 |
| - TMVA::MsgLogger& log ) |
| 67 | +void CreateVariableTransforms(const TString& trafoDefinitionIn, |
| 68 | + TMVA::DataSetInfo& dataInfo, |
| 69 | + TMVA::TransformationHandler& transformationHandler, |
| 70 | + TMVA::MsgLogger& log) |
71 | 71 | {
|
72 |
| - TString trafoDefinition(trafoDefinitionIn); |
73 |
| - if (trafoDefinition == "None") return; // no transformations |
74 |
| - |
75 |
| - // workaround for transformations to complicated to be handled by makeclass |
76 |
| - // count number of transformations with incomplete set of variables |
77 |
| - TString trafoDefinitionCheck(trafoDefinitionIn); |
78 |
| - int npartial = 0, ntrafo=0; |
79 |
| - for (Int_t pos = 0, siz = trafoDefinition.Sizeof(); pos < siz; ++pos) { |
80 |
| - TString ch = trafoDefinition(pos,1); |
81 |
| - if ( ch == "(" ) npartial++; |
82 |
| - if ( ch == "+" || ch == ",") ntrafo++; |
83 |
| - } |
84 |
| - if (npartial>1) { |
85 |
| - log << kWARNING << "The use of multiple partial variable transformations during the application phase can be properly invoked via the \"Reader\", but it is not yet implemented in \"MakeClass\", the creation mechanism for standalone C++ application classes. The standalone C++ class produced by this training job is thus INCOMPLETE AND MUST NOT BE USED! The transformation in question is: " << trafoDefinitionIn << Endl; // ToDo make info and do not write the standalone class |
86 |
| - // |
87 |
| - // this does not work since this function is static |
88 |
| - // fDisableWriting=true; // disable creation of stand-alone class |
89 |
| - // ToDo we need to tell the transformation that it cannot write itself |
90 |
| - } |
91 |
| - // workaround end |
92 |
| - |
93 |
| - Int_t parenthesisCount = 0; |
94 |
| - for (Int_t position = 0, size = trafoDefinition.Sizeof(); position < size; ++position) { |
95 |
| - TString ch = trafoDefinition(position,1); |
96 |
| - if (ch == "(") ++parenthesisCount; |
97 |
| - else if (ch == ")") --parenthesisCount; |
98 |
| - else if (ch == "," && parenthesisCount == 0) trafoDefinition.Replace(position,1,'+'); |
99 |
| - } |
100 |
| - |
101 |
| - TList* trList = gTools().ParseFormatLine( trafoDefinition, "+" ); |
102 |
| - TListIter trIt(trList); |
103 |
| - while (TObjString* os = (TObjString*)trIt()) { |
104 |
| - TString tdef = os->GetString(); |
105 |
| - Int_t idxCls = -1; |
106 |
| - |
107 |
| - TString variables = ""; |
108 |
| - if (tdef.Contains("(")) { // contains selection of variables |
109 |
| - Ssiz_t parStart = tdef.Index( "(" ); |
110 |
| - Ssiz_t parLen = tdef.Index( ")", parStart )-parStart+1; |
111 |
| - |
112 |
| - variables = tdef(parStart,parLen); |
113 |
| - tdef.Remove(parStart,parLen); |
114 |
| - variables.Remove(parLen-1,1); |
115 |
| - variables.Remove(0,1); |
116 |
| - } |
117 |
| - |
118 |
| - TList* trClsList = gTools().ParseFormatLine( tdef, "_" ); // split entry to get trf-name and class-name |
119 |
| - TListIter trClsIt(trClsList); |
120 |
| - if (trClsList->GetSize() < 1) log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Incorrect transformation string provided." << Endl; |
121 |
| - const TString& trName = ((TObjString*)trClsList->At(0))->GetString(); |
122 |
| - |
123 |
| - if (trClsList->GetEntries() > 1) { |
124 |
| - TString trCls = "AllClasses"; |
125 |
| - ClassInfo *ci = NULL; |
126 |
| - trCls = ((TObjString*)trClsList->At(1))->GetString(); |
127 |
| - if (trCls != "AllClasses") { |
128 |
| - ci = dataInfo.GetClassInfo( trCls ); |
129 |
| - if (ci == NULL) |
130 |
| - log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Class " << trCls << " not known for variable transformation " |
131 |
| - << trName << ", please check." << Endl; |
132 |
| - else |
133 |
| - idxCls = ci->GetNumber(); |
134 |
| - } |
135 |
| - } |
136 |
| - |
137 |
| - VariableTransformBase* transformation = NULL; |
138 |
| - if (trName == "I" || trName == "Ident" || trName == "Identity") { |
139 |
| - if (variables.Length() == 0) variables = "_V_"; |
140 |
| - transformation = new VariableIdentityTransform( dataInfo); |
141 |
| - } |
142 |
| - else if (trName == "D" || trName == "Deco" || trName == "Decorrelate") { |
143 |
| - if (variables.Length() == 0) variables = "_V_"; |
144 |
| - transformation = new VariableDecorrTransform( dataInfo); |
145 |
| - } |
146 |
| - else if (trName == "P" || trName == "PCA") { |
147 |
| - if (variables.Length() == 0) variables = "_V_"; |
148 |
| - transformation = new VariablePCATransform ( dataInfo); |
149 |
| - } |
150 |
| - else if (trName == "U" || trName == "Uniform") { |
151 |
| - if (variables.Length() == 0) variables = "_V_,_T_"; |
152 |
| - transformation = new VariableGaussTransform ( dataInfo, "Uniform" ); |
153 |
| - } |
154 |
| - else if (trName == "G" || trName == "Gauss") { |
155 |
| - if (variables.Length() == 0) variables = "_V_"; |
156 |
| - transformation = new VariableGaussTransform ( dataInfo); |
157 |
| - } |
158 |
| - else if (trName == "N" || trName == "Norm" || trName == "Normalise" || trName == "Normalize") { |
159 |
| - if (variables.Length() == 0) variables = "_V_,_T_"; |
160 |
| - transformation = new VariableNormalizeTransform( dataInfo); |
161 |
| - } |
162 |
| - else log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "<ProcessOptions> Variable transform '" |
163 |
| - << trName << "' unknown." << Endl; |
164 |
| - |
165 |
| - |
166 |
| - if (transformation) { |
167 |
| - ClassInfo* clsInfo = dataInfo.GetClassInfo(idxCls); |
168 |
| - if (clsInfo ) |
169 |
| - log << kHEADER <<Form("[%s] : ",dataInfo.GetName()) |
170 |
| - << "Create Transformation \"" << trName << "\" with reference class " |
171 |
| - << clsInfo->GetName() << "=("<< idxCls <<")"<<Endl << Endl; |
172 |
| -else |
173 |
| - log << kHEADER <<Form("[%s] : ",dataInfo.GetName()) |
174 |
| - << "Create Transformation \"" << trName << "\" with events from all classes." << Endl << Endl; |
175 |
| - |
176 |
| - transformation->SelectInput( variables ); |
177 |
| - transformationHandler.AddTransformation(transformation, idxCls); |
178 |
| - } |
179 |
| - } |
180 |
| - return; |
| 72 | + TString trafoDefinition(trafoDefinitionIn); |
| 73 | + if (trafoDefinition == "None") return; // no transformations |
| 74 | + |
| 75 | + // workaround for transformations to complicated to be handled by makeclass |
| 76 | + // count number of transformations with incomplete set of variables |
| 77 | + TString trafoDefinitionCheck(trafoDefinitionIn); |
| 78 | + int npartial = 0, ntrafo = 0; |
| 79 | + for (Int_t pos = 0, siz = trafoDefinition.Sizeof(); pos < siz; ++pos) { |
| 80 | + TString ch = trafoDefinition(pos,1); |
| 81 | + if ( ch == "(" ) npartial++; |
| 82 | + if ( ch == "+" || ch == ",") ntrafo++; |
| 83 | + } |
| 84 | + if (npartial>1) { |
| 85 | + log << kWARNING |
| 86 | + << "The use of multiple partial variable transformations during the " |
| 87 | + "application phase can be properly invoked via the \"Reader\", but " |
| 88 | + "it is not yet implemented in \"MakeClass\", the creation mechanism " |
| 89 | + "for standalone C++ application classes. The standalone C++ class " |
| 90 | + "produced by this training job is thus INCOMPLETE AND MUST NOT BE USED! " |
| 91 | + "The transformation in question is: " << trafoDefinitionIn << Endl; |
| 92 | + // ToDo make info and do not write the standalone class |
| 93 | + // |
| 94 | + // this does not work since this function is static |
| 95 | + // fDisableWriting=true; // disable creation of stand-alone class |
| 96 | + // ToDo we need to tell the transformation that it cannot write itself |
| 97 | + } |
| 98 | + // workaround end |
| 99 | + |
| 100 | + Int_t parenthesisCount = 0; |
| 101 | + for (Int_t position = 0, size = trafoDefinition.Sizeof(); position < size; ++position) { |
| 102 | + TString ch = trafoDefinition(position,1); |
| 103 | + if (ch == "(") ++parenthesisCount; |
| 104 | + else if (ch == ")") --parenthesisCount; |
| 105 | + else if (ch == "," && parenthesisCount == 0) trafoDefinition.Replace(position,1,'+'); |
| 106 | + } |
| 107 | + |
| 108 | + TList* trList = gTools().ParseFormatLine( trafoDefinition, "+" ); |
| 109 | + TListIter trIt(trList); |
| 110 | + while (TObjString* os = (TObjString*)trIt()) { |
| 111 | + TString tdef = os->GetString(); |
| 112 | + Int_t idxCls = -1; |
| 113 | + |
| 114 | + TString variables = ""; |
| 115 | + if (tdef.Contains("(")) { // contains selection of variables |
| 116 | + Ssiz_t parStart = tdef.Index( "(" ); |
| 117 | + Ssiz_t parLen = tdef.Index( ")", parStart )-parStart+1; |
| 118 | + |
| 119 | + variables = tdef(parStart,parLen); |
| 120 | + tdef.Remove(parStart,parLen); |
| 121 | + variables.Remove(parLen-1,1); |
| 122 | + variables.Remove(0,1); |
| 123 | + } |
| 124 | + |
| 125 | + TList* trClsList = gTools().ParseFormatLine( tdef, "_" ); // split entry to get trf-name and class-name |
| 126 | + TListIter trClsIt(trClsList); |
| 127 | + if (trClsList->GetSize() < 1) |
| 128 | + log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Incorrect transformation string provided." << Endl; |
| 129 | + const TString& trName = ((TObjString*)trClsList->At(0))->GetString(); |
| 130 | + |
| 131 | + if (trClsList->GetEntries() > 1) { |
| 132 | + TString trCls = "AllClasses"; |
| 133 | + ClassInfo *ci = NULL; |
| 134 | + trCls = ((TObjString*)trClsList->At(1))->GetString(); |
| 135 | + if (trCls != "AllClasses") { |
| 136 | + ci = dataInfo.GetClassInfo( trCls ); |
| 137 | + if (ci == NULL) |
| 138 | + log << kFATAL <<Form("Dataset[%s] : ",dataInfo.GetName())<< "Class " << trCls << " not known for variable transformation " |
| 139 | + << trName << ", please check." << Endl; |
| 140 | + else |
| 141 | + idxCls = ci->GetNumber(); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + VariableTransformBase* transformation = NULL; |
| 146 | + if (trName == "I" || trName == "Ident" || trName == "Identity") { |
| 147 | + if (variables.Length() == 0) variables = "_V_"; |
| 148 | + transformation = new VariableIdentityTransform(dataInfo); |
| 149 | + } |
| 150 | + else if (trName == "D" || trName == "Deco" || trName == "Decorrelate") { |
| 151 | + if (variables.Length() == 0) variables = "_V_"; |
| 152 | + transformation = new VariableDecorrTransform(dataInfo); |
| 153 | + } |
| 154 | + else if (trName == "P" || trName == "PCA") { |
| 155 | + if (variables.Length() == 0) variables = "_V_"; |
| 156 | + transformation = new VariablePCATransform(dataInfo); |
| 157 | + } |
| 158 | + else if (trName == "U" || trName == "Uniform") { |
| 159 | + if (variables.Length() == 0) variables = "_V_,_T_"; |
| 160 | + transformation = new VariableGaussTransform(dataInfo, "Uniform" ); |
| 161 | + } |
| 162 | + else if (trName == "G" || trName == "Gauss") { |
| 163 | + if (variables.Length() == 0) variables = "_V_"; |
| 164 | + transformation = new VariableGaussTransform(dataInfo); |
| 165 | + } |
| 166 | + else if (trName == "N" || trName == "Norm" || trName == "Normalise" || trName == "Normalize") { |
| 167 | + if (variables.Length() == 0) variables = "_V_,_T_"; |
| 168 | + transformation = new VariableNormalizeTransform(dataInfo); |
| 169 | + } |
| 170 | + else |
| 171 | + log << kFATAL << Form("Dataset[%s] : ",dataInfo.GetName()) |
| 172 | + << "<ProcessOptions> Variable transform '" |
| 173 | + << trName << "' unknown." << Endl; |
| 174 | + |
| 175 | + |
| 176 | + if (transformation) { |
| 177 | + ClassInfo* clsInfo = dataInfo.GetClassInfo(idxCls); |
| 178 | + if (clsInfo) |
| 179 | + log << kHEADER << Form("[%s] : ",dataInfo.GetName()) |
| 180 | + << "Create Transformation \"" << trName << "\" with reference class " |
| 181 | + << clsInfo->GetName() << "=("<< idxCls <<")" << Endl << Endl; |
| 182 | + else |
| 183 | + log << kHEADER << Form("[%s] : ",dataInfo.GetName()) |
| 184 | + << "Create Transformation \"" << trName << "\" with events from all classes." |
| 185 | + << Endl << Endl; |
| 186 | + |
| 187 | + transformation->SelectInput(variables); |
| 188 | + transformationHandler.AddTransformation(transformation, idxCls); |
| 189 | + } |
| 190 | + } |
181 | 191 | }
|
182 | 192 |
|
183 | 193 | }
|
0 commit comments