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>
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.
◆ capabilities()
◆ explain()
Computes Shapley value approximations for one output index.
- Parameters
-
| predict | Forward-pass callable: input Tensor in, output Tensor out. |
| input | Input to explain. |
| baseline | Reference "feature absent" input. Must match input's shape. |
| target_index | Which output element to attribute (0-based, flat index). |
| backend | Backend 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: