neural: grounding refinement + all five Layer-1.5 figures

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>
This commit is contained in:
Giorgio Gilestro 2026-07-05 08:14:19 +01:00
parent d22dd9d535
commit b8da418034
23 changed files with 680 additions and 26 deletions

84
figures/plot_collapse.py Normal file
View file

@ -0,0 +1,84 @@
"""`collapse` figure — model collapse in REAL RNN weights, arrested by grounding (↔ E1/C1).
The existence proof: a GRU trained each generation on the previous generation's own samples
loses the rare tail and drifts from truth (forward-KL climbs), and even a little grounding
arrests it. Forward-KL is the operative neural collapse metric (the RNN's smoothing keeps
spurious tail support alive, so H barely moves see the `grounding` finding).
Four panels: (A) forward-KL trajectories (dry climbs, grounded suppressed); (B) H trajectories
(barely moves smoothing resists H-collapse); (C) stationary forward-KL vs g; (D) tail-item
survival vs g. Reads only the committed bundle.
Usage: python figures/plot_collapse.py [results/collapse]
"""
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
sys.path.insert(0, str(Path(__file__).parents[1] / "src"))
from knowledge.metrics import heterozygosity # noqa: E402
from neural.config import SyntheticCfg # noqa: E402
from neural.synthetic import make_mode_truth # noqa: E402
def main(results_dir: str = "results/collapse") -> None:
df, cfg = load_bundle(results_dir)
syn = SyntheticCfg(**cfg["synthetic"])
H_star = heterozygosity(make_mode_truth(syn).p_star)
g_values = sorted(df["g"].unique())
last = int(cfg["generations"] * 0.6)
stat = df[df["generation"] >= last]
colors = plt.cm.viridis(np.linspace(0, 0.85, len(g_values)))
fig, axes = plt.subplots(2, 2, figsize=(13, 9))
# Panel A: forward-KL trajectories (dry climbs, grounded suppressed).
ax = axes[0, 0]
for g, c in zip(g_values, colors):
s = df[df["g"] == g].groupby("generation")["forward_kl"].mean()
ax.plot(s.index, s.values, "-o", color=c, ms=3, label=f"g={g:g}")
ax.set(xlabel="generation", ylabel=r"forward-KL $D(p^*\Vert\hat p)$",
title="Collapse in weights: dry KL climbs, grounding holds it")
ax.legend(frameon=False, fontsize=9)
# Panel B: H trajectories (barely moves — smoothing resists H-collapse).
ax = axes[0, 1]
for g, c in zip(g_values, colors):
s = df[df["g"] == g].groupby("generation")["heterozygosity"].mean()
ax.plot(s.index, s.values, "-o", color=c, ms=3, label=f"g={g:g}")
ax.axhline(H_star, ls=":", color="gray", lw=1, label="$H^*$")
ax.set(xlabel="generation", ylabel="heterozygosity $H$",
title="H barely moves (RNN smoothing resists H-collapse)")
ax.legend(frameon=False, fontsize=9)
# Panel C: stationary forward-KL vs g.
ax = axes[1, 0]
kg, Km, Kci = mean_ci(stat, "g", "forward_kl")
ax.errorbar(kg, Km, yerr=Kci, fmt="o-", color="#1f77b4", capsize=3)
ax.set(xlabel="grounding fraction $g$", ylabel=r"stationary forward-KL",
title="Grounding lowers stationary divergence")
# Panel D: tail-item survival vs g.
ax = axes[1, 1]
tg, Tm, Tci = mean_ci(stat, "g", "tail_frac_alive")
ax.errorbar(tg, Tm, yerr=Tci, fmt="s-", color="#d62728", capsize=3)
ax.set(xlabel="grounding fraction $g$", ylabel="tail items alive",
title="Grounding lifts tail survival")
fig.suptitle("collapse — a trained GRU collapses under dry self-training; grounding arrests it "
f"($K$={syn.K}, $n$={cfg['dynamics']['n']})", y=1.0, fontsize=13)
fig.tight_layout()
savefig(fig, results_dir, "collapse")
if __name__ == "__main__":
main(*sys.argv[1:])