returned: ShapValues[featureIdx][dim][documentIdx]
| 1530 | |
| 1531 | // returned: ShapValues[featureIdx][dim][documentIdx] |
| 1532 | TVector<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 | |
| 1581 | static void OutputShapValuesMulti(const TVector<TVector<TVector<double>>>& shapValues, TFileOutput& out) { |
| 1582 | for (const auto& shapValuesForDocument : shapValues) { |
no test coverage detected