Erion et al. 2021 (NMI)
Expected Gradients removes the single-baseline choice from Integrated Gradients by averaging over many baselines. Instead of one reference, it draws references from a distribution of real states and averages the integrated-gradient attribution across them. This makes the result stable: it no longer depends on one arbitrary baseline, and the attributions are provably consistent across reference draws. The method was introduced to fix the perennial worry that Integrated Gradients can be gamed by picking a convenient baseline. We apply it to the VCS by averaging integrated gradients over a pool of recorded machine states. The result is very stable but not more accurate. Each integrated-gradient term contains the factor input-minus-baseline. When the reference pool holds bytes that are constant across states, that factor is zero and the attribution collapses. Even on a varied gameplay reference pool, and with the sampler restoring a position gradient, the method carries almost no true causal signal, and on a sprite's position it still vanishes for the usual reason. It is the clearest case in the study of a method that is more careful and more expensive, yet buys stability without buying faithfulness. That trade-off is exactly what makes it worth measuring here.
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.464 — 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.
Integrated Gradients (IG) needs a baseline, an input that means “nothing”. As the IG guide showed, the answer depends heavily on that choice: a black image, a blurred image and random noise each give a different map. There is rarely a single right “nothing”.
Expected Gradients (EG) sidesteps the choice. Instead of one hand-picked baseline it uses a whole reference distribution: a pool of real inputs, for example images from the training set. It runs IG from many randomly drawn references and averages the results. The attribution then answers “how does this input differ from a typical input, and which features carry the difference?” This links EG to Shapley values from game theory, which also average a feature's contribution over many reference situations. EG is stable and keeps completeness in expectation. But stable does not mean faithful, and averaging differences can cancel them.
With \(y = f(x)\) and a reference distribution \(D\), EG assigns input \(i\) the expected value (average) of the IG integrand over references \(x'\) and path positions \(\alpha\):
\[ \mathrm{EG}_i(x) \;=\; \mathbb{E}_{x' \sim D,\;\alpha \sim U(0,1)} \Big[(x_i - x'_i)\,\frac{\partial f}{\partial x_i}\big(x' + \alpha(x - x')\big)\Big]. \]Erion et al. estimate it by Monte Carlo integration: draw \(M\) pairs \((x'^{(m)}, \alpha_m)\), one gradient each, and average. There is no inner Riemann sum; the random \(\alpha\) does the path integral. Summing over \(i\) gives completeness in expectation: \(\sum_i \mathrm{EG}_i = f(x) - \mathbb{E}_{x'}[f(x')]\).
Toy example: averaging over baselines. \(f(x_1, x_2) = x_1 x_2\) at \(x = (2, 3)\), with \(D = \{(0,0),\,(2,0)\}\), each drawn half the time. From the IG guide: IG from \((0,0)\) is \((3, 3)\); IG from \((2,0)\) is \((0, 6)\). EG is the average, \((1.5,\ 4.5)\). Check: \(1.5 + 4.5 = 6 = f(x) - \tfrac12\big(f(0,0) + f(2,0)\big) = 6 - 0\). The baseline choice is no longer a single arbitrary pick, but the result now depends on the pool \(D\).
Toy example: cancellation. Let \(f(x) = x\) at \(x = 3\), with references \(\{1, 5\}\). The two IG terms are \(3 - 1 = 2\) and \(3 - 5 = -2\). EG \(= 0\). Yet \(f\) depends on \(x\) one-for-one. EG measures how far \(x\) is from the average reference. An input sitting at the typical value gets no credit, however much the output depends on it.
| The network \(f\) | The Atari 2600 VCS running the ROM, emulated bit-exactly by jutari; its differentiable twin is JuTari.Diff. |
|---|---|
| The input \(x\) | The 128 RAM bytes at the intervention frame \(f^*\) (frame 90 of seeded random play). |
| The reference distribution \(D\) | The 90 genuine RAM states at frames 1–90 of the same seeded gameplay run: every row is a reachable machine state. |
| Monte Carlo samples | \(M = 64\) (reference, \(\alpha\)) draws per run, five independent seeds for the stability estimate. |
| The output \(y\) | A content output (one RAM byte read one-hot) and a position output (screen pixels changed versus the un-intervened frame, made differentiable by the bilinear sampler). |
| “Is the attribution right?” | The intervention oracle: poke each cause, re-run the real ROM, measure \(|\Delta y|\). |
The runner implements Erion's single-\(\alpha\)-per-reference estimator over the RAM vector: 64 draws per run, each a uniformly sampled row of \(D\) and a uniform \(\alpha\). It repeats this with five seeds, reports the mean pairwise cosine similarity between the seeds' maps (stability), and also scores single-baseline IG with the zeros baseline on the same output for a head-to-head comparison.
XAI the interpretability method substrate the bit-exact emulator it runs on (jutari, Julia).
expected_gradients.jl:182 — The method: \(M\) Monte Carlo (reference, \(\alpha\)) draws, plus completeness in expectation.expected_gradients.jl:198 — One EG term: \((x - x')\) times the gradient at the interpolated state.expected_gradients.jl:494 — The reference pool used: real RAM states from the shared gameplay run.expected_gradients.jl:149 — The older NOOP-replay pool, kept for the legacy path; its constant bytes zeroed EG.expected_gradients.jl:266 — Stability across seeds: mean pairwise cosine of the per-cause maps.expected_gradients.jl:248 — The head-to-head: single-baseline IG (zeros, 64 steps) on the same output.shared_testbed_impl.jl:393 — Builds \(D\): replays the seeded gameplay stream and records RAM at frames 1–90.SoftStep.jl:106 — The linear one-hot read: its gradient is \(e_s\) at every interpolated state.shared_testbed_impl.jl:357 — The bilinear sampler for the position output.oracle_intervene.jl:242 — The ground truth: poke a cause, re-run the real ROM, read the output.The stability score is high: different seeds give nearly the same map. That is EG's promise, and it keeps it. But look at agreement with the oracle. On the content output the map is still a single spike at the read byte, now sized by its distance from the average reference, and that spike can shrink to almost nothing. On the position output agreement stays low. Overall EG is among the least faithful attribution methods in the study while producing tidy, plausible-looking maps. That combination, high plausibility and low faithfulness, is exactly what the intervention oracle is designed to expose.
julia --project=jutari tools/xai_study/phaseB_attribution/expected_gradients.jl --games core
Writes expected_gradients_<game>_{content,ball_pixel}.json/.npz and expected_gradients_core_summary.json into tools/xai_study/phaseB_attribution/out/. Defaults: --eg-samples 64 --eg-stability-seeds 5; the IG head-to-head uses --ig-steps 64.
Read next: Integrated Gradients · KernelSHAP / Shapley · Grad×Input / DeepLIFT · Occlusion
The score is the Pearson correlation of the Expected-Gradients attribution with the oracle's exact causal map, reported raw, and the grading is always against the intervention oracle. Expected Gradients averages Integrated Gradients over a distribution of baselines, which makes the attribution provably stable across reference draws, but stability is not accuracy. Each term carries the factor input-minus-baseline, so when the reference pool holds bytes that are constant across states, that factor is zero and the attribution collapses. Even on the redesigned gameplay reference pool, and with the differentiable sampler turned on for the position regime, the method carries almost no true causal signal, and it is the lowest-faithfulness attribution method in the study. On a sprite's position it still vanishes for the usual reason: the naive gradient is zero on a discrete strobe-timed step and averaging baselines does not change that. Its plausibility proxy is high, which places it squarely in the danger zone of high plausibility with low faithfulness. The audit box reports the measured all-regime faithfulness across the 44 scored games, so the low number is an average over the whole scored set, not one unlucky game.
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 expected_gradients.jl: attr = expected-gradients per cause, F = pearson(attr, oracle_abs_delta); triad_extra_dict(f.pearson, attr, f.oracle_abs_delta). Record: out/expected_gradients_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.expected_gradients.per_game).
M is n/a on 13 of these games. Minimality is M = |U*|/|Û|, the size of the true minimal cause set over the size of the set the method actually names. On a game where the method names nothing (|Û| = 0 — it discovers no circuit, its attribution map is all-zero, or it decodes no cell), that ratio is undefined, so M is left blank rather than scored. The aggregate M is the mean over the 31 games where the method did name a cause set.
| Game | F (all) | content-F | position-F | S | M | Note |
|---|---|---|---|---|---|---|
| Bowling | 0.518 | 0.688 | 0.348 | 0.905 | 1.000 | |
| Enduro | 0.500 | 1.000 | 0.000 | 0.500 | 1.000 | position gradient vanishes |
| Riverraid | 0.500 | 1.000 | 0.000 | 0.522 | 1.000 | position gradient vanishes |
| Boxing | 0.487 | 0.817 | 0.156 | 0.542 | 1.000 | |
| Ice Hockey | 0.477 | 0.767 | 0.188 | 0.545 | 1.000 | |
| Demon Attack | 0.477 | 0.955 | 0.000 | 0.875 | 1.000 | position gradient vanishes |
| Fishing Derby | 0.474 | 0.948 | 0.000 | 0.500 | 1.000 | position gradient vanishes |
| Phoenix | 0.455 | 0.909 | 0.000 | 0.577 | 1.000 | position gradient vanishes |
| Bank Heist | 0.450 | 0.900 | 0.000 | 0.833 | 1.000 | position gradient vanishes |
| Skiing | 0.405 | 0.810 | 0.000 | 0.450 | 1.000 | position gradient vanishes |
| Double Dunk | 0.399 | 0.797 | 0.000 | 0.538 | 1.000 | position gradient vanishes |
| Freeway | 0.398 | 0.747 | 0.049 | 0.500 | 1.000 | |
| Name This Game | 0.394 | 0.788 | 0.000 | 0.417 | 1.000 | position gradient vanishes |
| Jamesbond | 0.388 | 0.747 | 0.028 | 0.893 | 1.000 | |
| Atlantis | 0.386 | 0.773 | 0.000 | 0.450 | 1.000 | position gradient vanishes |
| Video Pinball | 0.385 | 0.770 | 0.000 | 0.500 | 1.000 | position gradient vanishes |
| Private Eye | 0.380 | 0.758 | 0.003 | 0.960 | 1.000 | position gradient vanishes |
| Pong | 0.371 | 0.464 | 0.278 | 0.444 | 1.000 | |
| Air Raid | 0.294 | 0.360 | 0.228 | 0.036 | 1.000 | |
| Berzerk | 0.058 | 0.096 | 0.020 | 0.481 | 1.000 | position gradient vanishes |
| Alien | 0.000 | 0.000 | 0.000 | 0.500 | n/a | position gradient vanishes |
| Assault | 0.000 | 0.000 | 0.000 | 0.905 | 1.000 | position gradient vanishes |
| Asterix | 0.000 | 0.000 | 0.000 | 0.100 | 1.000 | position gradient vanishes |
| Breakout | 0.000 | 0.000 | 0.000 | 0.600 | 1.000 | position gradient vanishes |
| Carnival | 0.000 | 0.000 | 0.000 | 0.526 | 1.000 | position gradient vanishes |
| Centipede | 0.000 | 0.000 | 0.000 | 0.500 | 1.000 | position gradient vanishes |
| Chopper Command | 0.000 | 0.000 | 0.000 | 0.452 | n/a | position gradient vanishes |
| Frostbite | 0.000 | 0.000 | 0.000 | 0.125 | n/a | position gradient vanishes |
| Gopher | 0.000 | 0.000 | 0.000 | 0.929 | n/a | position gradient vanishes |
| Hero | 0.000 | 0.000 | 0.000 | 0.417 | n/a | position gradient vanishes |
| Kangaroo | 0.000 | 0.000 | 0.000 | 0.469 | n/a | position gradient vanishes |
| Krull | 0.000 | 0.000 | 0.000 | 0.481 | n/a | position gradient vanishes |
| Kung-Fu Master | 0.000 | 0.000 | 0.000 | 0.800 | n/a | position gradient vanishes |
| Montezuma's Revenge | 0.000 | 0.000 | 0.000 | 0.906 | 1.000 | position gradient vanishes |
| Ms. Pac-Man | 0.000 | 0.000 | 0.000 | 0.475 | n/a | position gradient vanishes |
| Pacman | 0.000 | 0.000 | 0.000 | 0.556 | n/a | position gradient vanishes |
| Pitfall | 0.000 | 0.000 | 0.000 | 0.882 | 1.000 | position gradient vanishes |
| Q*bert | 0.000 | 0.000 | 0.000 | 0.476 | n/a | position gradient vanishes |
| Road Runner | 0.000 | 0.000 | 0.000 | 0.105 | 1.000 | position gradient vanishes |
| Seaquest | 0.000 | 0.000 | 0.000 | 0.479 | n/a | position gradient vanishes |
| Space Invaders | 0.000 | 0.000 | 0.000 | 0.528 | n/a | position gradient vanishes |
| Tennis | 0.000 | 0.000 | 0.000 | 0.500 | 1.000 | position gradient vanishes |
| Venture | 0.000 | 0.000 | 0.000 | 0.474 | 1.000 | position gradient vanishes |
| Yars' Revenge | 0.000 | 0.000 | 0.000 | 0.464 | 1.000 | position gradient vanishes |
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 jutariinclude(ig_baseline_sweep.jl) runnercontent_read -> soft_ram_peek jutari-diff call site tools/xai_study/phaseB_attribution/ig_baseline_sweep.jl:294 (reused via include)reference_pool runnerexpected_gradients runnerZygote.gradient(readf, xalpha) Zygote_st_sampler_position_read runner-diffScored against the exact intervention oracle Δy(u): run_intervention.
On jaxtari (JAX / GPU): the same differentiable path has a bit-exact JAX sibling (Theorem 1, forward-exact) for batched GPU runs — JAX-equivalent differentiable path (bit-exact per Theorem 1, for GPU batching): jaxtari/jaxtari/diff/soft_step.py, soft_mem.py, straight_through.py
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.