Grounding refinement (18 reps): forward-KL is the operative neural
collapse metric, not H or tail-survival. The RNN's smoothing keeps
spurious tail modes alive, so tail_truth_mass_alive is flat/non-monotone
in g and H stays ~0.8 of H*; only forward-KL falls monotonically (dry
2.08 -> g=0.2: 0.75, paired t up to 3.3). The sharp g* << 1 is an
exact-operator feature carried by the histogram bridge (0.047); the
trained RNN confirms the SIGN and softens the sharpness (half the KL gap
closes by g~0.04, but full recovery needs g~0.19). Blueprint 3.5's
directional claim holds; the pre-registered 95%-of-H*/tail falsifier is
not met because those are the wrong metrics for a smoothing model.
Robustness: a fully-degenerate RNN can emit only invalid codewords, so
measure_distribution now returns a terminal-collapse sentinel (fixation
on the dominant mode) instead of crashing a long sweep. Edge test added
(94 tests green).
Figures: plot_{bridge,collapse,grounding,architectures,recombination}.py,
each a pure function of its committed bundle, wired into `make figures`
(glob plot_*.py minus plot_E[1-6]/_*). bridge sits on the exact H_eq
curve (g*=0.047); recombination shows max-merge rising while mean-distill
stays flat; architectures shows the collapse/rescue signs across
histogram/GRU/MLP.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
82 lines
3.6 KiB
Python
82 lines
3.6 KiB
Python
"""`architectures` figure — the Wright-Fisher collapse operator is architecture-general.
|
|
|
|
The same dry-collapse / grounding-rescue signature appears in three distinct inductive biases:
|
|
the exact histogram (multinomial), an autoregressive GRU, and a causal-masked MLP. If the
|
|
signs held only for the histogram, the effect would be an artefact of the exact operator;
|
|
seeing them in every trained architecture is the generality claim.
|
|
|
|
Three panels: (A) forward-KL trajectories per architecture, dry (solid) vs grounded (dashed);
|
|
(B) stationary forward-KL, dry vs grounded, grouped by architecture (all fall with grounding);
|
|
(C) tail-item survival, dry vs grounded, grouped by architecture (all rise). Reads only the
|
|
committed bundle.
|
|
|
|
Usage: python figures/plot_architectures.py [results/architectures]
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
from _figlib import load_bundle, mean_ci, savefig # noqa: E402
|
|
|
|
_ARCH_ORDER = ["histogram", "rnn", "mlp"]
|
|
_ARCH_LABEL = {"histogram": "histogram\n(exact)", "rnn": "GRU\n(autoregressive)",
|
|
"mlp": "MLP\n(causal-masked)"}
|
|
|
|
|
|
def main(results_dir: str = "results/architectures") -> None:
|
|
df, cfg = load_bundle(results_dir)
|
|
kinds = [k for k in _ARCH_ORDER if k in set(df["kind"].unique())]
|
|
g_dry, g_wet = min(df["g"].unique()), max(df["g"].unique())
|
|
last = int(cfg["generations"] * 0.6)
|
|
stat = df[df["generation"] >= last]
|
|
|
|
fig, axes = plt.subplots(1, 3, figsize=(16, 4.6))
|
|
arch_colors = dict(zip(kinds, plt.cm.tab10(np.arange(len(kinds)))))
|
|
|
|
# Panel A: forward-KL trajectories per architecture, dry (solid) vs grounded (dashed).
|
|
ax = axes[0]
|
|
for k in kinds:
|
|
for g, ls, alpha in [(g_dry, "-", 1.0), (g_wet, "--", 0.7)]:
|
|
s = df[(df["kind"] == k) & (df["g"] == g)].groupby("generation")["forward_kl"].mean()
|
|
ax.plot(s.index, s.values, ls, color=arch_colors[k], alpha=alpha, lw=1.8,
|
|
label=f"{k} (g={g:g})")
|
|
ax.set(xlabel="generation", ylabel=r"forward-KL $D(p^*\Vert\hat p)$",
|
|
title="Dry (solid) collapses; grounded (dashed) held —\nin every architecture")
|
|
ax.legend(frameon=False, fontsize=7, ncol=1)
|
|
|
|
# Panels B & C: grouped bars, dry vs grounded per architecture.
|
|
def grouped_bar(ax, metric, title, ylabel):
|
|
x = np.arange(len(kinds))
|
|
w = 0.36
|
|
for off, g, lab, col in [(-w / 2, g_dry, f"dry (g={g_dry:g})", "#d62728"),
|
|
(w / 2, g_wet, f"grounded (g={g_wet:g})", "#2ca02c")]:
|
|
means, errs = [], []
|
|
for k in kinds:
|
|
sub = stat[(stat["kind"] == k) & (stat["g"] == g)]
|
|
_, m, ci = mean_ci(sub.assign(_x=0), "_x", metric)
|
|
means.append(m[0]); errs.append(ci[0])
|
|
ax.bar(x + off, means, w, yerr=errs, capsize=3, label=lab, color=col, alpha=0.85)
|
|
ax.set_xticks(x)
|
|
ax.set_xticklabels([_ARCH_LABEL[k] for k in kinds], fontsize=8)
|
|
ax.set(ylabel=ylabel, title=title)
|
|
ax.legend(frameon=False, fontsize=8)
|
|
|
|
grouped_bar(axes[1], "forward_kl", "Stationary forward-KL falls with grounding",
|
|
r"stationary forward-KL")
|
|
grouped_bar(axes[2], "tail_frac_alive", "Tail-item survival rises with grounding",
|
|
"tail items alive")
|
|
|
|
fig.suptitle("architectures — dry collapse and grounding-rescue are architecture-general "
|
|
"(histogram, GRU, MLP)", y=1.02, fontsize=13)
|
|
fig.tight_layout()
|
|
savefig(fig, results_dir, "architectures")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(*sys.argv[1:])
|