neural: real-MNIST external-validity tier (collapse + grounding)

Confirms model collapse and its arrest by grounding on REAL images, not
just the synthetic sandbox. A conv VAE (the canonical generative-collapse
model) is retrained each generation on its own generated digits, with a
fraction g of fresh real MNIST mixed in. Modes = digit class x stroke-
thickness bin (K=30, Zipf, ~18 tail modes); the oracle is a frozen CNN +
deterministic thickness at 98.5% mode accuracy (30x30 confusion matrix
recorded in the manifest as the measurement-noise floor).

Result (4 reps): dry (g=0) collapses to a single mode -- forward-KL
0.5->18, support 30->1, tail 1.0->0.06, H->0 -- while 10% grounding holds
all 30 modes (KL~0.6, full tail, H~0.9). Signs, not magnitudes (blueprint
3.5); the exact synthetic oracle stays the quantitative anchor. The VAE
needs ~10% grounding vs the synthetic histogram's ~5%, consistent with the
grounding finding that trained nets need more than the exact operator.

Plugs into the existing data-agnostic contract (metrics/grounding/output
reused verbatim): mnist_data (thickness bins, class x thickness bijection,
MnistSampler), mnist_oracle (ClassifierOracle + confusion matrix),
mnist_vae (ConvVAEGenerator), mnist_loop (run_mnist_lineage), kind=
mnist_lineage dispatch, MnistCfg/OracleCfg. Figures: plot_mnist (parquet-
only) + mnist_montage (eyeball diagnostic showing digits degenerate to one
blurry mode). make mnist / make env-mnist, kept out of the make neural
loop. 99 tests green (+5 torchvision-gated).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-07-05 09:19:36 +01:00
parent 3b9f4f7893
commit 79bbc45f41
21 changed files with 2200 additions and 10 deletions

View file

@ -58,6 +58,45 @@ class SyntheticCfg:
return self.id_len + self.style_len
@dataclass(frozen=True)
class MnistCfg:
"""Real-MNIST mode-truth: a Zipf ``p*`` over ``K = n_classes * style_bins`` modes.
A mode is ``(digit class, stroke-thickness bin)`` under the fixed bijection
``mode = class * style_bins + bin``. The first seven fields are the Layer-1 ``TruthCfg``
knobs (they build the Zipf ``p*`` over the ``K`` modes via ``make_true_distribution``);
the rest govern the image tier. Unlike ``SyntheticCfg`` there is no rendering grammar
observations are real images and the oracle is a frozen classifier.
"""
K: int = 30
R: int = 1
tail: str = "zipf"
zipf_s: float = 1.5 # steep enough that the rarest ~18/30 modes form a real tail
tail_frac: float = 0.5
tail_threshold: float = 1e-2 # modes with p* < 0.01 are "tail" (~9% of the mass)
init: str = "truth" # initial p_0 over modes: {uniform, truth}
n_classes: int = 10 # MNIST digit classes
style_bins: int = 3 # S: per-class stroke-thickness quantile bins (K = n_classes*S)
data_root: str = "data" # gitignored MNIST download dir
def __post_init__(self) -> None:
if self.K != self.n_classes * self.style_bins:
raise ValueError(
f"K ({self.K}) must equal n_classes*style_bins "
f"({self.n_classes}*{self.style_bins}={self.n_classes * self.style_bins})")
@dataclass(frozen=True)
class OracleCfg:
"""Frozen-classifier oracle training/caching (MNIST tier)."""
epochs: int = 5
lr: float = 1.0e-3
batch_size: int = 256
cache: str = "models/mnist_cnn.pt" # gitignored checkpoint; its hash goes in the manifest
@dataclass(frozen=True)
class ModelCfg:
"""The generative learner. ``kind`` selects the architecture behind a thin adapter.
@ -65,7 +104,7 @@ class ModelCfg:
Neural hyperparameters are ignored by the ``histogram`` bridge model.
"""
kind: str = "histogram" # {histogram, rnn, vae, mlp}
kind: str = "histogram" # {histogram, rnn, vae, mlp, convvae}
hidden: int = 64
embed: int = 16
epochs: int = 30