diff --git a/results/invariance.md b/results/invariance.md new file mode 100644 index 0000000..040bf17 --- /dev/null +++ b/results/invariance.md @@ -0,0 +1,90 @@ +# The knight null was an input, not an architecture + +`sharp.md` measured that shown six of a knight's eight L-squares, neither the CPPN nor any +control finds the other two — everything at or above the floor. That looked like a verdict on +relational architectures. It was a verdict on what the kernel was allowed to see. + +The CPPN reads `r_ij` raw. It has no reason to know that (1,2) and (-2,-1) are the same law; +they are two different points of the plane. Canonicalise the displacement to +`(min|dx|, max|dy|)` — a D4 invariant — and the square's eight symmetries collapse to one orbit. +The knight's eight squares become **a single input**. + +``` +teacher arm seen unseen floor u/floor vs rp +knight_sym rp 0.00097 0.02395 0.02182 1.098 +knight_sym rp_inv 0.00002 0.00009 0.02182 0.004 -0.02386 +/- 0.00154 6/6 +knight_sym table_interp 0.00001 0.02205 0.02182 1.010 -0.00190 +/- 0.00014 6/6 +knight rp 0.00117 0.02359 0.02228 1.059 +knight rp_inv 0.00130 0.02611 0.02228 1.172 +0.00252 +/- 0.00189 2/6 +smooth rp 0.00006 0.00007 0.01533 0.004 +smooth rp_inv 0.00138 0.00216 0.01533 0.141 +0.00209 +/- 0.00025 0/6 +``` + +**Six of eight L-squares gives the other two, exactly.** 0.02395 → 0.00009, 0.4% of the floor, +6 seeds out of 6, per-seed 0.00012 0.00008 0.00007 0.00012 0.00004 0.00012 — no spread worth +reporting. The same architecture, the same parameters, the same training data. Only the +parameterisation of the relation changed. + +It is also 48x better on the cells it *did* train on (0.00097 → 0.00002). Eight squares became +one thing to learn, so this is sample efficiency and generalisation from the same cause. + +## The two controls are why this means anything + +Handing a model an invariance does not sneak the held-out cells into training — it hands over +the **claim** that those cells are equivalent to ones it saw. The controls test that claim in +both directions, and both were predicted before the run. + +**When the claim is false, the invariance hurts.** The `knight` teacher puts a different value on +each of the eight squares: they share a support but not a rule. `rp_inv` reads 0.02611 against +plain `rp`'s 0.02359 — worse than doing nothing, and worse than the floor. It is not that +invariants always win. + +**When the claim is the wrong one, it costs 31x.** The smooth Gabor has random frequency +directions and no D4 symmetry. Collapsing eight directions into one destroys information the +model needed: 0.00007 → 0.00216, 0/6 seeds. **An invariance is a commitment, not a free lunch.** + +## What this says + +A relational architecture infers a rule exactly when the domain's invariance is in its input, +and pays for the invariance where the domain does not have it. That is a statement about +relational architectures rather than about knights, and it is the same shape as this project's +other good result — `chess_reach.md`'s finding that the piece type must enter the kernel rather +than scale it. Both are failures of **what was expressible in the input**, not of capacity. That +is now five separate times in this project, and it is the pattern worth taking to the paper. + +For the RP verdict, this reverses the conclusion `sharp.md` was heading towards. The RP does not +have to be let go. Its knight null was our input design, and when the input carries the group the +same mechanism does rule inference cleanly. + +## What it does not say, and this is the real frontier + +**The model is GIVEN the group. It does not find it.** `rp_inv` is handed the exact symmetry the +teacher was built with. So the claim earned is: *if you know a domain's invariance, putting it in +the kernel's input converts unseen orbit members into seen ones.* Whether a model can **discover** +which invariance a domain has is untouched, and it is arguably what the word "understanding" in +this project's framing actually means. Everything measured so far — including this — is a model +applying structure it was given. + +That is the sharpest open question the project has, and unlike the ones before it, it does not +have an obvious cheap oracle. Candidates: a model that learns the canonicalisation, or one +scored across a family of domains with different groups so that discovering the right one is the +only way to win. + +**Also untested:** one group (D4), one sparse family, one exactly-representable student-teacher +setup. And a prediction this now makes, for the parked chess arc: a kernel given D4 invariants +should learn piece movement from fewer positions and generalise to offsets it never saw. That is +recorded as a prediction, not a result. + +## Reproduce + +``` +for t in knight_sym knight smooth; do + uv run python unseen.py --teacher $t --holdout support --arms rp,rp_inv,table_interp \ + --omega 2 --steps 2500 --seeds 0,1,2,3,4,5 --out results/inv_${t}.json +done +``` + +Tests: `tests/test_unseen.py`. One of them exists because an edit silently failed to land and +`rp_inv` ran as plain `rp`, producing two identical columns that could have been read as +"invariants change nothing"; the arm dispatch now raises on an unknown name and the test asserts +each arm builds the kernel it claims. diff --git a/results/rp_properties.md b/results/rp_properties.md index d906598..b785892 100644 --- a/results/rp_properties.md +++ b/results/rp_properties.md @@ -151,18 +151,30 @@ signal or sit at a boundary. On top of that sits the cost argument, which is una table scales as B^(continuous axes) × cells × channels and the CPPN is constant, 80-320× at two continuous axes. -**And one thing nothing here can do.** Shown six of a knight's eight L-squares, neither the CPPN -nor any control infers the other two — both sit at or above the floor (`sharp.md`). The symmetry -group is not learned. That bounds how `chess_reach.md` may be read: the type-conditioned kernel -can **represent** a knight's L, which is what its 0.000 → 0.758 measures. It did not acquire the -rule. It memorised a shape it was shown in full. +**And the null that looked like a verdict was an input.** `sharp.md` found that shown six of a +knight's eight L-squares nothing infers the other two. `invariance.md` gives the CPPN D4 +invariants of the displacement instead of the raw vector — the eight squares become one input — +and the same architecture recovers them exactly: 0.02395 → 0.00009, 0.4% of the floor, 6/6 seeds, +and 48× better on the training cells too. Two controls make it mean something: where the eight +squares share a support but not a rule the invariance is *worse* than nothing, and on a domain +without that symmetry it costs 31×. **An invariance is a commitment, not a free lunch.** + +That is the fifth time in this project that a null turned out to be what was expressible in the +input rather than what the mechanism could do. It also bounds `chess_reach.md` differently than +`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. ## What is open, in order -1. **Rule inference on a sparse support.** The knight null is one symmetry group, one sparse - family, one architecture. It says the group was not inferred here, not that none can be. This - is the sharpest open question the project has and it is the one chess kept implying it had - answered. +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. 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 c0026dd..52a9b2d 100644 --- a/tests/test_unseen.py +++ b/tests/test_unseen.py @@ -3,6 +3,7 @@ That leak is silent: every arm still trains, every number still prints, and `unseen` quietly becomes `seen`. So it gets the test, and the test was checked against a broken mask. """ +import pytest import torch import unseen @@ -132,3 +133,35 @@ def test_noise_teacher_has_no_neighbour_structure(): return abs(float(torch.corrcoef(torch.stack([a, b]))[0, 1])) assert neighbour_corr("smooth") > 0.8 assert neighbour_corr("noise") < 0.2 + + +def test_every_arm_name_actually_changes_the_kernel(): + # This test exists because an edit silently failed to land and rp_inv ran as plain rp, + # producing two identical columns that could have been read as "invariants change nothing". + kinds = {arm: type(unseen.make_model(arm, 0)["rp"].cppn).__name__ + for arm in ("rp", "rp_inv", "table", "table_interp")} + assert kinds["rp"] == "AffectiveCPPN" + assert kinds["rp_inv"] == "InvariantCPPN" + assert kinds["table"] == kinds["table_interp"] == "TableKernel" + with pytest.raises(ValueError): + unseen.make_model("rp_typo_arm_that_does_not_exist", 0) + + +def test_invariant_cppn_gives_one_answer_for_the_whole_d4_orbit(): + # The mechanism under test: the eight knight offsets must reach the CPPN as one input. + m = unseen.make_model("rp_inv", 0) + edge, ctx = torch.ones(1, 1, 1), torch.zeros(2) + outs = [m["rp"].cppn(torch.tensor([[[float(dx), float(dy)]]]), edge, ctx) + for dx, dy in unseen.KNIGHT] + for o in outs[1:]: + assert torch.allclose(outs[0], o, atol=1e-6) + other = m["rp"].cppn(torch.tensor([[[3.0, 1.0]]]), edge, ctx) # not in the orbit + assert not torch.allclose(outs[0], other) + + +def test_knight_sym_is_one_orbit_and_knight_is_not(): + cells = [(dy + unseen.R) * unseen.G + (dx + unseen.R) for dx, dy in unseen.KNIGHT] + sym = unseen.gabor_kernel(kind="knight_sym", seed=0)[cells] + 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 diff --git a/unseen.py b/unseen.py index 12fdbcb..1fba110 100644 --- a/unseen.py +++ b/unseen.py @@ -61,6 +61,8 @@ def gabor_kernel(sigma: float = 3.0, seed: int = 0, kfreq: float = 0.35, smooth a band-limited Gabor. The replication: a blur should match the CPPN. highfreq the same, at a frequency near the grid's resolution. Structured, not smooth. + knight_sym 1 on the eight L-offsets with the SAME value at all eight, 0 elsewhere. A + genuine D4 orbit: the eight squares are one rule under the square's symmetries. knight 1 on the eight L-offsets, 0 elsewhere. NOT smooth and RULE-GENERATED -- a neighbour average cannot recover an isolated spike, since its neighbours are 0. This is chess_reach.md's knight, asked as a mechanism question. @@ -73,12 +75,17 @@ def gabor_kernel(sigma: float = 3.0, seed: int = 0, kfreq: float = 0.35, r = torch.stack([xs, ys], -1).reshape(CELLS, 2).float() if kind == "noise": return torch.randn(CELLS, D, generator=g) * 0.2 - if kind == "knight": + if kind in ("knight", "knight_sym"): w = torch.zeros(CELLS, D) - sign = torch.randint(0, 2, (D, len(KNIGHT)), generator=g).float() * 2 - 1 + # knight_sym gives every channel ONE value across all eight offsets, so the pattern is a + # true D4 orbit and an invariant input can express it. knight varies the sign per offset, + # so the eight squares share a support but NOT a rule -- the control that keeps + # "invariants win" from being indistinguishable from "invariants always win". + sign = torch.randint(0, 2, (D, 1 if kind == "knight_sym" else len(KNIGHT)), + generator=g).float() * 2 - 1 for c in range(D): for m, (dx, dy) in enumerate(KNIGHT): - w[(dy + R) * G + (dx + R), c] = sign[c, m] + w[(dy + R) * G + (dx + R), c] = sign[c, 0 if kind == "knight_sym" else m] return w if kind == "highfreq": kfreq = 1.5 @@ -88,6 +95,31 @@ def gabor_kernel(sigma: float = 3.0, seed: int = 0, kfreq: float = 0.35, return env * torch.cos(r @ k.T + phi) +class InvariantCPPN(nn.Module): + """The CPPN over D4 invariants of the displacement instead of the displacement itself. + + The knight null in `sharp.md` says nothing here induces a symmetry group from partial + support. This asks the other question: the CPPN sees raw r_ij, and has no reason to know + that (1,2) and (-2,-1) are the same law -- they are two different points of the plane. + Canonicalising to (min|dx|,max|dy|) collapses the square's eight symmetries to one orbit, + and the knight's eight squares become a single input. + + STATED PLAINLY BECAUSE A CRITIC WILL SAY IT: this does not sneak the held-out cells into + training. It hands the model the CLAIM that those cells are equivalent to ones it did see. + The experiment measures whether that claim, when it is true of the domain, converts unseen + displacements into seen ones -- and the `knight` teacher, whose eight squares share a + support but not a value, is the control for when the claim is FALSE. + """ + def __init__(self, cppn: nn.Module): + super().__init__() + self.cppn = cppn + + def forward(self, r, edge_onehot, context): + a = r.abs() + inv = torch.stack([a.min(-1).values, a.max(-1).values], dim=-1) + return self.cppn(inv, edge_onehot, context) + + class TableKernel(nn.Module): """One weight vector per discrete displacement: a GNN with one edge type per relation. @@ -114,6 +146,12 @@ def make_model(arm: str, seed: int, omega: float = 1.0) -> nn.Module: rp = RelationalPerceptron(ATTR, 2, 1, 2, hidden_dim=D, cppn_hidden=32, omega=omega) if arm.startswith("table"): 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 != "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. + raise ValueError(f"unknown arm {arm!r}") return nn.ModuleDict({"rp": rp, "out": nn.Linear(D, D)}) @@ -307,7 +345,7 @@ def main(): ap.add_argument("--omega", type=float, default=1.0) ap.add_argument("--kfreq", type=float, default=0.35, help="the DOMAIN's spatial frequency") ap.add_argument("--teacher", default="smooth", - choices=["smooth", "highfreq", "knight", "noise"]) + choices=["smooth", "highfreq", "knight", "knight_sym", "noise"]) ap.add_argument("--out", default="results/unseen.json") args = ap.parse_args()