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

Function CalcShapValueWithQuantizedData

catboost/libs/fstr/shap_values.cpp:1532–1579  ·  view source on GitHub ↗

returned: ShapValues[featureIdx][dim][documentIdx]

Source from the content-addressed store, hash-verified

1530
1531// returned: ShapValues[featureIdx][dim][documentIdx]
1532TVector<TVector<TVector<double>>> CalcShapValueWithQuantizedData(
1533 const TFullModel& model,
1534 const TVector<TIntrusivePtr<NModelEvaluation::IQuantizedData>>& quantizedFeatures,
1535 const TVector<TVector<NModelEvaluation::TCalcerIndexType>>& indices,
1536 const TMaybe<TFixedFeatureParams>& fixedFeatureParams,
1537 const size_t documentCount,
1538 int logPeriod,
1539 TShapPreparedTrees* preparedTrees,
1540 NPar::ILocalExecutor* localExecutor,
1541 ECalcTypeShapValues calcType
1542) {
1543 CalcShapValuesByLeaf(
1544 model,
1545 fixedFeatureParams,
1546 logPeriod,
1547 preparedTrees->CalcInternalValues,
1548 localExecutor,
1549 preparedTrees,
1550 calcType
1551 );
1552 const TModelTrees& forest = *model.ModelTrees;
1553 TVector<TVector<TVector<double>>> shapValues(documentCount);
1554 const int featuresCount = preparedTrees->CombinationClassFeatures.size();
1555 const size_t documentBlockSize = CB_THREAD_LIMIT;
1556 for (ui32 startIdx = 0, blockIdx = 0; startIdx < documentCount; startIdx += documentBlockSize, ++blockIdx) {
1557 NPar::ILocalExecutor::TExecRangeParams blockParams(startIdx, startIdx + Min(documentBlockSize, documentCount - startIdx));
1558 auto quantizedFeaturesBlock = quantizedFeatures[blockIdx];
1559 auto& indicesForBlock = indices[blockIdx];
1560 localExecutor->ExecRange([&](ui32 documentIdx) {
1561 const size_t documentIdxInBlock = documentIdx - startIdx;
1562 auto docIndices = MakeArrayRef(indicesForBlock.data() + forest.GetTreeCount() * documentIdxInBlock, forest.GetTreeCount());
1563 CalcShapValuesForDocumentMulti(
1564 model,
1565 *preparedTrees,
1566 quantizedFeaturesBlock.Get(),
1567 fixedFeatureParams,
1568 featuresCount,
1569 docIndices,
1570 documentIdxInBlock,
1571 &shapValues[documentIdx],
1572 calcType
1573 );
1574 }, blockParams, NPar::TLocalExecutor::WAIT_COMPLETE);
1575 }
1576
1577 const auto& swapedShapValues = SwapFeatureAndDocumentAxes(shapValues);
1578 return swapedShapValues;
1579}
1580
1581static void OutputShapValuesMulti(const TVector<TVector<TVector<double>>>& shapValues, TFileOutput& out) {
1582 for (const auto& shapValuesForDocument : shapValues) {

Calls 10

CalcShapValuesByLeafFunction · 0.85
MakeArrayRefFunction · 0.85
MinFunction · 0.50
sizeMethod · 0.45
ExecRangeMethod · 0.45
dataMethod · 0.45
GetTreeCountMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected