feat: D4-invariant kernel input recovers the knight rule from partial support
InvariantCPPN canonicalises the displacement to (min|dx|, max|dy|), collapsing the square's eight symmetries to one orbit, plus a knight_sym teacher whose eight L-squares carry one value and are therefore a genuine D4 orbit. Trained on six of the eight, it recovers the other two at 0.4% of the floor on 6/6 seeds where the raw-displacement kernel sits above the floor. Two controls, both predicted beforehand: on a teacher whose eight squares share a support but not a value the invariance is worse than nothing, and on a smooth teacher with no D4 symmetry it costs 31x. The arm dispatch now raises on unknown names -- an edit had silently failed to land and rp_inv ran as plain rp, which looked like a null. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
This commit is contained in:
4 files changed
+186
-13
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user