| 130 | } |
| 131 | |
| 132 | CATBOOST_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 | |
| 180 | CATBOOST_API bool TrainCatBoost(const TDataSet* trainPtr, |
| 181 | const TDataSet* testPtr, |
no test coverage detected