MCPcopy Create free account
hub / github.com/catboost/catboost / OutputLeafValues

Function OutputLeafValues

catboost/libs/model/model_export/export_helpers.cpp:45–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 }
44
45 TString OutputLeafValues(const TFullModel& model, TIndent indent, EModelType modelType) {
46 char bracketStart, bracketEnd;
47 switch (modelType) {
48 case EModelType::Cpp:
49 bracketStart = '{';
50 bracketEnd = '}';
51 break;
52 case EModelType::Python:
53 bracketStart = '[';
54 bracketEnd = ']';
55 break;
56 default:
57 CB_ENSURE(false, "Can not export to this format");
58 }
59
60 TStringBuilder outString;
61 TSequenceCommaSeparator commaOuter(model.ModelTrees->GetModelTreeData()->GetTreeSizes().size());
62 ++indent;
63 auto currentTreeFirstLeafPtr = model.ModelTrees->GetModelTreeData()->GetLeafValues().data();
64 for (const auto& treeSize : model.ModelTrees->GetModelTreeData()->GetTreeSizes()) {
65 const auto treeLeafCount = 1uLL << treeSize;
66 const auto dim = model.ModelTrees->GetDimensionsCount();
67 outString << '\n' << indent;
68 outString << OutputArrayInitializer([&currentTreeFirstLeafPtr, &dim, &bracketStart, &bracketEnd] (size_t i) {
69 return bracketStart + OutputArrayInitializer([&currentTreeFirstLeafPtr, &dim, &i] (size_t j) {
70 return FloatToString(currentTreeFirstLeafPtr[i * dim + j], PREC_NDIGITS, 16);
71 }, dim) + bracketEnd;
72 }, treeLeafCount);
73 outString << commaOuter;
74 currentTreeFirstLeafPtr += treeLeafCount * dim;
75 }
76 --indent;
77 outString << '\n';
78 return outString;
79 }
80}

Callers 2

WriteModelCatFeaturesMethod · 0.85
WriteModelMethod · 0.85

Calls 7

OutputArrayInitializerFunction · 0.85
GetTreeSizesMethod · 0.80
FloatToStringFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
GetLeafValuesMethod · 0.45
GetDimensionsCountMethod · 0.45

Tested by

no test coverage detected