KernelSHAP estimates Shapley values, the game-theoretic fair share of each input. The Shapley value asks how much each input contributes to the output on average, over every possible order in which the inputs could be added. It is the unique attribution that satisfies a set of fairness axioms, which is why it is widely trusted. Computing it exactly is exponential, so KernelSHAP approximates it by sampling many coalitions, subsets of inputs that are present, evaluating the output for each, and solving a weighted least-squares problem whose solution approximates the Shapley values. We apply it to the VCS by sampling coalitions of candidate causes, re-running the program for each, and correlating the estimated Shapley values with the true causal contributions. Because every coalition is a real re-run of the machine, the method works on a sprite's position where gradients fail. Given enough coalitions it recovers much of the true contribution on both content and position outputs, so it is among the more faithful attribution methods, and it reports its own completeness as a check. Its cost is the number of coalitions needed to converge. On the VCS we can watch that convergence against the exact answer, which turns a theoretical fairness guarantee into a measured faithfulness number.
Top row (image domain, as in Paper 1): the game frame, then the oracle's true causal region and this method's attributed region — each painted onto the frame through the screen footprint of the RAM cells it implicates (brighter = more important). A faithful method's heat matches the oracle's. Bottom: per-cell importance — oracle (green) vs method (blue) — and the deletion/insertion faithfulness curves (perturb the ranked causes and watch the output move). Note: the image-domain overlay footprints are illustrative, computed on the pre-redesign boot frame; the bars, curves and all reported numbers come from the re-run records on the shared gameplay states. pearson_corr_with_oracle = 0.690 — this example only (pong, state f90+15); the audit aggregate is below.
This example explains the content of RAM $36 (byte 54) — the most causally-active concept byte at this state. Its strongest true-causes are: RAM $36 (the play area — ball / paddles); RAM $31 (17% of its footprint sits in the score band, the rest in the play area). The score digits appear in the region because RAM $31 reaches them: perturbing it over the 30-frame NOOP window changes the game outcome, and hence the score — a downstream effect, not direct rendering.
New to explainable AI? This block explains the method as it is used on neural networks, then how we run the very same method on an Atari 2600, where — unlike for a network — we know the right answer. Every implementation step links to the code. See also the XAI primer for the shared vocabulary.
Three friends share a taxi and the fare is 30 euros. How should they split it fairly, if each lives at a different distance? Game theory has a famous answer: the Shapley value. Imagine the friends joining the ride one after another, in every possible order. Each time someone joins, note how much the fare goes up. A person's fair share is the average increase they cause, over all orders. Lloyd Shapley proved this is the only split that obeys a few fairness rules, for example: the shares add up to the total, and two people who always contribute the same pay the same.
For a neural network, the “players” are the input features and the “total” is the output minus a baseline output. A feature's Shapley value is its fair share of the prediction. Unlike occlusion, which removes one feature at a time, Shapley values look at every coalition (subset) of features, so backups and interactions are shared out correctly. The catch: \(n\) features have \(2^n\) coalitions. KernelSHAP estimates the values from a random sample of coalitions by solving one cleverly weighted linear regression.
Let \(N\) be the set of \(n\) features and \(v(S)\) the model output when only the features in \(S\) are present (the others replaced by a baseline). The Shapley value of feature \(i\) is
\[ \phi_i \;=\; \sum_{S \subseteq N\setminus\{i\}} \frac{|S|!\,(n-|S|-1)!}{n!}\,\big[v(S\cup\{i\}) - v(S)\big] , \]the order-averaged marginal contribution. The values always satisfy efficiency: \(\sum_i \phi_i = v(N) - v(\varnothing)\). Lundberg and Lee showed that the same \(\phi\) solves a weighted least-squares problem over coalitions \(z\in\{0,1\}^n\):
\[ \min_{\phi}\; \sum_{z} \pi(z)\Big(v(z) - v(\varnothing) - \textstyle\sum_i z_i\phi_i\Big)^2 \quad\text{s.t.}\;\; \sum_i\phi_i = v(N)-v(\varnothing),\qquad \pi(z) = \frac{n-1}{\binom{n}{|z|}\,|z|\,(n-|z|)} . \]The Shapley kernel \(\pi\) puts most weight on very small and very large coalitions. KernelSHAP samples coalitions instead of enumerating all \(2^n\), and solves this regression.
Toy example: exact Shapley values of a 3-player game. \(f(x) = 4x_1x_2 + 2x_3\) at \(x = (1,1,1)\), baseline 0. The coalition values are \(v(\varnothing)=0\), \(v(1)=v(2)=0\), \(v(3)=2\), \(v(12)=4\), \(v(13)=v(23)=2\), \(v(123)=6\). Walk through the 6 orders and record what each player adds:
| order | \(x_1\) adds | \(x_2\) adds | \(x_3\) adds |
|---|---|---|---|
| 1,2,3 | 0 | 4 | 2 |
| 1,3,2 | 0 | 4 | 2 |
| 2,1,3 | 4 | 0 | 2 |
| 2,3,1 | 4 | 0 | 2 |
| 3,1,2 | 0 | 4 | 2 |
| 3,2,1 | 4 | 0 | 2 |
Averages: \(\phi = (2, 2, 2)\), and \(2+2+2 = 6 = v(123)-v(\varnothing)\). The product term \(4x_1x_2\) is split evenly between its two players. Occlusion on the same toy gives \((4, 4, 2)\), which sums to 10: it counts the shared term twice. With \(n = 3\) the kernel gives every coalition of size 1 or 2 the same weight \(\pi = 1/3\), and the constrained regression over those 6 coalitions returns exactly \((2,2,2)\).
| The model \(f\) | The cartridge program on the bit-exact emulated Atari 2600 VCS (jutari). |
|---|---|
| The players (features) | The candidate RAM cells, de-duplicated (8 to 23 per core game). TIA and joystick causes are not players. |
| Feature absent / background | One fixed baseline: the cell is set to 0 with intervene_ram!. No background dataset is averaged over. |
| Value \(v(z)\) of a coalition | deepcopy the checkpoint, zero the absent cells, run 15 frames of the real ROM, read \(y\). No surrogate model of \(f\) is trained. |
| Sampling budget | 512 sampled coalitions plus the two endpoints; repeated draws are merged, so each distinct coalition costs one re-run. |
| “Ground-truth importance” | The oracle's single-cause |Δy| per cause, from real re-runs. |
The value function is the real machine. In textbook SHAP, \(v(S)\) is often approximated
(e.g. by averaging over a background dataset). Here coalition_value computes it exactly:
copy the checkpoint, zero every absent candidate cell with intervene_ram!, play the
recorded 15 actions with env_step!, read the output. The only approximations left are
the coalition sampling and the additive form of the explanation.
sample_coalitions draws 512 coalitions: a size \(s\in\{1,\dots,C-1\}\)
with probability \(\propto (C-1)/(s(C-s))\), then a uniform random subset of that size. Identical
draws are merged by dedup_coalitions; their kernel weights are summed.kernelshap_solve solves the weighted least squares (tiny ridge
\(10^{-8}\)) and projects the answer onto \(\sum_i\phi_i = f_1 - f_0\) with a
Lagrange multiplier. The runner records the remaining completeness residual as a check.An implementation detail worth knowing. The coalitions are drawn in proportion to the kernel and then also weighted by the kernel \(\pi(s)\) in the solve. Textbook KernelSHAP does one or the other, not both. Our estimate therefore leans even more on near-empty and near-full coalitions (“only this cell kept”, “only this cell zeroed”) than exact Shapley values would. Efficiency still holds exactly, by the constraint.
How is this different from the oracle? The oracle measures each cause alone at the real state, in two directions (+17 and →0). Shapley values average a cell's effect over many coalitions of other cells being zeroed, and split shared effects fairly. So when two cells form an AND-like pair, the oracle (like occlusion) gives each one the full effect, while SHAP gives each half. Agreement in ranking is what we score.
XAI the interpretability method substrate the bit-exact emulator it runs on (jutari, Julia).
kernelshap.jl:156 — The value function \(v(z)\): deepcopy, zero the absent cells, 15 × env_step!, read y.kernelshap.jl:176 — The Shapley kernel \(\pi(s) = (C-1)/(\binom{C}{s}s(C-s))\); endpoints handled by the constraint.kernelshap.jl:189 — Draws coalition sizes from the kernel's size distribution, then a uniform subset.kernelshap.jl:256 — Merges repeated draws (one re-run each) and sums their kernel weights.kernelshap.jl:230 — Weighted least squares plus the Lagrange projection onto \(\sum\phi = f_1-f_0\).kernelshap.jl:368 — One experiment: oracle, endpoints, 512 coalitions, solve, scoring, convergence sweep.jutari_oracle.jl:176 — The poke that makes a cell “absent” in the emulated RAM.StellaEnvironment.jl:259 — One frame of the real machine; each coalition costs 15 of them.oracle_intervene.jl:242 — The oracle's single-cause re-run, the ground truth the Shapley values are compared with.shared_testbed_impl.jl:115 — The shared gameplay checkpoint and the position output.Bars are \(|\phi|\) per cause next to the oracle's true effect. TIA and joystick causes are zero for SHAP by construction, and both causes of a byte share a height. Where the oracle shows two cells with large, similar effects, SHAP may show them at about half height each: that is fair sharing, not an error. Check the completeness residual (should be near zero) and the convergence block: if agreement still changes between \(N/2\) and \(N\), more coalitions would help. Expect SHAP to recover much of the true structure on both content and position outputs.
julia --project=jutari tools/xai_study/phaseB_attribution/kernelshap.jl --games core
Writes kernelshap_<game>_{content,ball_pixel}.json/.npz into tools/xai_study/phaseB_attribution/out/, with the signed \(\phi\), the completeness residual and the convergence sweep. Change the budget with --n-coalitions.
Read next: LIME · RISE · Occlusion · Integrated Gradients
The score is the Pearson correlation of the estimated Shapley values with the oracle's exact causal map, reported raw, and the grading is always against the intervention oracle. KernelSHAP samples coalitions of candidate causes, re-runs the machine for each, and solves a weighted least-squares problem to approximate each cause's Shapley value, so every coalition is a real intervention and the method works on a sprite's position where the gradient family scores zero. That is why it does not collapse on the position regime. Given enough coalitions it recovers much of the true contribution on both content and position outputs, so it is among the more faithful attribution methods. It also reports its own completeness, that the Shapley values sum to the difference between the intact and fully masked outputs, which is an internal consistency check. The cost the score implicitly reflects is convergence: too few coalitions leave the estimate noisy. The grading is always against the oracle, never against another method. The audit box reports the measured all-regime faithfulness across the 44 scored games. On the VCS the theoretical fairness of the Shapley value becomes a measured faithfulness number, tested against an exact answer the method never sees on a real network.
The score is measured against the §1 intervention oracle — never against another interpretability method. F (faithful) is always vs the oracle; see the execution stack. How each of F / S / M is actually computed for this method (and whether it matches the paper) is in the box just below; the numbers are in the In the audit box under it.
The exact formula this method uses for each score, read from its runner, and
whether it matches the paper's §3 (F ∧ S ∧ M triad) definition.
From the committed audit
fsm_math_phaseB.json.
| Axis | Formula (as computed) | What it measures | Matches §3? |
|---|---|---|---|
| F faithfulness | \(F = \rho_{\mathrm{Pearson}}\!\left(\mathrm{attr},\ |\Delta y(u)|\right)\) | Raw Pearson correlation between the method's per-cause attribution magnitudes and the oracle's true absolute causal effects |Delta_y(u)|, scored separately for the content and position output regimes. | ✓ matches kernelshap.jl: SHAP map per cause, F = pearson(shap_attr, oracle_abs_delta); triad_extra_dict(f.pearson, attr, f.oracle_abs_delta). Record: out/kernelshap_air_raid_content.json (metric_name=pearson_corr_with_oracle, value=0.79). Scorer pilot_ig_vs_oracle.jl pearson() (raw Statistics.cor, zero-variance->0); F = pearson(attr, oracle_abs_delta) where oracle_abs_delta = abs.(cmap.delta) (true |Delta_y| per cause). Also reports spearman, precision@k, deletion/insertion AUC (paper's auxiliary F metrics). Per-regime split: separate *_content.json and *_position.json records, each carrying its own extra.triad.{F,S,M}. how it's measured — call stack:
|
| S sufficiency | \(S = \dfrac{\#\{\,u_{\mathrm{held}}:\ |\hat{y}-y|\le\varepsilon\,\}}{|\mathrm{held\text{-}out}|}\in[0,1]\) | Fit Delta_y = a*attr + b on a calibration half of the do(u) causes, predict the disjoint held-out half, and report the fraction of held-out causes whose predicted output lands within an epsilon band of the oracle's bit-exact re-run. | ✓ matches common/triad_sm.jl sufficiency_score() (interleaved calib/held split by seed, least-squares 1-D fit Delta_y~a*attr+b on calib, epsilon = max(0.5, 0.10*heldout_spread)); assembled in triad_extra_dict(). The new §3 (sec:triad) admits the fraction-within-tolerance [0,1] special case of the held-out predictive test, which this held-out do(u) fit-then-predict estimator satisfies, so it matches. (Detail: epsilon is a self-scaled band 0.10*spread; the [-1,1] correlation form is available but this method reports the [0,1] hit fraction.) how it's measured — call stack:
|
| M minimality | \(M = |U^{\star}| / |\hat{U}| \in (0,1]\quad U^{\star}=\{u:\Delta y(u)>0\},\ \hat{U}=\{u:|\mathrm{attr}(u)|>\tau\}\) | Ratio of the number of oracle causal movers (causes with nonzero true Delta_y) to the number of cells the method names above 1e-6 of its own max attribution; null when the oracle finds no mover or the method names nothing. | ✓ matches common/triad_sm.jl minimality_score() with name_frac=1e-6, mover_floor=0.0; the above-threshold named set is used (topk kept but not passed), see triad_extra_dict(). This is the paper's M = |U*|/|U_hat| in (0,1] (standardized everywhere), so it matches the new §3. (Detail: |U*| is taken as all oracle movers with Delta_y>0, an upper bound on the strictly-smallest reproducing subset, so M can be optimistic.) how it's measured — call stack:
|
✓ matches = the same quantity as §3; ◐ partial = the same kind of estimator but a differing detail; ✗ does not match = a different quantity (see the note). Definitions: F = agreement with the oracle's true causal effects Δy(u); S = held-out predictive score in [−1, 1]; M = |U*|/|Û| (true-minimal-set size / named-set size).
This is the method's entry in the actual cross-method audit — scored on the paper's correctness triad, each axis a mean over 44 of the 44 scored games (88 committed §R records), not the single example shown above. Tradition: gradient. The example figure (Pong) is one of those records.
F faithfulness (scored vs the oracle for every method) · S sufficiency (held-out predictive score in [−1, 1]; a negative value means the explanation predicts held-out interventions worse than the unperturbed baseline; reported for the predictive methods across all three phases where the calibration/held-out split is defined) · M minimality (true-minimal-set / named-set; where the method names a cause set) — n/a otherwise, per the paper's F ∧ S ∧ M triad.
Source: leaderboard.json · the whole leaderboard is on the
methods page and the
Paper 2 audit.
This method's faithfulness on each of the 44 scored games (all-regime F, and the content vs position split). Click a header to
sort. Every number is read from site_data.json
(methods.kernelshap.per_game).
| Game | F (all) | content-F | position-F | S | M | Note |
|---|---|---|---|---|---|---|
| Enduro | 0.989 | 1.000 | 0.979 | 0.875 | 0.833 | recovers the true causes |
| Fishing Derby | 0.958 | 0.948 | 0.968 | 0.950 | 0.722 | recovers the true causes |
| Montezuma's Revenge | 0.943 | 1.000 | 0.887 | 0.938 | 0.400 | recovers the true causes |
| Space Invaders | 0.910 | 1.000 | 0.820 | 0.917 | 0.294 | recovers the true causes |
| Name This Game | 0.894 | 0.788 | 1.000 | 0.917 | 1.000 | recovers the true causes |
| Riverraid | 0.893 | 1.000 | 0.787 | 0.957 | 0.432 | recovers the true causes |
| Krull | 0.876 | 0.999 | 0.752 | 0.865 | 0.190 | recovers the true causes |
| Alien | 0.855 | 0.779 | 0.931 | 0.714 | 0.750 | recovers the true causes |
| Boxing | 0.853 | 0.817 | 0.889 | 0.750 | 0.795 | recovers the true causes |
| Gopher | 0.806 | 0.776 | 0.835 | 0.929 | 0.762 | holds up on position |
| Bowling | 0.802 | 0.767 | 0.838 | 0.881 | 0.225 | holds up on position |
| Ice Hockey | 0.788 | 0.761 | 0.815 | 0.591 | 0.500 | holds up on position |
| Frostbite | 0.783 | 0.763 | 0.804 | 0.400 | 0.395 | holds up on position |
| Phoenix | 0.765 | 0.909 | 0.622 | 0.462 | 1.000 | |
| Pacman | 0.750 | 0.776 | 0.725 | 0.444 | 1.000 | |
| Demon Attack | 0.722 | 0.735 | 0.708 | 0.875 | 0.350 | |
| Kung-Fu Master | 0.720 | 0.745 | 0.696 | 0.800 | 0.806 | |
| Jamesbond | 0.719 | 0.747 | 0.691 | 0.893 | 0.288 | |
| Skiing | 0.700 | 0.810 | 0.590 | 0.450 | 0.833 | |
| Pitfall | 0.697 | 0.686 | 0.707 | 0.882 | 0.344 | holds up on position |
| Q*bert | 0.693 | 0.999 | 0.387 | 0.500 | 1.000 | |
| Bank Heist | 0.669 | 0.900 | 0.438 | 0.833 | 0.900 | |
| Ms. Pac-Man | 0.659 | 0.810 | 0.507 | 0.475 | 0.816 | |
| Freeway | 0.633 | 0.387 | 0.879 | 0.600 | 0.536 | holds up on position |
| Breakout | 0.629 | 0.750 | 0.509 | 0.550 | 0.806 | |
| Pong | 0.625 | 0.690 | 0.559 | 0.389 | 0.281 | |
| Private Eye | 0.620 | 0.503 | 0.737 | 0.960 | 0.229 | holds up on position |
| Air Raid | 0.607 | 0.602 | 0.612 | 0.500 | 0.423 | holds up on position |
| Atlantis | 0.596 | 0.546 | 0.646 | 0.450 | 0.417 | holds up on position |
| Double Dunk | 0.589 | 0.797 | 0.381 | 0.615 | 0.500 | |
| Video Pinball | 0.540 | 0.770 | 0.309 | 0.500 | 0.500 | |
| Tennis | 0.500 | 1.000 | 0.000 | 0.500 | 0.817 | position gradient vanishes |
| Kangaroo | 0.500 | 0.999 | 0.000 | 0.500 | 0.767 | position gradient vanishes |
| Assault | 0.482 | 0.264 | 0.699 | 0.905 | 0.263 | holds up on position |
| Asterix | 0.476 | 0.459 | 0.494 | 0.150 | 0.417 | |
| Road Runner | 0.474 | 0.000 | 0.948 | 0.500 | 0.306 | holds up on position |
| Carnival | 0.414 | 0.827 | 0.000 | 0.447 | 0.417 | position gradient vanishes |
| Yars' Revenge | 0.406 | 0.771 | 0.041 | 0.464 | 0.673 | |
| Centipede | 0.373 | 0.747 | 0.000 | 0.400 | 0.472 | position gradient vanishes |
| Venture | 0.368 | 0.736 | 0.000 | 0.474 | 0.500 | position gradient vanishes |
| Seaquest | 0.357 | 0.000 | 0.714 | 0.479 | 0.432 | holds up on position |
| Berzerk | 0.348 | 0.691 | 0.004 | 0.481 | 0.260 | position gradient vanishes |
| Chopper Command | 0.342 | 0.000 | 0.684 | 0.452 | 0.400 | holds up on position |
| Hero | 0.266 | 0.000 | 0.532 | 0.417 | 0.500 | holds up on position |
The path from this method's runner (main) into the bit-exact VCS substrate, and the
computation it involves. Every step links to the exact source on main. From
callstack_phaseB.json.
env_reset! / env_step! jutaribuild_shared_testbed jutaricoalition_value -> intervene_ram! jutari intervene_ram! call at kernelshap.jl:159 -> jutari_oracle.jl:174sample_coalitions runnerkernelshap_solve runnersnapshot jutariScored against the exact intervention oracle Δy(u): run_intervention.
The figure is generated from the committed record by
docs/gen_method_figures.py; the game frame
and each RAM cell's screen footprint are produced by
render_scenes.jl /
cell_footprints.jl.