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

Function CopyTree

catboost/libs/train_interface/catboost_api.cpp:132–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132CATBOOST_API bool CopyTree(
133 ResultHandle handle,
134 int treeIndex,
135 int* features,
136 float* conditions,
137 float* leaves,
138 float* weights) {
139 if (handle) {
140 try {
141 const auto modelTrees = RESULT_PTR(handle)->ModelTrees.GetMutable();
142
143 size_t treeLeafCount = (1uLL << modelTrees->GetModelTreeData()->GetTreeSizes()[treeIndex]) * modelTrees->GetDimensionsCount();
144 auto srcLeafValues = modelTrees->GetFirstLeafPtrForTree(treeIndex);
145 const auto& srcWeights = modelTrees->GetModelTreeData()->GetLeafWeights();
146
147 for (size_t idx = 0; idx < treeLeafCount; ++idx) {
148 leaves[idx] = (float) srcLeafValues[idx];
149 }
150
151 auto applyData = modelTrees->GetApplyData();
152 const size_t weightOffset = applyData->TreeFirstLeafOffsets[treeIndex] / modelTrees->GetDimensionsCount();
153 for (size_t idx = 0; idx < (1uLL << modelTrees->GetModelTreeData()->GetTreeSizes()[treeIndex]); ++idx) {
154 weights[idx] = (float) srcWeights[idx + weightOffset];
155 }
156
157 int treeSplitEnd;
158 if (treeIndex + 1 < modelTrees->GetModelTreeData()->GetTreeStartOffsets().ysize()) {
159 treeSplitEnd = modelTrees->GetModelTreeData()->GetTreeStartOffsets()[treeIndex + 1];
160 } else {
161 treeSplitEnd = modelTrees->GetModelTreeData()->GetTreeSplits().ysize();
162 }
163 const auto& binFeatures = modelTrees->GetBinFeatures();
164
165 const auto offset = modelTrees->GetModelTreeData()->GetTreeStartOffsets()[treeIndex];
166 for (int idx = offset; idx < treeSplitEnd; ++idx) {
167 auto split = binFeatures[modelTrees->GetModelTreeData()->GetTreeSplits()[idx]];
168 CB_ENSURE(split.Type == ESplitType::FloatFeature);
169 features[idx - offset] = split.FloatFeature.FloatFeature;
170 conditions[idx - offset] = split.FloatFeature.Split;
171 }
172 } catch (...) {
173 Singleton<TErrorMessageHolder>()->Message = CurrentExceptionMessage();
174 return false;
175 }
176 }
177 return true;
178}
179
180CATBOOST_API bool TrainCatBoost(const TDataSet* trainPtr,
181 const TDataSet* testPtr,

Callers 1

TrainFunction · 0.85

Calls 11

CurrentExceptionMessageFunction · 0.85
GetMutableMethod · 0.80
GetTreeSizesMethod · 0.80
GetLeafWeightsMethod · 0.80
GetApplyDataMethod · 0.80
GetTreeStartOffsetsMethod · 0.80
GetTreeSplitsMethod · 0.80
GetDimensionsCountMethod · 0.45
ysizeMethod · 0.45
GetBinFeaturesMethod · 0.45

Tested by

no test coverage detected