Phase A · neuroscience battery

A7 · Dimensionality reduction (NMF/PCA)

cf. Jonas & Kording 2017

← back to the method catalogue

What it does?

Dimensionality reduction summarises high-dimensional activity by a few components. Principal component analysis (PCA) finds the directions of largest variance; non-negative matrix factorisation (NMF) finds additive, parts-based factors. Both are standard in neuroscience for turning a large population recording into a handful of interpretable 'latent factors'. We run them on the VCS state tensor, the values of all cells over time, and read off the recovered components. We then match each component to a known signal: the frame or scanline clock, a read/write pattern, the vsync flag, or a game variable. The intuition is that the strongest components should correspond to the machine's real internal signals, so the factorisation recovers the structure without any labels. The method is unsupervised and cheap, which is why it is popular. On the VCS it does moderately well: it recovers most of the known factors, and NMF's non-negativity fits the additive register basis a little better than PCA. But a large fraction of components stay unmatched or mix several true signals into one, so the decomposition is suggestive rather than exact. It finds structure that is genuinely present, without telling us how the program uses it.

A7 · Dimensionality reduction (NMF/PCA) result

Left: the frame. Right: this method's per-cell/per-component result against the ground-truth importance, with the RAM cells labelled. A7_nmf_matched_component_fraction_vs_known_vars = 0.600 — this example only (pong, state gameplay(seed=0,prefix=90)+15); the audit aggregate is below.

Neuroscience battery · latent factors of population activity

Learn the method — a beginner's guide

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.

The idea in plain words

Modern recordings are huge: hundreds of neurons, or thousands of hidden units, over thousands of time steps. Nobody can stare at that table. Dimensionality reduction compresses it. It looks for a few components: patterns of joint activity that, added together, rebuild most of the table. Each component has a loading (how strongly each unit takes part) and an activation over time (how strongly the pattern is “on” at each step). The hope is that these few latent factors are the system's real internal variables: “arm direction”, “choice”, “ball position”.

Two classic tools are used. PCA (principal component analysis) finds the directions along which the data vary most. NMF (non-negative matrix factorisation) instead rebuilds the data as a sum of non-negative “parts”, which often look more like separate objects. Both are unsupervised: they need no labels. That is their charm and their risk. They find what is large in the data, and large is not the same as important. On the Atari we can check which components match real signals, and whether the bytes they highlight are the ones that actually cause what appears on screen.

How it works on a neural network

Neuroscience origin. PCA, factor analysis and NMF are staples of population analysis (Cunningham & Yu 2014): reduce a recording to a few latent trajectories, then interpret them. Jonas & Kording ran NMF on the transistor activity of a simulated 6502 and found components that tracked the clock and bus activity, not the program's logic.

Deep-learning analogue. Dimensionality reduction of activations: PCA of a layer's activations over a dataset, NMF of CNN feature maps into “concept” parts, or the top singular directions of a residual stream. Arrange the recording as a matrix \(X\) of size \(T\times n\) (time steps × units).

PCA centres each column (subtracts its mean, giving \(X_c\)) and takes the singular value decomposition \(X_c = U S V^\top\). Column \(j\) of \(V\) is component \(j\)'s loading over the \(n\) units; \(X_c V\) gives the activations; the share of variance explained is \(s_j^2/\sum_k s_k^2\).

NMF requires \(X\ge 0\) and finds \(W\ge 0\) (\(T\times r\), activations) and \(H\ge 0\) (\(r\times n\), loadings) that minimise \(\lVert X - WH\rVert_F\). The Lee–Seung multiplicative updates keep everything non-negative:

\[ H \leftarrow H \odot \frac{W^\top X}{W^\top W H}, \qquad W \leftarrow W \odot \frac{X H^\top}{W H H^\top} . \]

Toy example. Record two bytes over four frames. Byte A is a frame counter: \((0, 64, 128, 192)\). Byte B is the score: \((0, 0, 1, 1)\). Byte A has variance 5120; byte B has variance 0.25. PCA's first component points almost entirely at A and explains more than 99.99 % of the variance. The score barely registers. Now suppose the score is what the screen shows and the counter only drives a blink. The top component has picked the loudest byte, not the causal one. Variance is a statement about the data, not about cause.

Recipe

  1. Record the population as a \(T\times n\) matrix \(X\) (here: 128 RAM bytes over \(T\) frames).
  2. PCA: centre the columns, take the SVD, keep the variance fraction of each component.
  3. NMF: pick a rank \(r\), run multiplicative updates from a seeded random start, and order components by energy.
  4. For each leading component, ask whether it matches a known variable (its loading sits on one variable) or a known signal (its activation tracks it).
  5. Turn the loadings into a per-unit “recovery” score: how strongly the leading components load on each unit.
  6. On the VCS, compare that score with the oracle's true causal importance of each unit.

From a neural network to the Atari

Population recording / layer activationsThe \(T\times128\) RAM tape: every byte of the VCS's working memory, once per frame. Bytes are 0–255, so the tape is non-negative and NMF applies directly.
Latent factorsThe top-5 PCA components and the top-5 of a rank-8 NMF, each with a loading over the 128 bytes and an activation over frames.
Known task variablesThe game's candidate bytes, grouped into variable families (score, ball, enemy, …), plus three structural signals: a frame clock ramp, the population write activity (bytes changed per frame), and a periodic frame-phase wave.
“This component is the choice variable”A matched component: at least half of its candidate-byte loading lies on one family (and candidates carry a real share of the loading), or its activation correlates \(|r|\ge0.5\) with one structural signal.
Importance of a unit (unknown in a brain)The intervention oracle: set the byte to 0 or base+17 at frame \(f^*\), re-run the real ROM for the horizon, count changed screen pixels.

How we apply it to the VCS

The runner A7_dimred.jl does two things: a descriptive match of components to known signals, and an oracle-scored test of whether the components point at causal bytes.

  1. The recording. From the shared gameplay state (seeded random actions, checkpoint at frame \(f^*=90\), 15-frame horizon), a7_record_ram steps the real ROM with env_step! and stores the RAM each frame. The trajectory is 150 frames for most games, continued with NOOP after the gameplay window.
  2. Decompositions. run_pca centres the raw byte values and takes an SVD. run_nmf runs 300 Lee–Seung updates at rank 8 from a seeded random start, then sorts components by energy (the size of each rank-one part \(W_{:,k}H_{k,:}\)). No package is added; both are written out in the file.
  3. Matching. known_signals builds the clock ramp, the write-activity count, and a sinusoid at the dominant autocorrelation period of that count. match_components then labels each of the top-5 components as a game variable, a known signal, or unmatched (purity threshold 0.5). The headline record value is the NMF matched-component fraction.
  4. Causal check. recovery_scores gives each candidate byte a score: its squared loading on the top-5 components, weighted by variance (PCA) or energy (NMF). oracle_importance pokes each candidate byte to 0 and to base+17, re-runs the horizon and counts changed pixels. A third value, base+37, is held out. score_triad gives F (Spearman rank correlation of recovery vs importance), S (Pearson against the held-out effect) and M (the true cause set's size over the named set's size).

Read the match metric carefully. A component that tracks the frame clock counts as “matched”. That is honest bookkeeping (the component is a real signal), but it is the epiphenomenal signal A5 warns about. The triad is what asks whether the components point at causes. Note also that the “frame-phase” wave is a stand-in: per-frame sampling cannot see the real VSYNC pulse, so it is a periodic proxy derived from the data.

Read the code

XAI the interpretability method   substrate the bit-exact emulator it runs on (jutari, Julia).

Reading the result

The figure shows two bars per candidate byte (Pong): the oracle's true causal importance and the byte's NMF recovery score, both scaled so the largest is 1. A faithful decomposition would give bars of matching height. Expect them not to match. The leading components favour the bytes that vary most, such as a paddle position the oracle calls inert, while bytes that matter but barely change, such as the scores, get almost no recovery. The match metric in the record tells a kinder story: a good share of the leading components match a game variable or a known signal, for PCA and NMF alike. The structure is real; it is just not the same thing as the program's causal story.

Pitfalls

Try it yourself

julia --project=jutari tools/xai_study/phaseA_kording/A7_dimred.jl --games core

Writes A7_<game>.json/.npz (variance curves, loadings, matches, recovery scores, oracle importance, PCA and NMF triads) plus A7_dimred_all.json into tools/xai_study/phaseA_kording/out/. Flags --nmf-rank, --topk and --purity let you test the sensitivity. Minutes per game.

Original papers & further reading

Read next: A5 · Local field potentials · A3 · Tuning curves · Sparse autoencoders · Linear probing + control tasks

How it's scored

The score is the fraction of NMF or PCA components that match a known signal or variable. We decompose the state tensor into components, then match each to the machine's known internal signals, the frame or scanline clock, a read/write pattern, vsync, or a game variable, and count the matched fraction against what the oracle marks as important. Faithfulness for this method is that matched-component fraction. It is moderate: the decomposition recovers most of the known factors, and NMF's non-negativity fits the additive register basis a little better than PCA, but a substantial fraction of components stay unmatched or mix several signals into one. A secondary reconstruction-error composite gives NMF a small edge, but on the primary matched-fraction metric the two are close. The grading is always against the oracle, not against another method. There is no sprite-position hard-case here; the output is a set of components. The audit box reports the measured matched fraction across the scored games, so the number is an average over the scored set rather than the best single 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.

How F, S, M are computed here

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_phaseA.json.

AxisFormula (as computed) What it measuresMatches §3?
F
faithfulness
\(F = \rho_{\mathrm{Spearman}}\!\left(\mathrm{attr}_{\mathrm{recovery}},\ \Delta y(u)\right)\)Spearman correlation between each cell's PCA/NMF component-recovery score and the oracle causal importance over candidate cells (reported separately for PCA and NMF).✓ matches Two triads (triad_pca, triad_nmf); correlation vs oracle causal importance, not vs known-variable labels. Runner A7_dimred.jl,; record out/A7_pong.json triad_nmf.F=-0.385, triad_pca.F=-0.041.
how it's measured — call stack:
  1. F = Spearman(component recovery, oracle causal importance) — A7_dimred.jl:751
  2. score_triad for the PCA / NMF recovery maps — A7_dimred.jl:749
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242
S
sufficiency
\(S = \rho_{\mathrm{Pearson}}\!\left(\mathrm{attr}_{\mathrm{recovery}},\ \Delta y_{\mathrm{held\text{-}out}}(u)\right) \in [-1,1]\)Pearson correlation of the component-recovery score vs the held-out do(base+37) screen break.✓ matches Held-out predictive correlation in [-1,1] of the component-recovery score vs the held-out do(base+37) screen break: the §3 (sec:triad) form. Two triads (pca, nmf). A7_dimred.jl; record S: nmf=-0.291, pca=-0.192.
how it's measured — call stack:
  1. S = Pearson(recovery, held-out do(base+37) screen break) — A7_dimred.jl:752
  2. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242
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\}\)Number of oracle-causal cells over the number of dim-reduction-surfaced cells the method names.✓ matches Runner now emits M = |U*|/|U_hat| for both triad_pca and triad_nmf (M_note '|U*|=4 (oracle movers) / |U_hat|=4/6'), the paper's set-size ratio. Record out/A7_pong.json triad_pca.M=1.0, triad_nmf.M=0.667. Replaced the former 1 − variance-not-causal over-claim rate.
how it's measured — call stack:
  1. minimality_score(recovery, oracle importance) — A7_dimred.jl:767
  2. minimality_score: |U*| oracle movers / |U_hat| surfaced cells — triad_sm.jl:57
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242

✓ 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).

In the audit

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 (44 committed §R records), not the single example shown above. Tradition: dim_reduction. The example figure (Pong) is one of those records.

0.523F — faithfulness vs oracle (mean over 44 games, ±0.057 CI95)
n/aS — sufficiency: held-out predictive (n/a where the paper does not define this axis)
n/aM — minimality: true-minimal-set / named-set (n/a otherwise)
44committed records aggregated
0.00human-plausibility proxy

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.

Results per game

This method's faithfulness on each of the 44 scored games (all-regime F; this method has no content-vs-position split (see the note below)). Click a header to sort. Every number is read from site_data.json (methods.A7_dimred.per_game).

content-F and position-F are n/a for this method. The content-vs-position split applies only to pixel-attribution methods — those that produce an attribution map over the framebuffer, whose score can be read separately on the smooth content outputs and the discrete position outputs (where the naive gradient is provably zero). This method does not attribute to a pixel output; it is graded by its own fidelity metric (A7_nmf_matched_component_fraction_vs_known_vars), reported as the F column, so there is no content or position regime to separate.

GameF (all)content-Fposition-FSMNote
Alien1.000n/an/an/an/arecovers the true causes
Berzerk0.800n/an/an/an/a
Demon Attack0.800n/an/an/an/a
Kangaroo0.800n/an/an/an/a
Pacman0.800n/an/an/an/a
Riverraid0.800n/an/an/an/a
Venture0.800n/an/an/an/a
Air Raid0.600n/an/an/an/a
Asterix0.600n/an/an/an/a
Bank Heist0.600n/an/an/an/a
Breakout0.600n/an/an/an/a
Centipede0.600n/an/an/an/a
Chopper Command0.600n/an/an/an/a
Double Dunk0.600n/an/an/an/a
Freeway0.600n/an/an/an/a
Hero0.600n/an/an/an/a
Jamesbond0.600n/an/an/an/a
Montezuma's Revenge0.600n/an/an/an/a
Ms. Pac-Man0.600n/an/an/an/a
Pong0.600n/an/an/an/a
Private Eye0.600n/an/an/an/a
Q*bert0.600n/an/an/an/a
Seaquest0.600n/an/an/an/a
Space Invaders0.600n/an/an/an/a
Yars' Revenge0.600n/an/an/an/a
Assault0.400n/an/an/an/a
Atlantis0.400n/an/an/an/a
Bowling0.400n/an/an/an/a
Boxing0.400n/an/an/an/a
Fishing Derby0.400n/an/an/an/a
Ice Hockey0.400n/an/an/an/a
Krull0.400n/an/an/an/a
Kung-Fu Master0.400n/an/an/an/a
Name This Game0.400n/an/an/an/a
Phoenix0.400n/an/an/an/a
Pitfall0.400n/an/an/an/a
Road Runner0.400n/an/an/an/a
Skiing0.400n/an/an/an/a
Carnival0.200n/an/an/an/a
Enduro0.200n/an/an/an/a
Frostbite0.200n/an/an/an/a
Gopher0.200n/an/an/an/a
Tennis0.200n/an/an/an/a
Video Pinball0.200n/an/an/an/a

Call stack — how it runs on jutari / jaxtari

The path from this method's runner (compute_game) into the bit-exact VCS substrate, and the computation it involves. Every step links to the exact source on main. From callstack_phaseA.json.

Applied on the substrate

  1. assemble the shared gameplay-state testbed + cause-density gate — build_a7_shared_state(game) -> build_shared_testbed(game; ...) runner
  2. build_shared_testbed definition: booted checkpoint + shared output + gate — function build_shared_testbed(game; ...) runner
  3. cause-density gate counts causes with |Delta_y|>floor via the oracle — cause_density = count(>(floor), deltas) runner
  4. record a (frames x 128) RAM tape by stepping the ROM with A7's per-game settings — a7_record_ram(game, frames, actions) runner
  5. step the real emulator one frame per action while recording — env_step!(env, Int(actions[t])) jutari
  6. read RAM into the tape each frame — get_ram(env) jutari

The computation

  1. PCA (method under test): principal-component decomposition of the RAM tape — run_pca(tape) runner
  2. NMF (method under test): non-negative matrix factorization of the RAM tape into rank components — run_nmf(tape, rank; iters=300, seed=0) runner
  3. match recovered components to known ground-truth signals (scoring) — match_components(method, tape, ...) runner

Scored against the exact intervention oracle Δy(u): run_intervention(checkpoint, actions, target_frame, horizon, cause).

Implementation
tools/xai_study/phaseA_kording/A7_dimred.jl
Reference
cf. Jonas & Kording 2017
Record
A7_pong.json
All records
phaseA_kording/out

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.