feat: unseen relations -- the one property that separates the RP from a GNN

A GNN holds fixed weights per edge type: a lookup with one entry per discrete
relation. The CPPN computes weights from geometry, so it has something to say
about a displacement absent from training. Every chess run trained and evaluated
on the same offset grid, so this had never been tested.

Student-teacher with an analytic Gabor kernel; held-out cells masked out of
training via the RP's own mask argument; evaluation always on pairs so seen and
unseen measure the same object. Eight seeds, two hold-out structures.

The property is real -- held-out error 1.28x seen error, lower on 3/8 seeds -- and
smaller than the framing assumed. The bare table fails by construction and is
labelled as scale, not evidence. Against a table plus neighbour diffusion the
CPPN wins interpolation 2x on 6/8 seeds and loses extrapolation on 8/8. At
omega=10, the default every chess run used, it is 17x worse and below the
smoothed table even on interpolation.

The boundary is the useful part: the diffusion control exists only because the
relation space was enumerable. Chess is exactly such a domain.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-09-07 17:02:46 -05:00
1 parent 79b0324537
commit 6c545fd035
5 files changed
+696

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
"""The held-out cells are the experiment. If one leaks into training, the result is decorative.
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 torch
import unseen
def _held(kind="random", frac=0.25, seed=0):
return unseen.holdout_cells(kind, frac, seed)
def test_training_masks_out_every_held_cell():
held = _held()
gen = torch.Generator().manual_seed(0)
for _a, r, mask in unseen.train_batch(held, gen, size=64):
assert not held[unseen.cell_of(r)][mask.bool()].any() # nothing held survives
assert (mask.bool() | held[unseen.cell_of(r)]).all() # nothing seen was dropped
def test_a_masked_pair_cannot_move_the_output():
# The mask is only meaningful if it actually severs the message. Perturb a masked
# neighbour's attributes and the receiver must not notice.
held = _held()
model = unseen.make_model("rp", 0)
gen = torch.Generator().manual_seed(3)
for a, r, mask in unseen.train_batch(held, gen, size=40):
if mask.min() == 1:
continue
i, j = (mask == 0).nonzero()[0].tolist()
a2 = a.clone(); a2[j] += 7.0
y0 = unseen.run_model(model, a, r, mask)
y1 = unseen.run_model(model, a2, r, mask)
assert torch.allclose(y0[i], y1[i], atol=1e-6)
return
raise AssertionError("no masked pair was generated")
def test_eval_pairs_are_wholly_seen_or_wholly_held():
held = _held()
gen = torch.Generator().manual_seed(1)
off = ~torch.eye(2, dtype=torch.bool)
for _a, r, _m in unseen.pair_batch(held, True, gen, size=32):
assert held[unseen.cell_of(r)][off].all()
for _a, r, _m in unseen.pair_batch(held, False, gen, size=32):
assert not held[unseen.cell_of(r)][off].any()
def test_centre_cell_is_never_held():
# r = 0 is every entity's message to itself, so it appears in every configuration. Holding
# it out would mask a pathway that has nothing to do with the relation under test.
centre = unseen.R * unseen.G + unseen.R
for kind in ("random", "band"):
for seed in range(4):
assert not _held(kind, 0.25, seed)[centre]
def test_both_holdouts_withhold_a_real_fraction():
for kind in ("random", "band"):
n = int(_held(kind, 0.25, 0).sum())
assert 0.15 * unseen.CELLS < n < 0.35 * unseen.CELLS
def test_table_kernel_matches_cppn_call_signature():
# The table arm is swapped into RelationalPerceptron in place, so a signature drift would
# show up as a confusing shape error inside the RP rather than here.
k = unseen.TableKernel()
r = torch.randint(-3, 4, (4, 4, 2)).float()
assert k(r, torch.ones(4, 4, 1), torch.zeros(2)).shape == (4, 4, unseen.D)
def test_diffusion_fills_only_from_trained_cells():
# The control is only a control if the filled values come from cells that actually saw
# gradient. Trained cells all hold 1, held cells hold 0 (their "init"): after filling,
# every held cell must be 1 -- a 0 anywhere means an untrained entry was used as a source.
held = _held()
w = torch.ones(unseen.CELLS, unseen.D)
w[held] = 0.0
unseen.fill_by_diffusion(w, held)
assert torch.allclose(w, torch.ones_like(w), atol=1e-6)
def test_diffusion_reaches_every_held_cell_in_both_holdouts():
for kind in ("random", "band"):
held = _held(kind)
w = torch.zeros(unseen.CELLS, unseen.D)
w[~held] = 1.0
unseen.fill_by_diffusion(w, held)
assert (w[held] > 0).all() # no held cell was left stranded at its init