MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / ToIfElse

Method ToIfElse

python-package/compile/src/io/tree.cpp:361–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361std::string Tree::ToIfElse(int index, bool predict_leaf_index) const {
362 std::stringstream str_buf;
363 str_buf << "double PredictTree" << index;
364 if (predict_leaf_index) {
365 str_buf << "Leaf";
366 }
367 str_buf << "(const double* arr) { ";
368 if (num_leaves_ <= 1) {
369 str_buf << "return " << leaf_value_[0] << ";";
370 } else {
371 str_buf << "const std::vector<uint32_t> cat_threshold = {";
372 for (size_t i = 0; i < cat_threshold_.size(); ++i) {
373 if (i != 0) {
374 str_buf << ",";
375 }
376 str_buf << cat_threshold_[i];
377 }
378 str_buf << "};";
379 // use this for the missing value conversion
380 str_buf << "double fval = 0.0f; ";
381 if (num_cat_ > 0) {
382 str_buf << "int int_fval = 0; ";
383 }
384 str_buf << NodeToIfElse(0, predict_leaf_index);
385 }
386 str_buf << " }" << '\n';
387
388 // Predict func by Map to ifelse
389 str_buf << "double PredictTree" << index;
390 if (predict_leaf_index) {
391 str_buf << "LeafByMap";
392 } else {
393 str_buf << "ByMap";
394 }
395 str_buf << "(const std::unordered_map<int, double>& arr) { ";
396 if (num_leaves_ <= 1) {
397 str_buf << "return " << leaf_value_[0] << ";";
398 } else {
399 str_buf << "const std::vector<uint32_t> cat_threshold = {";
400 for (size_t i = 0; i < cat_threshold_.size(); ++i) {
401 if (i != 0) {
402 str_buf << ",";
403 }
404 str_buf << cat_threshold_[i];
405 }
406 str_buf << "};";
407 // use this for the missing value conversion
408 str_buf << "double fval = 0.0f; ";
409 if (num_cat_ > 0) {
410 str_buf << "int int_fval = 0; ";
411 }
412 str_buf << NodeToIfElseByMap(0, predict_leaf_index);
413 }
414 str_buf << " }" << '\n';
415
416 return str_buf.str();
417}
418

Callers 1

ModelToIfElseMethod · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected