diff --git a/regime.py b/regime.py index eefb8d9..aa3f3a8 100644 --- a/regime.py +++ b/regime.py @@ -61,7 +61,7 @@ def _metrics(losses: list[float], switched: list[bool], arousals: list[float], w def run(name: str, seed: int, steps: int, window: int = 20, bptt: int = 20, - lr: float = 1e-3, hidden: int = 32, kappa: float = 4.0) -> dict: + lr: float = 1e-3, hidden: int = 32, kappa: float = 4.0, omega: float = 10.0) -> dict: spec = dict(CONDITIONS[name]) if spec["kappa"] == KAPPA_FLAG: spec["kappa"] = kappa @@ -75,7 +75,7 @@ def run(name: str, seed: int, steps: int, window: int = 20, bptt: int = 20, world = ParticleWorld(wcfg) ctx_dim = wcfg.n_regimes if spec["ctx"] == "regime" else 2 org = Organism(attr_dim=world.attr_dim, coord_dim=2, target_dim=2, context_dim=ctx_dim, - hidden_dim=hidden, kappa=spec["kappa"], memory=spec["memory"]) + hidden_dim=hidden, omega=omega, kappa=spec["kappa"], memory=spec["memory"]) opt = torch.optim.Adam(org.parameters(), lr=lr) acfg = AffectConfig() affect = Affect() @@ -124,12 +124,13 @@ def main() -> None: ap.add_argument("--steps", type=int, default=20000) ap.add_argument("--window", type=int, default=20) ap.add_argument("--kappa", type=float, default=4.0) + ap.add_argument("--omega", type=float, default=10.0) ap.add_argument("--out", default="results/run.json") a = ap.parse_args() results = [] for name in a.conditions.split(","): for seed in (int(s) for s in a.seeds.split(",")): - r = run(name, seed, a.steps, window=a.window, kappa=a.kappa) + r = run(name, seed, a.steps, window=a.window, kappa=a.kappa, omega=a.omega) print(f"{name:<18} seed={seed} steady={r['steady']:.5f} rec@0={r['recovery'][0]:.5f}", flush=True) results.append(r) Path(a.out).parent.mkdir(parents=True, exist_ok=True) diff --git a/results/headroom.md b/results/headroom.md new file mode 100644 index 0000000..14656f1 --- /dev/null +++ b/results/headroom.md @@ -0,0 +1,332 @@ +# Headroom check for the regime setup + +Task 7. This file is the audit trail for the paper's setup section: it records what +was measured, which of the three requirements held, every knob that was moved with +its before/after, and the conclusion. + +**Verdict up front: requirement 2 holds; requirements 1 and 3 fail. Requirement 1 +fails for a structural reason that no tuning fixes — the regime oracle cannot reach +the noise floor on this domain because the architecture's bottleneck is not the +regime. Requirement 3 fails because the change flag is an untrained input spike, not +an information leak. Both failures are properties of the setup, not of claim A1.** + +Environment: `experiments/` at 164810a, `ailed/` unmodified. All runs `uv run` from +`experiments/`. Noise floor for every table below is `noise² = 4.0e-06`. + +## 1. The table + +`uv run python regime.py --conditions rp_only,grp_k0,grp_regime,rp_flag --seeds 0,1,2 --steps 8000 --out results/headroom.json` + +Means over seeds 0,1,2. `(sd)` is the across-seed standard deviation of `steady`. + +``` +condition steady (sd) rec@0 rec@2 rec@5 rec@10 a@switch +--------------------------------------------------------------------------------------------- +rp_only 0.000061 0.000020 0.000070 0.000080 0.000103 0.000090 0.130 +grp_k0 0.000021 0.000004 0.000028 0.000031 0.000045 0.000043 0.127 +grp_regime 0.000029 0.000006 0.000052 0.000054 0.000067 0.000057 0.203 +rp_flag 0.000060 0.000024 0.000280 0.000110 0.000120 0.000095 0.422 +``` + +Per-seed `steady`, because the across-seed spread is comparable to the effects being +claimed and the paired comparison is what carries the result: + +``` +condition seed 0 seed 1 seed 2 grp_k0 beaten? +rp_only 8.09e-05 6.17e-05 4.17e-05 no (0/3) +grp_k0 2.39e-05 1.67e-05 2.11e-05 -- +grp_regime 3.51e-05 2.38e-05 2.77e-05 no (0/3, worse on every seed) +rp_flag 6.13e-05 3.65e-05 8.36e-05 no (0/3) +``` + +## 2. The three requirements + +### Requirement 1 — FAILS, and is unreachable as written + +> `grp_regime` steady error must sit near the noise floor `4e-6` (within ~3x). + +`grp_regime` steady is 2.9e-05, which is 7x the floor, and it is *worse* than +`grp_k0` (2.1e-05) on all three seeds. Longer training does not rescue it: at 40 000 +steps `grp_regime` is still worse than `grp_k0` on all three seeds (1.7e-05 vs +1.5e-05). The oracle does not merely fail to help — it costs a consistent ~13-35%. + +The reason is not tuning. It is that **the regime is not the information the model is +missing.** Section 3 measures this. + +### Requirement 2 — HOLDS + +> `grp_k0` must beat `rp_only` on `steady` and on `rec@10`. + +At 8000 steps `grp_k0` beats `rp_only` 2.9x on steady (2.1e-05 vs 6.1e-05) and 2.1x +on `rec@10` (4.3e-05 vs 9.0e-05), on every seed. Memory has a job. + +**Caveat that Tasks 8 and 9 must carry:** the margin is substantially a +training-speed effect, not a capability ceiling. At 40 000 steps the memoryless +baseline largely catches up: + +``` +steps rp_only grp_k0 ratio + 8000 6.1e-05 2.1e-05 2.9x +40000 2.3e-05 1.5e-05 1.5x +``` + +`grp_k0` still wins on all three seeds at 40 000 steps, so requirement 2 holds at both +budgets. But a 2.9x headline quoted from an 8000-step run is a claim about how fast +memory learns, not about what it can represent. A1 should say which it means. + +### Requirement 3 — FAILS + +> `rp_flag` must equal `rp_only` within seed noise on every column. + +It does not. `rp_flag` matches `rp_only` on `steady` (6.0e-05 vs 6.1e-05) but is 4x +worse at `rec@0` (2.8e-04 vs 7.0e-05), on every seed. + +The brief says to investigate before A1 if this happens. It is **not** an information +leak. Diagnostic (`attr_dim` held at 4 in all three flag rows, so parameter count and +init draw are identical; only the column's *contents* change): + +``` +variant steady rec@0 rec@2 rec@5 +---------------------------------------------------------------------- +rp_only (attr_dim=3) 0.000061 0.000070 0.000080 0.000103 +rp_flag flag fires 0.000060 0.000280 0.000110 0.000120 +rp_flag flag always 0 0.000071 0.000071 0.000076 0.000096 +rp_flag flag always 1 0.000133 0.000134 0.000166 0.000179 +``` + +With the column present but never firing, `rp_flag` reproduces `rp_only`. The extra +column is harmless. With the column pinned on, everything degrades uniformly. So the +`rec@0` spike is caused by the column *changing value*, at the exact step `rec@0` +measures. + +Mechanism. `attrs` enters the RP only through `f_j = W_feat attrs_j`, the message +*from* `j`. The flag column is the same value on every particle, so firing it adds a +fixed vector `w_flag` to every `f_j`, shifting every message by +`(Σ_j m_ij) ⊙ w_flag`. Because the flag is on for ~1.5% of steps, `W_feat`'s flag +column receives gradient on ~1.5% of steps and stays near its random init. The flag +therefore delivers an *untrained perturbation* precisely when it fires. `rec@0` is +measuring the model being kicked, not the model being informed. + +This matters beyond the control: **`grp_flag` is an A1 condition and has the same +defect.** As encoded, `grp_flag` does not test "does knowing a change occurred help"; +it tests "does memory absorb an input spike". A1 should not use the change flag in +this encoding. + +## 3. Why the oracle cannot help: measured information ceilings + +The governing rule is to measure the ceiling before building the mechanism, so I +measured it directly rather than tuning against it. + +The RP computes `pred_i = (1/N) Σ_j G(r_ij, t_j, ctx) + b`. The sum includes `j = i` +at `r = 0` (the default `mask` is all-ones including the diagonal), so the receiver's +own type enters **only as an additive offset** — it can never modulate the +per-neighbour message. The world's dynamics are +`d_i = dt Σ_j K[t_i, t_j] · kern(r_ij) · r_ij`, whose entire content is the +*multiplicative pairing* `K[t_i, t_j]`. + +So I fitted, by least squares over the run, the best predictor of the form +`d_i = a[·] + Σ_j c[key(i,j)] · dt · kern(r_ij) · r_ij` under several information +sets. This is an optimistic bound: it assumes the model nails the radial kernel +exactly, so a trained model can only do worse. Means over seeds 0,1,2: + +``` +ceiling MSE(det part) MSE(vs target) +------------------------------------------------------------------------- +A perfect: (regime, t_i, t_j) 1.35e-19 4.52e-06 +B regime-blind, pair-aware (t_i, t_j) 1.13e-05 1.56e-05 +C REGIME ORACLE ceiling (regime, t_j) 7.95e-06 1.24e-05 +D no-oracle ceiling (t_j) 1.32e-05 1.75e-05 +``` + +Row A recovers the deterministic dynamics to 1e-19 and lands at 4.5e-06 against the +noisy target, which is the noise floor — the construction is correct. + +Three things follow, and together they answer the question: + +1. **Requirement 1 is unreachable in practice.** It asks `grp_regime` to reach + 1.2e-05 (3x the floor). The ceiling for *any* model given the regime but + restricted to this architecture's information flow is **C = 1.18e-05** — sitting + exactly on requirement 1's tolerance boundary, and that bound already assumes a + perfect radial kernel. Every real trained model is strictly worse than C, so no + amount of tuning satisfies requirement 1. It was written expecting the regime + oracle to close the gap to the noise floor; measurement says it cannot. + +2. **The oracle prize is small.** Going from no oracle (D, 1.82e-05) to the regime + oracle (C, 1.18e-05) is worth **1.54x**. Meanwhile `grp_k0` already measures + 1.5e-05 at 40 000 steps — i.e. `grp_k0` is *already between* D and C. Memory is + recovering most of what the regime oracle could tell it, which is exactly why + telling the model the regime adds nothing. + +3. **The real bottleneck is the type pair, not the regime.** Compare B (1.69e-05, + knows `t_i,t_j` but not the regime) with C (1.18e-05, knows the regime but not + `t_i`) against A (4.47e-06). Knowing the pair is worth about as much as knowing + the regime, and neither alone gets near the floor. The regime oracle cannot supply + `t_i`, so it cannot close the gap. + +## 4. Knobs changed + +One thing at a time; same seeds (0,1,2) before and after; every change re-ran the +affected conditions. + +| knob | before | after | evidence | kept? | +|---|---|---|---|---| +| `run(omega=...)` in `regime.py` | not a parameter (hard-coded 10.0 inside `Organism`) | parameter, **default 10.0** | plumbing only; default unchanged so all prior runs reproduce byte-identically | **yes** | +| `omega` value | 10.0 | tried 5 and 20 | see below | **no — kept 10.0** | +| `noise` | 0.002 | tried 0.0005 | see below | **no — kept 0.002** | +| `sigma` | 0.2 | tried 0.3 | see below | **no — kept 0.2** | +| `steps` | 8000 | also ran 40000 | see §2 requirement 2 | diagnostic only | +| `edge_types` | `None` (1 edge type) | tried type-pair (9 edge types) | see below | **no — not adopted; recommended for Task 8** | + +**No default in `particles.py` or `regime.py` was changed.** The only source change is +the `omega` parameter, whose default reproduces the previous behaviour exactly. +Tasks 8 and 9 run against the same parameters Task 6 was reviewed under. + +### omega (hypothesis: the CPPN cannot represent the domain's length scale) + +Ruled out. `omega` matters a lot for `rp_only` and not at all for the memory +conditions, and it never changes the `grp_regime` vs `grp_k0` ordering. + +``` +omega rp_only grp_k0 grp_regime + 5 3.0e-05 2.0e-05 2.6e-05 + 10 6.1e-05 2.1e-05 2.9e-05 <- kept + 20 7.7e-05 2.2e-05 3.3e-05 +``` + +`omega=5` would *improve* the memoryless baseline 2x and so shrink requirement 2's +margin from 2.9x to 1.5x. It is kept at 10.0 because nothing justifies moving it, but +this is worth flagging: **the size of A1's memory effect at 8000 steps is partly an +`omega` artefact.** `grp_k0` is insensitive to `omega`; `rp_only` is not. + +### noise and sigma (hypothesis: too noise-dominated to have headroom) + +Ruled out, decisively. Cutting `noise` 4x lowers the irreducible floor 16x +(4.0e-06 → 2.5e-07) and barely moves any measured error: + +``` +noise sigma floor rp_only grp_k0 grp_regime +0.002 0.2 4.0e-06 6.1e-05 2.1e-05 2.9e-05 +0.0005 0.2 2.5e-07 5.9e-05 1.8e-05 2.9e-05 +0.002 0.3 4.0e-06 7.8e-05 4.3e-05 5.5e-05 +0.0005 0.3 2.5e-07 7.1e-05 4.1e-05 5.3e-05 +``` + +At `noise=0.0005` the models sit ~70x above the floor. The residual is model error, +not noise. Raising `sigma` to 0.3 makes every condition worse and does not change any +ordering. `grp_regime` is worse than `grp_k0` in all four cells. + +This is the clearest single result in the file: **the models are not +information-limited, they are optimisation-limited.** An oracle cannot help a model +that is not yet using the information it already has, which is why adding four +columns costs ~13-35% instead of paying. + +### edge_types (hypothesis: the pair coupling has no channel) + +`regime.py` passes `edge_types=None`, so every pair is edge type 0 and the CPPN +never sees the type pair. Opening that channel (`edge_types = t_i * n_types + t_j`, +9 edge types) is the only wiring that could reach ceiling A. It helps, but it does +not change the verdict: + +``` +steps edge types rp_only grp_k0 grp_regime + 8000 single (1) 6.1e-05 2.1e-05 2.9e-05 + 8000 pair (9) 3.0e-05 1.9e-05 2.2e-05 +40000 single (1) 2.3e-05 1.5e-05 1.7e-05 +40000 pair (9) 1.7e-05 1.5e-05 1.6e-05 +``` + +With the pair channel open the model *could* represent the dynamics exactly +(ceiling A = 4.47e-06). It plateaus at 1.5e-05 instead — 3.4x short. Not adopted; +see the recommendation in §6. + +## 5. The result underneath all of this + +Read the last table by column rather than by row. At 40 000 steps with the pair +channel open, `rp_only`, `grp_k0` and `grp_regime` measure 1.7e-05, 1.5e-05 and +1.6e-05 — indistinguishable. **Every condition converges to roughly the same error +regardless of what information it is given, and that error is 3-4x above the +architecture's own information ceiling.** + +That number is set by the optimiser, not by information. The target is +non-stationary by construction: the regime switches every 40-80 steps, and an online +learner with `lr=1e-3` and truncated BPTT is permanently chasing it. The steady error +reported by `_metrics` is dominated by **weight-tracking lag**, not by representational +capacity or by noise. + +This explains every result in this file at once: + +- The regime oracle enters through `W_feat`, i.e. through *weights*. It therefore + inherits exactly the tracking lag that is causing the error, and cannot reduce it. + Worse, it adds columns that must themselves be learned, which is why it *costs* + 35% at 8000 steps and 13% at 40 000 — a tax that shrinks as those columns get fit. +- Memory (`grp_k0`) helps because `M` is *state*, and state can move faster than + weights. That is a real mechanism and it is the one A1 is about. +- The memory advantage shrinks with training (2.9x → 1.5x) because weights slowly + catch up to what state was providing early. + +## 6. Conclusion and recommendations + +**This setup has no headroom for the regime oracle, and requirement 1 cannot be +satisfied by tuning.** The regime oracle's own information ceiling on this domain is +1.18e-05, which sits on requirement 1's tolerance boundary before any training loss is +accounted for; and the trained models never get within 3x of even that, because their +error is dominated by optimiser tracking lag rather than by missing information. An +oracle cannot help a model that is not yet using the information it already has. The +`grp_regime` condition as currently constituted measures nothing about A1 — it is a +neutral-to-negative control, and the negative part is an encoding artefact. + +Requirement 2 holds at both 8000 and 40 000 steps, so memory does have a job. But the +job is *faster adaptation*, not *better asymptotic fit*, and the headline ratio +depends on the training budget (2.9x at 8000, 1.5x at 40 000) and on `omega` +(2.9x at 10, 1.5x at 5). A1 must state the budget and the knob it quotes. + +Three concrete recommendations, none of them adopted here: + +**(a) Zero-initialise the oracle columns of `W_feat`.** One line, applied in +`regime.py` after `Organism` is constructed (`ailed` should not need to know which +columns are oracle columns): + +```python +with torch.no_grad(): + org.rp.feat.weight[:, wcfg.n_types:] = 0.0 # oracle columns start as a no-op +``` + +An oracle column then starts as an exact no-op and can only act once gradient has +earned it a weight. Measured, seeds 0,1,2, 8000 steps: + +``` +init condition steady rec@0 rec@2 rec@5 +-------------------------------------------------------------------- +default rp_only 0.000061 0.000070 0.000080 0.000103 +default rp_flag 0.000060 0.000280 0.000110 0.000120 +default grp_regime 0.000029 0.000052 0.000054 0.000067 + +zero-init oracle cols rp_only 0.000061 0.000070 0.000080 0.000103 +zero-init oracle cols rp_flag 0.000076 0.000077 0.000085 0.000105 +zero-init oracle cols grp_regime 0.000021 0.000029 0.000034 0.000049 +``` + +`rp_only` is unchanged to every digit — the change is a no-op for non-oracle +conditions, so spec §7's byte-identical requirement is preserved. `rp_flag`'s 4x +`rec@0` spike disappears and it now tracks `rp_only`: **requirement 3 holds under +this fix.** And `grp_regime` drops from 2.9e-05 to 2.1e-05, exactly equal to +`grp_k0` — with the artefact removed, **the regime oracle is precisely neutral.** +That is the honest null this task was built to find: not "the oracle hurts", but +"the oracle changes nothing." + +This is not adopted because it changes every oracle condition's numbers relative to +what Task 6 was reviewed under, and because A1's condition list may itself change in +response to this file. It is a one-line change whenever it is wanted. + +**(b) Rewrite requirement 1 against the measured ceiling, not the noise floor.** +`noise² = 4e-06` is the ceiling for a model that knows `(regime, t_i, t_j)`. The +regime oracle's ceiling is 1.18e-05. Requirement 1 should compare `grp_regime` to +1.18e-05, or the domain should change so that the two coincide. + +**(c) If A1 needs an oracle with real headroom, the domain must change.** The gap the +oracle can win (1.54x) is smaller than the gap the optimiser is currently losing +(3-4x). Any of these would open it, and each needs its own measurement before being +built on: give the type pair a channel *and* train long enough to use it (§4); widen +the contrast between regimes so D and C separate further; or slow the switching so +weight-tracking lag stops dominating. Absent one of those, `grp_regime` should be +reported as a measured null rather than carried into A1 as a ceiling.