pulsatrix
Loading...
Searching...
No Matches
pulsatrix::KernelSHAP Class Reference

Approximates Shapley values via full coalition enumeration + SHAP-kernel-weighted linear regression, reusing fit_weighted_linear_regression for the reduced (n-1)-dimensional problem the efficiency-axiom substitution produces. More...

#include <kernel_shap.hpp>

Public Member Functions

Attribution explain (const std::function< Tensor(const Tensor &)> &predict, const Tensor &input, const Tensor &baseline, int64_t target_index, DeviceBackend *backend) const
 Computes Shapley value approximations for one output index.
 

Detailed Description

Approximates Shapley values via full coalition enumeration + SHAP-kernel-weighted linear regression, reusing fit_weighted_linear_regression for the reduced (n-1)-dimensional problem the efficiency-axiom substitution produces.

Note
The empty/full coalitions have undefined SHAP kernel weight (division by zero) – phi_0 is fixed to f(baseline) exogenously, and the efficiency axiom (sum(phi_i) = f(x) - f(baseline)) is enforced by substitution (eliminating the last feature's coefficient), not by including those two coalitions in the regression. See mission_kernel_shap.md's Recon for the hand-derived n=2 case this was verified against before implementation.
Full 2^n enumeration, not sampling – exact at this codebase's small feature counts (mathematically equivalent to the definitional Shapley formula at full enumeration), not the charter's excluded O(2^n)/O(n!) brute-force-at-scale case.
Takes a forward-pass callable, not ExplainerContext& – model-agnosticism by construction, same pattern as LIME.
Device-generic host boundary: coalitions are built on the host from one read of input/baseline, uploaded beside the input, and only f(z)[target] is read back.

Member Function Documentation

◆ explain()

Attribution pulsatrix::KernelSHAP::explain ( const std::function< Tensor(const Tensor &)> &  predict,
const Tensor &  input,
const Tensor &  baseline,
int64_t  target_index,
DeviceBackend *  backend 
) const
inline

Computes Shapley value approximations for one output index.

Parameters
predictForward-pass callable: input Tensor in, output Tensor out.
inputInput to explain.
baselineReference "feature absent" input. Must match input's shape.
target_indexWhich output element to attribute (0-based, flat index).
backendBackend to allocate intermediate tensors through.
Returns
An Attribution with method "kernel_shap", values = the per-feature Shapley values (same shape as input), and metadata recording the target index used.

The documentation for this class was generated from the following file: