123 {
125
127 auto base = std::string("TMVA@@MethodBase");
132 auto ctor2 = std::string(
"Method") +
specific_options.
m_method + std::string(
"(TString&,TString&,TMVA::DataSetInfo&,TString&)");
134
135 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
136 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
137 }
138
141 }
142
143 Weightfile weightfile;
144 std::string logfilename = weightfile.generateFileName(".log");
145
146
147
148
149
150 auto logfile = open(logfilename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
151 auto saved_stdout = dup(STDOUT_FILENO);
152 dup2(logfile, 1);
153
154 factory.TrainAllMethods();
155 factory.TestAllMethods();
156 factory.EvaluateAllMethods();
157
158
159 dup2(saved_stdout, STDOUT_FILENO);
160 close(saved_stdout);
161 close(logfile);
162
163
165 weightfile.addFile(
"TMVA_Weightfile", std::string(
"TMVA/weights/") + jobName +
"_" +
specific_options.
m_method +
".weights.xml");
166 weightfile.addFile("TMVA_Logfile", logfilename);
167
168
169 std::string begin = "Ranking input variables (method specific)";
170 std::string end = "-----------------------------------";
171 std::string line;
172 std::ifstream file(logfilename, std::ios::in);
173 std::map<std::string, float> feature_importances;
174 int state = 0;
175 while (std::getline(file, line)) {
176 if (state == 0 && line.find(begin) != std::string::npos) {
177 state = 1;
178 continue;
179 }
180 if (state >= 1 and state <= 4) {
181 state++;
182 continue;
183 }
184 if (state == 5) {
185 if (line.find(end) != std::string::npos)
186 break;
187 std::vector<std::string> strs;
188 boost::split(strs, line, boost::is_any_of(":"));
189 std::string variable = strs[2];
190 boost::trim(variable);
192 float importance = std::stof(strs[3]);
193 feature_importances[variable] = importance;
194 }
195 }
196 weightfile.addFeatureImportance(feature_importances);
197
198 return weightfile;
199
200 }
std::string m_prepareOption
Prepare options passed to prepareTrainingAndTestTree method.
std::string m_config
TMVA config string for the chosen method.
std::string m_method
tmva method name
std::string m_type
tmva method type
TMVAOptions specific_options
Method specific options.
GeneralOptions m_general_options
GeneralOptions containing all shared options.
static std::string invertMakeROOTCompatible(std::string str)
Invert makeROOTCompatible operation.