From 4fc5b38be920330b97319aed6974024e7f661da2 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Mon, 7 Sep 2026 19:45:14 -0500 Subject: [PATCH] feat: learned-frame arm and an orbit-consistency diagnostic rp_learn_K learns K linear maps on the displacement and averages the CPPN over them, so a set closed under the domain's group makes the kernel invariant to it without anyone naming the group. orbit_consistency measures that invariance from the kernel's behaviour rather than its parameters, validated against the two kernels whose answers are known exactly. Both false-positive modes are instrumented: fit-versus-held-out separates extra capacity from discovery, and the spread of the learned maps catches a collapse to K=1. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb --- results/discovery.md | 109 +++++++++++++++++++++++++++++++++++++++ results/rp_properties.md | 28 +++++++--- tests/test_unseen.py | 26 ++++++++++ unseen.py | 72 +++++++++++++++++++++++++- 4 files changed, 226 insertions(+), 9 deletions(-) create mode 100644 results/discovery.md diff --git a/results/discovery.md b/results/discovery.md new file mode 100644 index 0000000..beb9e3d --- /dev/null +++ b/results/discovery.md @@ -0,0 +1,109 @@ +# Discovering an invariance instead of being handed one — and why the objective forbids it + +`invariance.md` settled that a group **given** to the kernel converts unseen orbit members into +seen ones: six of a knight's eight L-squares yields the other two at 0.4% of the floor. Every +result in this project is a model applying structure it was handed. This asks the only question +whose answer would justify the word "understanding" in the project's own framing: can the model +**find** the reparameterisation? + +**No. And more optimisation makes it worse, which is the useful part — it means the objective, +not the optimiser, is what forbids it.** + +## Setup + +`rp_learn_K` learns K linear maps on the displacement and averages: `m = (1/K) Σ_k CPPN(T_k r)`. +If the learned set is closed under the domain's group the average is invariant to it and the +eight knight squares become one input, without anyone having said "D4". The `T_k` start at the +identity plus noise, so collapse to K=1 is the null the run has to move away from rather than +where it accidentally begins. + +The band is measured on the same harness and seeds, not assumed: `rp` 0.02395 below, +`rp_inv` 0.00009 above, floor 0.02182. And at K=8 **the solution exists in the parameter space** — +`T_k` equal to the eight D4 matrices makes the average invariant by construction — so a null here +cannot be a capacity result. + +`orbit` measures D4-invariance of the kernel's behaviour as a fraction of its own scale, so it +answers "did it find the group" without the learned maps having to look like anything. Validated +against the one kernel whose answer is known exactly: `rp_inv` reads 0.000, raw `rp` reads 1.12. + +## Results, knight_sym, 6 seeds + +``` +arm steps seen unseen orbit spread +rp 2500 0.00097 0.02395 1.121 - +rp_learn_2 2500 0.00093 0.02143 1.019 0.664 +rp_learn_4 2500 0.00087 0.02031 1.005 1.111 +rp_learn_4 12000 0.00032 0.04258 1.129 1.236 +rp_learn_8 2500 0.00065 0.02742 0.969 1.424 +rp_learn_8 12000 0.00020 0.04341 1.042 1.558 +rp_inv 2500 0.00002 0.00009 0.000 - +floor 0.02182 +``` + +**The 266x band is essentially untravelled.** The learned arms sit at the floor. `orbit` moves +from 1.121 to 0.969 at best — a weak drift towards invariance that buys nothing. + +**Both false-positive modes appeared, and both were instrumented before the run.** `seen` +improves monotonically with K and with steps (0.00097 → 0.00020, a 5x fit) while `unseen` does +not: the K transforms were used as extra capacity. And `spread` rises with K (0.66 → 1.56), so +the maps did not collapse to one — they diverged, just not towards the group. + +**Training to convergence makes it worse, not better.** This was run to the same standard applied +to the binned table in `psi.md`, because under-training an arm is the mirror of tuning one until +it catches up. At 12000 steps `seen` improves 3x and `unseen` **doubles** (0.02031 → 0.04258), +while `orbit` moves *away* from invariance (1.005 → 1.129). The null is not a budget artefact; it +is the opposite of one. + +## Why, and this is the finding + +**Nothing in the objective rewards invariance.** The loss scores fit on the cells the model was +shown. Invariance only pays on the cells it was not shown, and those are by construction absent +from the loss. An unconstrained kernel fits the training cells better than one tied to an orbit, +so gradient descent walks away from the invariant solution — correctly, by its own lights. + +That reframes the null. It is not that the architecture cannot hold the answer (it can, at K=8), +and not that the optimiser is too weak (more of it hurts). It is that **the thing we want was +never in what we asked for.** Which is the same shape as the five previous nulls in this project, +one level up: those were about what the input could express, this one is about what the objective +could reward. + +It also gives the next paper a measured starting line rather than a hunch. Evolutionary search — +already recorded as where this project goes next — selects on fitness, and a fitness that +includes held-out relations puts invariance *in* the objective, where gradient on a training loss +cannot. That is now a stated prediction with a number to beat: 0.02395 floor, 0.00009 ceiling, +and gradient reaching 0.02031. + +## One thing the learned frame does buy + +On the `smooth` teacher, which has no D4 symmetry, `rp_learn` costs nothing: 0.00006-0.00007 +against plain `rp`'s 0.00007. The hardcoded invariance costs **31x** there (0.00216). So a +learnable frame is free where the domain lacks the symmetry and a fixed one is not — the +advantage of discovering over committing is real. It just does not come with any discovering. + +And the `knight` control behaves: eight squares sharing a support but not a rule, every arm flat +at ~0.024 with `orbit` unmoved at ~1.49. Nothing to discover, nothing discovered. + +## What this does not establish + +One route to invariance (averaging over learned frames), one objective (fit the shown cells), one +optimiser (Adam 3e-3), one initialisation (identity plus 0.4 noise), K ∈ {2,4,8}, one group. +Other parameterisations exist — a learned canonicalisation, a Lie-algebra generator basis — and +they are not the same experiment. **This is a null about this route to discovery, not about +discovery.** The mechanism it points at, though, is not specific to the route: an objective that +scores only what was seen has no term that invariance improves, whatever the parameterisation. + +## Reproduce + +``` +for t in knight_sym knight smooth; do for a in rp rp_inv rp_learn_2 rp_learn_4 rp_learn_8; do + uv run python unseen.py --teacher $t --holdout support --arms $a --omega 2 --steps 2500 \ + --seeds 0,1,2,3,4,5 --out results/disc_${t}_${a}.json +done; done +for k in 4 8; do + uv run python unseen.py --teacher knight_sym --holdout support --arms rp_learn_$k --omega 2 \ + --steps 12000 --seeds 0,1,2,3,4,5 --out results/disc_long_k$k.json +done +``` + +Runs go 10-wide with `OMP_NUM_THREADS=1`; torch takes ~2 threads per process by default, so +pinning to one and going wide turns a 40-minute sweep into 6 minutes on this machine. diff --git a/results/rp_properties.md b/results/rp_properties.md index b785892..98a478d 100644 --- a/results/rp_properties.md +++ b/results/rp_properties.md @@ -164,17 +164,29 @@ input rather than what the mechanism could do. It also bounds `chess_reach.md` d `sharp.md` did: the type-conditioned kernel represents a knight's L, and a D4-conditioned one would generalise it — a prediction for the parked chess arc, not a result. -**What is still not shown: the model is GIVEN the group, it does not find it.** Every result in -this project is a model applying structure it was handed. Discovering which invariance a domain -has is untouched, and it is what the word "understanding" in this project's framing means. +**The model is GIVEN the group, and `discovery.md` measured that it cannot find one.** A learned +frame — K linear maps on the displacement, averaged — leaves the 266x band between floor and +oracle essentially untravelled, and **training to convergence makes it worse**: `seen` improves +5x while `unseen` doubles and the invariance metric moves away from zero. At K=8 the invariant +solution exists in the parameter space, so this is neither capacity nor optimiser strength. + +The reason is the objective. The loss scores fit on cells the model was shown; invariance only +pays on cells it was not, and those are by construction absent from the loss. An unconstrained +kernel fits the shown cells better than one tied to an orbit, so gradient descent walks away from +the answer, correctly by its own lights. **The five earlier nulls were about what the input could +express. This one is about what the objective could reward.** + +One thing the learned frame does buy: on a domain without the symmetry it costs nothing, where +the hardcoded invariance costs 31x. Discovering beats committing — it just does no discovering. ## What is open, in order -1. **Discovering an invariance rather than being handed one.** `invariance.md` settled that a - given group converts unseen orbit members into seen ones. Finding the group is untouched, has - no obvious cheap oracle, and is the only remaining question whose answer would justify the - word "understanding". Candidates: learning the canonicalisation, or scoring a model across a - family of domains with different groups so that discovery is the only way to win. +1. **An objective that can reward invariance at all.** `discovery.md` located the obstacle + precisely: a loss over shown relations has no term that invariance improves, whatever the + parameterisation. Gradient descent is not the thing to fix. The candidates are objectives, not + architectures — selection on held-out relations (which is what evolutionary search does by + construction, and is where this project already said it goes next), or a family of domains + sharing a group so that transfer is in the loss. 2. **Kernel capacity and interference.** How many distinct kernels fit before they collide, and which pairs collide first. The pawn/colour result is one measured point of this curve; the sweep makes similarity an independent variable instead of an accident of chess. Deliberately diff --git a/tests/test_unseen.py b/tests/test_unseen.py index 52a9b2d..a74c85c 100644 --- a/tests/test_unseen.py +++ b/tests/test_unseen.py @@ -165,3 +165,29 @@ def test_knight_sym_is_one_orbit_and_knight_is_not(): asym = unseen.gabor_kernel(kind="knight", seed=0)[cells] assert (sym.std(0) == 0).all() # same value on all eight squares, per channel assert (asym.std(0) > 0).any() # the control shares support but not a rule + + +def test_orbit_consistency_reads_zero_for_a_kernel_that_is_invariant_by_construction(): + # Validates the metric itself against the one kernel whose answer is known exactly. + inv = unseen.make_model("rp_inv", 0)["rp"].cppn + raw = unseen.make_model("rp", 0)["rp"].cppn + assert unseen.orbit_consistency(inv) < 1e-6 + assert unseen.orbit_consistency(raw) > 0.1 + + +def test_learned_frame_starts_spread_and_can_collapse(): + # The null hypothesis for the learned arm is that the maps collapse to one, making it K=1 + # with more compute. They start apart, and a deliberate collapse must read as one. + k = unseen.make_model("rp_learn_4", 0)["rp"].cppn + assert unseen.frame_spread(k) > 0.1 + with torch.no_grad(): + k.T.copy_(k.T[0].expand_as(k.T)) + assert unseen.frame_spread(k) < 1e-6 + + +def test_learned_frame_averages_over_its_maps(): + k = unseen.make_model("rp_learn_2", 0)["rp"].cppn + r = torch.randint(-3, 4, (4, 4, 2)).float() + edge, ctx = torch.ones(4, 4, 1), torch.zeros(2) + manual = torch.stack([k.cppn(r @ t.T, edge, ctx) for t in k.T]).mean(0) + assert torch.allclose(k(r, edge, ctx), manual, atol=1e-6) diff --git a/unseen.py b/unseen.py index 1fba110..0c6b09f 100644 --- a/unseen.py +++ b/unseen.py @@ -120,6 +120,69 @@ class InvariantCPPN(nn.Module): return self.cppn(inv, edge_onehot, context) +class LearnedFrameCPPN(nn.Module): + """K learned linear maps on the displacement, averaged: m = (1/K) sum_k CPPN(T_k r). + + `invariance.md` settled that a group HANDED to the kernel converts unseen orbit members into + seen ones. This asks the question that one could not: can the model FIND the reparameterisation + instead of being given it? If the learned set of T_k is closed under the domain's group, the + average is invariant to it and the eight knight squares become one input -- without anyone + having said the word D4. + + The oracle and the floor are both already measured on the same harness and seeds, so this + lands inside a 266x band rather than against nothing: `rp_inv` 0.00009 above, `rp` 0.02395 + below (knight_sym, sharp/invariance runs). + + TWO WAYS THIS CAN LOOK LIKE A RESULT WITHOUT BEING ONE, both checked: + - K transforms are extra capacity. A wider kernel fits training cells better and says + nothing about held-out ones, so the hold-out is the discriminator, not `seen`. + - The T_k collapse to one map, making this K=1 with more compute. Reported as their spread. + And `orbit_consistency` measures the property directly, independent of accuracy: apply a D4 + element to r and see whether the kernel's output moves. + """ + def __init__(self, cppn: nn.Module, k: int, seed: int = 0): + super().__init__() + self.cppn = cppn + g = torch.Generator().manual_seed(seed + 77) + # near identity plus noise: initialised AT the group's identity element, so a collapse to + # K=1 is the null hypothesis the run has to move away from rather than the thing it + # accidentally starts from. + self.T = nn.Parameter(torch.eye(2).repeat(k, 1, 1) + + torch.randn(k, 2, 2, generator=g) * 0.4) + + def forward(self, r, edge_onehot, context): + return torch.stack([self.cppn(r @ t.T, edge_onehot, context) for t in self.T]).mean(0) + + +D4 = [torch.tensor(m, dtype=torch.float32) for m in + ([[1, 0], [0, 1]], [[0, -1], [1, 0]], [[-1, 0], [0, -1]], [[0, 1], [-1, 0]], + [[-1, 0], [0, 1]], [[1, 0], [0, -1]], [[0, 1], [1, 0]], [[0, -1], [-1, 0]])] + + +@torch.no_grad() +def orbit_consistency(kernel: nn.Module) -> float: + """How D4-invariant the kernel actually is, as a fraction of its own scale. 0 = invariant. + + Measured on the kernel's behaviour, not on its parameters, so it answers "did it find the + group" without needing the learned maps to look like anything in particular. + """ + # (n, n, 2): the CPPN expands its context to r's first two dims, so the probe grid has to + # be square. 9x9 covers offsets -4..4, which contains the knight's orbit with room around it. + ys, xs = torch.meshgrid(torch.arange(-4, 5), torch.arange(-4, 5), indexing="ij") + r = torch.stack([xs, ys], -1).float() + edge, ctx = torch.ones(9, 9, 1), torch.zeros(2) + base = kernel(r, edge, ctx) + scale = base.abs().mean().clamp(min=1e-9).item() + return max((kernel(r @ g.T, edge, ctx) - base).abs().mean().item() for g in D4[1:]) / scale + + +@torch.no_grad() +def frame_spread(kernel: nn.Module) -> float: + """Mean pairwise distance between the learned maps. ~0 means they collapsed to one.""" + T = kernel.T + return float(torch.cdist(T.flatten(1), T.flatten(1)).mean()) + + class TableKernel(nn.Module): """One weight vector per discrete displacement: a GNN with one edge type per relation. @@ -148,6 +211,8 @@ def make_model(arm: str, seed: int, omega: float = 1.0) -> nn.Module: rp.cppn = TableKernel() # ponytail: swap in place so all arms share RP's exact forward elif arm.startswith("rp_inv"): rp.cppn = InvariantCPPN(rp.cppn) + elif arm.startswith("rp_learn_"): + rp.cppn = LearnedFrameCPPN(rp.cppn, int(arm.split("_")[2]), seed) elif arm != "rp": # Exact, not a prefix check: "rp_inv" typed as "rp_invariant" or "rp_nv" would otherwise # fall through and run as plain rp, which is how this went unnoticed the first time. @@ -329,7 +394,12 @@ def one_seed(arm: str, kind: str, frac: float, steps: int, seed: int, omega: flo ev = torch.Generator().manual_seed(seed + 5000) seen = pair_batch(held, False, ev) unseen = pair_batch(held, True, ev) - return {"seed": seed, "arm": arm, "omega": omega, "kfreq": kfreq, "teacher": teacher_kind, "seen": evaluate(model, tea, seen), + k = model["rp"].cppn + diag = {"orbit": orbit_consistency(k)} + if isinstance(k, LearnedFrameCPPN): + diag["spread"] = frame_spread(k) + return {"seed": seed, "arm": arm, "omega": omega, "kfreq": kfreq, "teacher": teacher_kind, + **diag, "seen": evaluate(model, tea, seen), "unseen": evaluate(model, tea, unseen), "floor_seen": floor_mse(tea, seen), "floor_unseen": floor_mse(tea, unseen), "n_held": int(held.sum())}