Teacher changes the kernel's shape with psi (valence rotates the frequency, arousal widens the envelope), never its gain, guarded by a test checked against a teacher deliberately reduced to a gain. The CPPN answers for withheld psi at 1.18x its trained-psi error from 720 parameters. A binned table plus interpolation along psi matches it on 6 seeds of 6 using 57,600. Not a sample-budget artefact: the largest table at 4x the steps fits three times better and generalises not at all better. The bare tables' 19x failure is arithmetic -- their bin never saw gradient -- and is labelled as scale rather than evidence, which is why the interp arms exist at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
82 lines
3.1 KiB
Python
82 lines
3.1 KiB
Python
"""The withheld psi region is the experiment, and a leak would be silent as usual.
|
|
|
|
Plus the property that makes the experiment non-vacuous: the teacher's kernel must change SHAPE
|
|
with psi, not gain. A psi that only scaled the kernel would be satisfiable by any model with a
|
|
gain on its output, and every arm would pass for the wrong reason.
|
|
"""
|
|
import torch
|
|
|
|
import psi as P
|
|
|
|
|
|
def test_training_psi_never_lands_in_the_held_box():
|
|
gen = torch.Generator().manual_seed(0)
|
|
for *_, p in P.batch(False, gen, size=256):
|
|
assert not P.in_held(p)
|
|
|
|
|
|
def test_eval_psi_is_always_inside_the_held_box():
|
|
gen = torch.Generator().manual_seed(1)
|
|
for *_, p in P.batch(True, gen, size=128):
|
|
assert P.in_held(p)
|
|
|
|
|
|
def test_teacher_kernel_changes_shape_with_psi_not_only_gain():
|
|
# The same check the library makes for the CPPN's context input, applied to the teacher:
|
|
# if psi were a gain the ratio between two kernels would be constant.
|
|
tea = P.PsiTeacher(0)
|
|
a = tea.kernel(torch.tensor([-0.8, 0.0]))
|
|
b = tea.kernel(torch.tensor([0.8, 0.0]))
|
|
assert (b / (a + 1e-9)).std() > 1e-2
|
|
c = tea.kernel(torch.tensor([0.0, -0.9]))
|
|
d = tea.kernel(torch.tensor([0.0, 0.9]))
|
|
assert (d / (c + 1e-9)).std() > 1e-2 # arousal too, not just valence
|
|
|
|
|
|
def test_bins_partition_psi_and_the_box_aligns_at_b4():
|
|
t4 = P.BinnedTable(4)
|
|
lo, hi = P.HELD
|
|
inside = {t4.bin_of(torch.tensor([x, y]))
|
|
for x in (lo + 0.01, hi - 0.01) for y in (lo + 0.01, hi - 0.01)}
|
|
assert len(inside) == 1 # the held box is exactly one bin at B=4
|
|
outside = t4.bin_of(torch.tensor([-0.9, -0.9]))
|
|
assert outside not in inside
|
|
|
|
|
|
def test_table_1_ignores_psi_entirely():
|
|
# The floor arm: it must be unable to represent any psi dependence, or it is not a floor.
|
|
t = P.BinnedTable(1)
|
|
r = torch.randint(-3, 4, (3, 3, 2)).float()
|
|
a = t(r, None, torch.tensor([-0.9, -0.9]))
|
|
b = t(r, None, torch.tensor([0.9, 0.9]))
|
|
assert torch.equal(a, b)
|
|
|
|
|
|
def test_untrained_bins_are_exactly_the_ones_inside_the_box():
|
|
# At B=4 the withheld box is exactly one bin; at B=2 it is half of one, so nothing is
|
|
# wholly untrained and there is nothing for the control to fill. If this drifted, the
|
|
# interp arm would quietly be filling bins that had data.
|
|
assert int(P.untrained_bins(4).sum()) == 1
|
|
assert int(P.untrained_bins(8).sum()) == 4
|
|
assert int(P.untrained_bins(2).sum()) == 0
|
|
assert int(P.untrained_bins(1).sum()) == 0
|
|
|
|
|
|
def test_diffusion_fills_held_bins_only_from_trained_ones():
|
|
# Trained bins all hold 1, untrained hold 0: after filling, every bin must be 1. A 0 left
|
|
# anywhere means an untrained bin was used as a source.
|
|
t = P.BinnedTable(4)
|
|
held = P.untrained_bins(4)
|
|
t.w.data.fill_(1.0)
|
|
t.w.data[held] = 0.0
|
|
P.fill_bins_by_diffusion(t, held)
|
|
assert torch.allclose(t.w.data, torch.ones_like(t.w.data), atol=1e-6)
|
|
|
|
|
|
def test_diffusion_leaves_trained_bins_untouched():
|
|
t = P.BinnedTable(4)
|
|
held = P.untrained_bins(4)
|
|
before = t.w.data.clone()
|
|
P.fill_bins_by_diffusion(t, held)
|
|
assert torch.equal(t.w.data[~held], before[~held])
|