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

Method TruncateTrees

catboost/libs/model/model.cpp:280–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280void TModelTrees::TruncateTrees(size_t begin, size_t end) {
281 //TODO(eermishkina): support non symmetric trees
282 CB_ENSURE(IsOblivious(), "Truncate support only symmetric trees");
283 CB_ENSURE(begin <= end, "begin tree index should be not greater than end tree index.");
284 CB_ENSURE(end <= GetModelTreeData()->GetTreeSplits().size(), "end tree index should be not greater than tree count.");
285 auto savedScaleAndBias = GetScaleAndBias();
286 TObliviousTreeBuilder builder(FloatFeatures,
287 CatFeatures,
288 TextFeatures,
289 EmbeddingFeatures,
290 ApproxDimension);
291 auto applyData = GetApplyData();
292 const auto& leafOffsets = applyData->TreeFirstLeafOffsets;
293
294 const auto treeSizes = GetModelTreeData()->GetTreeSizes();
295 const auto treeSplits = GetModelTreeData()->GetTreeSplits();
296 const auto leafValues = GetModelTreeData()->GetLeafValues();
297 const auto leafWeights = GetModelTreeData()->GetLeafWeights();
298 const auto treeStartOffsets = GetModelTreeData()->GetTreeStartOffsets();
299 for (size_t treeIdx = begin; treeIdx < end; ++treeIdx) {
300 TVector<TModelSplit> modelSplits;
301 for (int splitIdx = treeStartOffsets[treeIdx];
302 splitIdx < treeStartOffsets[treeIdx] + treeSizes[treeIdx];
303 ++splitIdx)
304 {
305 modelSplits.push_back(GetBinFeatures()[treeSplits[splitIdx]]);
306 }
307 TConstArrayRef<double> leafValuesRef(
308 leafValues.begin() + leafOffsets[treeIdx],
309 leafValues.begin() + leafOffsets[treeIdx] + ApproxDimension * (1u << treeSizes[treeIdx])
310 );
311 builder.AddTree(
312 modelSplits,
313 leafValuesRef,
314 leafWeights.empty() ? TConstArrayRef<double>() : TConstArrayRef<double>(
315 leafWeights.begin() + leafOffsets[treeIdx] / ApproxDimension,
316 leafWeights.begin() + leafOffsets[treeIdx] / ApproxDimension + (1ull << treeSizes[treeIdx])
317 )
318 );
319 }
320 builder.Build(this);
321 this->SetScaleAndBias(savedScaleAndBias);
322}
323
324flatbuffers::Offset<NCatBoostFbs::TModelTrees>
325TModelTrees::FBSerialize(TModelPartsCachingSerializer& serializer) const {

Callers 1

TruncateMethod · 0.80

Calls 12

SetScaleAndBiasMethod · 0.95
GetTreeSplitsMethod · 0.80
GetTreeSizesMethod · 0.80
GetLeafWeightsMethod · 0.80
GetTreeStartOffsetsMethod · 0.80
sizeMethod · 0.45
GetLeafValuesMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
AddTreeMethod · 0.45
emptyMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected