Skip to content

grl_snam.learning: learning histories, held-out curve marks, arms and learn-report (Phase 1a, 1b) - #171

Merged
transfix merged 2 commits into
mainfrom
feat/learning-core
Nov 13, 2026
Merged

transfix merged 2 commits into
mainfrom
feat/learning-core

Conversation

@transfix

@transfix transfix commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Is a learner learning, or fitting noise? This adds the public, generic core that answers it on held-out data, against an untrained arm (the policy at step 0) and a constant arm (fixed coefficients, no state dependence). It covers Phase 1a and 1b of the learning-proof plan. E1 (planted dissipation) and the retrain come later.

What's here

grl_snam/learning/history.py: one reader for every trainer's learning history.

  • load(paths, follow=False) reads JSON-lines histories by the shared conventions, with no per-schema adapter:
    • kind; x from step (else epoch);
    • train/terms beside heldout/heldout_terms;
    • heads.<g>.{mean,spread,dtheta_rel,…}, grad_norm;
    • best* and the end record's pick, blob/checkpoint.
  • It returns series named <kind>.<dotted.path> (the header becomes the meta), a checkpoint table with the pick, train/held-out term pairs, and band(runs, name) across seeds.
  • follow=True re-reads a file whose mtime or size changed. A missing file reads as empty, and a half-written last line is skipped.
  • It reads grl_snam.coef_train_history/v1 and grl_snam.coef_energy_history/v1 (round-trip tests through the real writers), libcvc's cvc.nav.coef_train_history/v1, and two downstream layouts (fixtures with neutral names).

grl_snam/learning/curves.py: marks on a held-out curve, after a 5-point running median.

  • best.
  • elbow: Kneedle.
  • plateau: the windowed Theil–Sen change stays below max(ε·IQR, σ̂) for patience windows. The window is max(5, n // 6).
  • divergence: the curve stays above best + max(δ·IQR, z·σ̂) after best.
  • σ̂ is the robust sd of the second differences. The IQR of a curve that never moved is its noise, so without the floor a flat, noisy curve got an elbow and a divergence most of the time.
  • Synthetic check (100 noise draws each at 20, 60 and 200 points):
    • pure noise: no elbow and no divergence in any draw;
    • a fall that turns back up: divergence in every draw;
    • a decay with noise at 1% of its fall: plateau in ≥ 99% of draws;
    • a straight descent: no plateau.
  • tests/fixtures/learning_marks_golden.json holds 8 synthetic curves with their marks, parameters and tolerance, for other implementations to check against. python -m grl_snam.tools.learning_marks_golden --out|--check regenerates and verifies it.

grl_snam/learning/stats.py. A seeded percentile bootstrap that follows the downstream A/B harness's bootstrap_ci draw for draw: 5000 resamples, random.Random, the same percentile indices, one generator consumed in order. Plus paired differences (arm − reference) that pair by unit and keep pairs together.

Arms: grl_snam/learning/arms.py, grl_snam/tools/arms_eval.py, grl-snam arms-eval.

  • An arm is --arm NAME=PATH|const:…:
    • a .cvcnav (a run's step-0 blob is the untrained arm) or a .pt;
    • const:1.2,3,4, const:beta=2.5, const:bias, or const:hist=H.jsonl (each head's mean at the run's held-out pick: the trained policy with its state dependence removed).
  • Every arm runs on the same seeds through coef_eval (the ice-band city: reach, pen, clear, gap) and scorecard_eval (one city scene per seed: arrival, success, penetration %, path ratio, time to goal, stalls).
  • scorecard_eval.episodes(model, seeds) is split out of evaluate() for the per-scene values. evaluate() is unchanged.
  • The output, grl_snam.arms/v1, has the harness's JSON shape: arms, then results[].metrics[m][arm] = {mean, ci95, n, paired_diff}. It adds per-seed seeds/values, direction and primary metrics, so one table reader reads both.

coef_export --constant SPEC out.cvcnav|out.pt.

  • It writes a CoefMLP with every weight zero, whose output bias is the inverse activation of each constant:
    • softplus⁻¹ through the out-bias log(expm1) fold for α/β/γ;
    • logit(c/max) for a sigmoid lam head.
  • --like takes the input layout from another policy. It also accepts the plain a,b,g form.
  • read_coef_mlp(path) loads any .cvcnav back into torch, with the same forward and byte-identical re-export. Every layout is tested: plain, μ, risk, lam v1, two-head v2.
  • Locally with pycvc 3.7.13, libcvc's C++ coef_mlp returns the constant blob's coefficients exactly.

The report: grl_snam/learning/report.py, grl-snam learn-report HIST… [--arms A.json] --json R.json. Each claim is marked pass or fail:

  • loss: each held-out loss term at the last evaluation beats the first. A loss term is a held-out value with a training twin (the same name, or <prefix>_<name> as in grl-snam train's obj_goal), or fitness. The last, not the picked one: the pick is chosen on the same held-out data. With several seeds the bootstrap CI of the per-run gain must lie above 0. One run needs at least 5 evaluations and a gain above max(δ·IQR, z·σ̂), and the evidence says that basis. Held-out metrics with no twin (reach, path length, clearance) get marks, with reach and clearance read as higher-is-better, but no claim; they are listed under untested.
  • selection: the pick was made on held-out data, and is not step 0.
  • task: on each primary metric, trained beats every other arm (the paired-difference CI lies on the better side of 0). It works from per-seed values, or from a harness table's own paired_diff.
  • planted: …planted.<region>.rel_err is within the bound at the pick, and the untrained net's is not. This is ready for E1.

The report also carries each run's curve marks, each head's plateau and the checkpoint table, which the Ariadne Learning window will read. A claim the data cannot support fails and says why, and --strict exits 1 on any failure.

Checked

  • tests/learning/: 61 tests, covering the five history layouts (plus two real ones from Does base GRL-SNAM's policy learn? The coef_sdf learning check, and E1 (planted dissipation) #172: a grl-snam train retrain seed and the E1 history with its init record), both writers' round trips, follow, the golden, bootstrap parity, the arms table, arms_eval end to end, --constant/read_coef_mlp, the report families and the CLI passthroughs.
  • black 26.5.1 and ruff (cvcpkg) are clean.
  • End to end: coef-train --history --checkpoint-every --keep-best → arms-eval → learn-report on a 40-step toy run. Its held-out pick was step 0, and the report fails selection:not-untrained and every trained-vs-untrained claim (difference exactly 0), which is the right verdict.

Not in this PR

  • The constant arm's loss terms on held-out data. The histories hold only the trained run's terms, so the loss family compares against step 0 only; the constant arm is compared on the task metric. Scoring a constant net on a trainer's held-out set is a follow-up.
  • E1, the retrain (1d) and the Ariadne Learning window (Phase 3).

Checked on real histories

The five retrain histories in #172 (grl-snam train, 4000 steps, 41 checkpoints each) give: fitness +0.007 [+0.002, +0.013] (n = 5, pass); none of the four objective terms improves on held-out data (obj_loss −0.60 [−1.23, +0.03], fail); selection:not-untrained fails (a seed picked step 0). This agrees with #172's write-up.

…pare arms, report claims

Phase 1a and 1b of the learning proof: is a learner learning, or fitting noise? Held-out data,
against an untrained arm and a constant arm.

- grl_snam/learning/history.py: load(paths, follow=False) reads any trainer's JSON-lines history
  by the shared conventions (kind, step/epoch, train/terms beside heldout, heads.<g>.*,
  grad_norm, best*, blob/checkpoint), no per-schema adapter: series <kind>.<path>, the header as
  meta, a checkpoint table with the pick, train/held-out term pairs, band() across seeds, and an
  mtime/size re-read that tolerates a half-written last line.
- grl_snam/learning/curves.py: best, Kneedle elbow, plateau (windowed Theil-Sen change against
  the curve's IQR) and divergence after best, on a 5-point running median, each threshold with a
  noise floor (robust sd of the second differences) so a flat noisy curve gets no elbow and no
  divergence.
- grl_snam/learning/stats.py: the downstream A/B harness's percentile bootstrap, draw for draw
  (5000 resamples, one seeded generator), and paired differences that keep pairs together.
- grl_snam/learning/arms.py + tools/arms_eval.py: arms NAME=PATH|const:..., scored on paired
  held-out seeds through coef_eval and scorecard_eval, written as grl_snam.arms/v1 (the
  harness's JSON shape plus per-seed values, direction and primary metrics).
- grl_snam/learning/report.py + `grl-snam learn-report`: loss, selection, task and planted
  claims, each pass or fail, plus the curves' marks and the checkpoint tables.
- tools/coef_export.py: --constant (a CoefMLP with zero weights whose output bias is the inverse
  activation of each constant, to .cvcnav or .pt) and read_coef_mlp (.cvcnav back to torch).
- tools/scorecard_eval.py: episodes(model, seeds) gives the per-scene stats evaluate() reduces.
- tests/learning/*, tests/fixtures/learning_history/* (five writers' layouts, downstream ones
  with neutral names), tests/fixtures/learning_marks_golden.json (tools/learning_marks_golden.py
  regenerates and checks it).
…rms, metrics, init)

Found running learn-report on the five real retrain histories of the base-measure work (its PR
#172):

- A held-out <prefix>_<term> (grl-snam train's obj_goal) with no exact twin pairs with the
  training <term>; without it no objective term had a twin.
- A held-out value with a training twin is a loss term; the loss claims are made on those (and
  on fitness) only. Held-out metrics with no twin (reach, path_m, min_clear_m, ...) get marks and
  are listed under untested, instead of a claim with a guessed direction: reach and min_clear_m
  read as lower-is-better before. HIGHER_IS_BETTER and a header `maximize` list give a metric's
  direction for its marks.
- An `init` record (train_coef_energy's untrained evaluation before epoch 0) joins the first
  evaluated kind's series one before its first x, so the untrained net is the first point.
- `planted` values are not loss terms (the planted claims read them).
- One run needs 5 evaluations for a loss claim to pass (the noise floor needs them); its margin
  is now max(delta * IQR, z * noise).

Fixtures: sdf_train_history.jsonl (a subset of retrain seed 0) and
coef_energy_history_planted.jsonl (the E1 pipeline history), both from #172.
@transfix
transfix merged commit d9f1a7e into main Nov 13, 2026
5 checks passed
transfix added a commit that referenced this pull request Nov 14, 2026
… (held-out objectives in arms-eval) (#174)

#171's loss claims compared a trained run's held-out loss terms only with that run's own step 0,
because a learning history holds the trained run alone. Every arm is now scored with the
trainer's own objective on the same held-out units, and learn-report claims on those as loss
terms, as it already did for the task metric.

- grl_snam.learning.objective: per-unit held-out terms for grl-snam train (loss, goal, col, reg
  per held-out pair; the mean is the history's obj_<term>) and coef-train (loss, goal, coll per
  held-out start, surrogate or bicycle; the mean is the trainer's step record at a fixed net).
  No gradient, a forked torch RNG, the net's mode restored.
- arms-eval: opt-in cases objective-sdf and objective-coef (direction down, family "loss", unit
  "pair"/"start"); --label names the run. The default cases are unchanged.
- arms: per-case family/unit fields; runs_paired_diff, a runs x units two-level bootstrap for
  one table per training seed.
- learn-report: claims on a loss case are family "loss"
  (loss:<case>:<term>:trained-vs-<arm>); --arms repeats (one table per run, pooled). The report
  JSON only gains fields (sources.arms_tables; unit, runs, per_run, labels in evidence).
- experiments/learning_proof/objective_arms.py scores through the library; it rebuilds
  docs/learning-validation/objective.json byte for byte.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant