18
18
19
19
#include < TMVA/RBDT.hxx>
20
20
21
- #include < TFile.h>
22
21
#include < ROOT/RSpan.hxx>
22
+ #include < ROOT/StringUtils.hxx>
23
+
24
+ #include < TFile.h>
25
+ #include < TSystem.h>
23
26
24
27
#include < cmath>
25
28
#include < fstream>
@@ -127,35 +130,14 @@ inline NumericAfterSubstrOutput<NumericType> numericAfterSubstr(std::string cons
127
130
return output;
128
131
}
129
132
130
- std::vector<std::string> split (std::string const &strToSplit, char delimeter)
131
- {
132
- std::stringstream ss (strToSplit);
133
- std::string item;
134
- std::vector<std::string> splittedStrings;
135
- while (std::getline (ss, item, delimeter)) {
136
- splittedStrings.push_back (item);
137
- }
138
- return splittedStrings;
139
- }
140
-
141
- bool exists (std::string const &filename)
142
- {
143
- if (FILE *file = fopen (filename.c_str (), " r" )) {
144
- fclose (file);
145
- return true ;
146
- } else {
147
- return false ;
148
- }
149
- }
150
-
151
133
} // namespace util
152
134
153
135
} // namespace
154
136
155
- using namespace TMVA ::Experimental;
137
+ using TMVA::Experimental::RTensor ;
156
138
157
139
// / Compute model prediction on input RTensor
158
- RTensor<TMVA::Experimental::RBDT::Value_t> TMVA::Experimental::RBDT::Compute (RTensor<Value_t> const &x)
140
+ RTensor<TMVA::Experimental::RBDT::Value_t> TMVA::Experimental::RBDT::Compute (RTensor<Value_t> const &x) const
159
141
{
160
142
std::size_t nOut = baseResponses_.size () > 2 ? baseResponses_.size () : 1 ;
161
143
const std::size_t rows = x.GetShape ()[0 ];
@@ -167,15 +149,15 @@ RTensor<TMVA::Experimental::RBDT::Value_t> TMVA::Experimental::RBDT::Compute(RTe
167
149
for (std::size_t iCol = 0 ; iCol < cols; ++iCol) {
168
150
xRow[iCol] = x ({iRow, iCol});
169
151
}
170
- compute (xRow.data (), yRow.data ());
152
+ ComputeImpl (xRow.data (), yRow.data ());
171
153
for (std::size_t iOut = 0 ; iOut < nOut; ++iOut) {
172
154
y ({iRow, iOut}) = yRow[iOut];
173
155
}
174
156
}
175
157
return y;
176
158
}
177
159
178
- void TMVA::Experimental::RBDT::softmax (const Value_t *array, Value_t *out) const
160
+ void TMVA::Experimental::RBDT::Softmax (const Value_t *array, Value_t *out) const
179
161
{
180
162
std::size_t nOut = baseResponses_.size () > 2 ? baseResponses_.size () : 1 ;
181
163
if (nOut == 1 ) {
@@ -202,20 +184,20 @@ void TMVA::Experimental::RBDT::softmax(const Value_t *array, Value_t *out) const
202
184
detail::softmaxTransformInplace (out, nOut);
203
185
}
204
186
205
- void TMVA::Experimental::RBDT::compute (const Value_t *array, Value_t *out) const
187
+ void TMVA::Experimental::RBDT::ComputeImpl (const Value_t *array, Value_t *out) const
206
188
{
207
189
std::size_t nOut = baseResponses_.size () > 2 ? baseResponses_.size () : 1 ;
208
190
if (nOut > 1 ) {
209
- softmax (array, out);
191
+ Softmax (array, out);
210
192
} else {
211
- out[0 ] = evaluateBinary (array);
193
+ out[0 ] = EvaluateBinary (array);
212
194
if (logistic_) {
213
195
out[0 ] = 1.0 / (1.0 + std::exp (-out[0 ]));
214
196
}
215
197
}
216
198
}
217
199
218
- TMVA::Experimental::RBDT::Value_t TMVA::Experimental::RBDT::evaluateBinary (const Value_t *array) const
200
+ TMVA::Experimental::RBDT::Value_t TMVA::Experimental::RBDT::EvaluateBinary (const Value_t *array) const
219
201
{
220
202
Value_t out = baseScore_ + baseResponses_[0 ];
221
203
@@ -260,19 +242,21 @@ void terminateTree(TMVA::Experimental::RBDT &ff, int &nPreviousNodes, int &nPrev
260
242
261
243
} // namespace
262
244
263
- RBDT TMVA::Experimental::RBDT::load_txt (std::string const &txtpath, std::vector<std::string> &features, int nClasses)
245
+ TMVA::Experimental::RBDT
246
+ TMVA::Experimental::RBDT::LoadText (std::string const &txtpath, std::vector<std::string> &features, int nClasses)
264
247
{
265
248
const std::string info = " constructing RBDT from " + txtpath + " : " ;
266
249
267
- if (! util::exists (txtpath)) {
250
+ if (gSystem -> AccessPathName (txtpath. c_str () )) {
268
251
throw std::runtime_error (info + " file does not exists" );
269
252
}
270
253
271
254
std::ifstream file (txtpath.c_str ());
272
- return load_txt (file, features, nClasses);
255
+ return LoadText (file, features, nClasses);
273
256
}
274
257
275
- RBDT TMVA::Experimental::RBDT::load_txt (std::istream &file, std::vector<std::string> &features, int nClasses)
258
+ TMVA::Experimental::RBDT
259
+ TMVA::Experimental::RBDT::LoadText (std::istream &file, std::vector<std::string> &features, int nClasses)
276
260
{
277
261
const std::string info = " constructing RBDT from istream: " ;
278
262
@@ -314,7 +298,7 @@ RBDT TMVA::Experimental::RBDT::load_txt(std::istream &file, std::vector<std::str
314
298
ss >> index;
315
299
line = ss.str ();
316
300
317
- std::vector<std::string> splitstring = util::split (subline, ' < ' );
301
+ std::vector<std::string> splitstring = ROOT::Split (subline, " < " );
318
302
std::string const &varName = splitstring[0 ];
319
303
Value_t cutValue;
320
304
{
0 commit comments