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

Function CalcShapValuesByLeafForTreeBlock

catboost/libs/fstr/shap_values.cpp:1123–1205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1121}
1122
1123static void CalcShapValuesByLeafForTreeBlock(
1124 const TModelTrees& forest,
1125 int start,
1126 int end,
1127 bool calcInternalValues,
1128 const TMaybe<TFixedFeatureParams>& fixedFeatureParams,
1129 NPar::ILocalExecutor* localExecutor,
1130 TShapPreparedTrees* preparedTrees,
1131 ECalcTypeShapValues calcType
1132) {
1133 const auto& binFeatureCombinationClass = preparedTrees->BinFeatureCombinationClass;
1134 const auto& combinationClassFeatures = preparedTrees->CombinationClassFeatures;
1135 const bool isOblivious = forest.GetModelTreeData()->GetNonSymmetricStepNodes().empty() && forest.GetModelTreeData()->GetNonSymmetricNodeIdToLeafId().empty();
1136
1137 NPar::ILocalExecutor::TExecRangeParams blockParams(start, end);
1138 localExecutor->ExecRange([&] (size_t treeIdx) {
1139 if (preparedTrees->CalcShapValuesByLeafForAllTrees && isOblivious) {
1140 const size_t leafCount = (size_t(1) << forest.GetModelTreeData()->GetTreeSizes()[treeIdx]);
1141 TVector<TVector<TShapValue>>& shapValuesByLeaf = preparedTrees->ShapValuesByLeafForAllTrees[treeIdx];
1142 shapValuesByLeaf.resize(leafCount);
1143 for (size_t leafIdx = 0; leafIdx < leafCount; ++leafIdx) {
1144 switch (calcType) {
1145 case ECalcTypeShapValues::Approximate:
1146 CalcObliviousApproximateShapValuesForLeaf(
1147 forest,
1148 binFeatureCombinationClass,
1149 combinationClassFeatures,
1150 leafIdx,
1151 treeIdx,
1152 preparedTrees->SubtreeValuesForAllTrees[treeIdx],
1153 calcInternalValues,
1154 &shapValuesByLeaf[leafIdx]
1155 );
1156 break;
1157 case ECalcTypeShapValues::Regular:
1158 CalcObliviousShapValuesForLeaf(
1159 forest,
1160 binFeatureCombinationClass,
1161 combinationClassFeatures,
1162 leafIdx,
1163 treeIdx,
1164 preparedTrees->SubtreeWeightsForAllTrees[treeIdx],
1165 calcInternalValues,
1166 fixedFeatureParams,
1167 &shapValuesByLeaf[leafIdx],
1168 preparedTrees->AverageApproxByTree[treeIdx]
1169 );
1170 break;
1171 case ECalcTypeShapValues::Exact:
1172 CalcObliviousExactShapValuesForLeaf(
1173 forest,
1174 binFeatureCombinationClass,
1175 combinationClassFeatures,
1176 leafIdx,
1177 treeIdx,
1178 preparedTrees->SubtreeWeightsForAllTrees[treeIdx],
1179 calcInternalValues,
1180 &shapValuesByLeaf[leafIdx]

Callers 1

CalcShapValuesByLeafFunction · 0.85

Calls 10

GetTreeSizesMethod · 0.80
emptyMethod · 0.45
ExecRangeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected