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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
This commit is contained in:
4 files changed
+226
-9
No files matched your search
@@ -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())}
|
||||
|
||||
Reference in new issue
Block a user