Fix style + fix small batches for internalshaps
@@ -684,15 +684,41 @@ void CalcShapValuesInternalForFeature(
TVector<TVector<double>> &docShapValues = (*shapValues)[documentIdx];
docShapValues.assign(featuresCount, TVector<double>(forest.ApproxDimension + 1, 0.0));
for (ui32 treeIdx = 0; treeIdx < forest.GetTreeCount(); ++treeIdx) {
- ui32 leafIdx = CalcLeafToFallForDocument(forest, treeIdx, binarizedFeaturesForBlock, documentIdx,
- documentCount);
+ ui32 leafIdx = CalcLeafToFallForDocument(
+ forest,
+ treeIdx,
+ binarizedFeaturesForBlock,
+ documentIdx,
+ documentCount
+ );
+
+ if (preparedTrees.CalcShapValuesByLeafForAllTrees) {
for (const TShapValue &shapValue : preparedTrees.ShapValuesByLeafForAllTrees[treeIdx][leafIdx]) {
for (int dimension = 0; dimension < forest.ApproxDimension; ++dimension) {
docShapValues[shapValue.Feature][dimension] += shapValue.Value[dimension];
}
}
- }
+ } else {
+ TVector<TShapValue> shapValuesByLeaf;
+
+ CalcShapValuesForLeaf(
+ forest,
+ preparedTrees.BinFeatureCombinationClass,
+ preparedTrees.CombinationClassFeatures,
+ leafIdx,
+ treeIdx,
+ preparedTrees.SubtreeWeightsForAllTrees[treeIdx],
+ preparedTrees.CalcInternalValues,
+ &shapValuesByLeaf
+ );
+ for (const TShapValue& shapValue : shapValuesByLeaf) {
+ for (int dimension = 0; dimension < forest.ApproxDimension; ++dimension) {
+ docShapValues[shapValue.Feature][dimension] += shapValue.Value[dimension];
+ }
+ }
+ }
+ }
}, blockParams, NPar::TLocalExecutor::WAIT_COMPLETE);
}
}
