feat: vary kernel sharpness and hold-out structure -- both readings change
Four teacher families on one axis (how predictable the kernel is from its neighbours): smooth, high-frequency, a rule-generated sparse knight, and iid noise as the negative control, which is asserted to have neighbour correlation below 0.2 where the smooth teacher's is above 0.8. The knight teacher forced a new hold-out: most of its cells are exactly zero, so withholding uniformly asks nothing and the floor collapses. --holdout support withholds cells the kernel uses, closed under negation since a pair contributes r and -r. Under it the CPPN beats a lookup plus blur 4.4x on smooth and 3.0x on high-frequency, 6/6 seeds, reversing the earlier headline. And on the knight nothing generalises at all -- both arms at or above the floor. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
This commit is contained in:
7 files changed
+279
-34
No files matched your search
@@ -51,7 +51,7 @@ from unseen import ATTR, CELLS, D, G, R, cell_of
|
|||||||
# other half is trained, so the entry it reads has seen data. Only B>=4 withholds it honestly.
|
# other half is trained, so the entry it reads has seen data. Only B>=4 withholds it honestly.
|
||||||
# Stated here rather than corrected for: correcting it would mean a different box per arm, and
|
# Stated here rather than corrected for: correcting it would mean a different box per arm, and
|
||||||
# then the arms would no longer be answering the same question.
|
# then the arms would no longer be answering the same question.
|
||||||
HELD = (0.0, 0.5)
|
HELD = (0.0, 0.5) # overridden by --held; see main()
|
||||||
|
|
||||||
|
|
||||||
def psi_offsets() -> torch.Tensor:
|
def psi_offsets() -> torch.Tensor:
|
||||||
@@ -236,8 +236,16 @@ def main():
|
|||||||
ap.add_argument("--omega", type=float, default=2.0)
|
ap.add_argument("--omega", type=float, default=2.0)
|
||||||
ap.add_argument("--steps", type=int, default=2500)
|
ap.add_argument("--steps", type=int, default=2500)
|
||||||
ap.add_argument("--seeds", default="0,1,2,3,4,5")
|
ap.add_argument("--seeds", default="0,1,2,3,4,5")
|
||||||
|
ap.add_argument("--held", default="0.0,0.5",
|
||||||
|
help="the withheld psi box. The interior default is the easy case: every "
|
||||||
|
"bin around it is trained. A corner box (0.5,1.0) leaves neighbours "
|
||||||
|
"on two sides only, which is what sharp.md showed the offset axis was "
|
||||||
|
"sensitive to -- the earlier conclusion there flipped with the "
|
||||||
|
"hold-out structure, so this axis gets the same check.")
|
||||||
ap.add_argument("--out", default="results/psi.json")
|
ap.add_argument("--out", default="results/psi.json")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
global HELD
|
||||||
|
HELD = tuple(float(x) for x in args.held.split(","))
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for arm in args.arms.split(","):
|
for arm in args.arms.split(","):
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# psi as a continuous kernel axis — the deciding test, and it decided against
|
# psi as a continuous kernel axis — the deciding test, and it decided against
|
||||||
|
|
||||||
|
> **SUPERSEDED IN PART by `sharp.md`.** The withheld box here is interior, with trained bins on
|
||||||
|
> all four sides, which is the easy case. Re-run with a corner box the CPPN goes from losing to
|
||||||
|
> beating the same-resolution table on 5/6 seeds and tying the one with 320x its parameters.
|
||||||
|
|
||||||
|
|
||||||
After `unseen.md` and `scale.md` the RP's distinguishing claim against a lookup had narrowed to
|
After `unseen.md` and `scale.md` the RP's distinguishing claim against a lookup had narrowed to
|
||||||
one thing: **parameter compression where the relation space cannot be enumerated.** psi is the
|
one thing: **parameter compression where the relation space cannot be enumerated.** psi is the
|
||||||
only genuinely continuous axis this architecture has — a table over (offset × valence × arousal)
|
only genuinely continuous axis this architecture has — a table over (offset × valence × arousal)
|
||||||
|
|||||||
+25
-18
@@ -131,31 +131,38 @@ The RP earns its cost where at least one of these is load-bearing:
|
|||||||
And it is the wrong tool where the law is anchored to absolute position (row 4), which has to be
|
And it is the wrong tool where the law is anchored to absolute position (row 4), which has to be
|
||||||
patched in through attributes.
|
patched in through attributes.
|
||||||
|
|
||||||
## Where the argument stands, after three deciding experiments
|
## Where the argument stands
|
||||||
|
|
||||||
Rows 1 and 2 are **shared with any GNN** — measured, not assumed (`scale.md`). Row 5, identity in
|
Rows 1 and 2 are **shared with any GNN** — measured, not assumed (`scale.md`). Row 5, identity in
|
||||||
the kernel, is the same statement as indexing a lookup by type as well as by offset. Row 3,
|
the kernel, is the same statement as indexing a lookup by type as well as by offset.
|
||||||
generating weights from geometry, is real but bounded: where relations are few and discrete, a
|
|
||||||
table plus a blur competes (`unseen.md`). ψ was the last place a lookup could not be built, and
|
|
||||||
`psi.md` found that it can: bin it and interpolate, and it matches the CPPN on 6 seeds of 6.
|
|
||||||
|
|
||||||
**Nothing measured in this project distinguishes the RP from a lookup in what it can represent.**
|
Row 3 went through a full reversal and the reversal is the interesting part. Measured against
|
||||||
What distinguishes it is what that representation costs: 720 parameters against 57,600 and
|
hold-outs that withheld cells uniformly (`unseen.md`) or a psi box with trained bins on all four
|
||||||
230,400 at equal accuracy. And the shape of that cost is the part worth keeping — the table
|
sides (`psi.md`), a lookup plus a neighbour average matched the CPPN and the conclusion was that
|
||||||
scales as B^(continuous axes) × cells × channels while the CPPN is constant, so the advantage is
|
nothing distinguishes the RP in what it can *represent*. `sharp.md` withheld cells the kernel
|
||||||
80-320× at two continuous axes and grows exponentially with the number of them.
|
actually **uses**, and the CPPN wins 4.4x on a smooth teacher and 3.0x on a high-frequency one,
|
||||||
|
6 seeds out of 6 in both; on a corner psi box it goes from losing to winning 5/6. One sentence
|
||||||
|
covers every hold-out tried: **a blur wins where the kernel is near zero, the CPPN wins where the
|
||||||
|
kernel carries signal.**
|
||||||
|
|
||||||
That is a smaller claim than the one the project was carrying, and it is the one the evidence
|
So the RP does have a representational advantage over a lookup, it is not large, and it lives
|
||||||
supports. It is also not nothing: a parameterisation that is exponentially smaller in the number
|
exactly where interpolation is hard — high-frequency content, and withheld regions that carry
|
||||||
of continuous inputs is a real property, now quantified instead of assumed.
|
signal or sit at a boundary. On top of that sits the cost argument, which is unaffected: the
|
||||||
|
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.
|
||||||
|
|
||||||
## What is open, in order
|
## What is open, in order
|
||||||
|
|
||||||
1. **A kernel that is NOT smooth in its inputs.** Every measurement here used a smooth teacher,
|
1. **Rule inference on a sparse support.** The knight null is one symmetry group, one sparse
|
||||||
and smoothness is exactly what lets the table's blur compete. A dependence that is
|
family, one architecture. It says the group was not inferred here, not that none can be. This
|
||||||
discontinuous or high-frequency — in ψ, or in the relation, where a knight's L is eight
|
is the sharpest open question the project has and it is the one chess kept implying it had
|
||||||
isolated cells — is where interpolation should fail and the CPPN should not. This is now the
|
answered.
|
||||||
sharpest open question, and the deferred capacity sweep is its sibling along the offset axis.
|
|
||||||
2. **Kernel capacity and interference.** How many distinct kernels fit before they collide, and
|
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
|
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
|
sweep makes similarity an independent variable instead of an accident of chess. Deliberately
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# Where a blur competes and where it does not — and one prediction that failed
|
||||||
|
|
||||||
|
Every null in `unseen.md`, `scale.md` and `psi.md` was measured against a **smooth** teacher, and
|
||||||
|
smoothness is exactly what lets a lookup plus a neighbour average compete. Those files concluded
|
||||||
|
that nothing distinguishes the RP from a lookup in what it can represent. This one varies the
|
||||||
|
smoothness and the hold-out structure, and **that conclusion does not survive**: it was an
|
||||||
|
artefact of hold-outs that made interpolation easy.
|
||||||
|
|
||||||
|
It also contains a prediction of mine that was falsified, which is the more useful half.
|
||||||
|
|
||||||
|
## Four teacher families, one axis: how predictable the kernel is from its neighbours
|
||||||
|
|
||||||
|
- `smooth` — band-limited Gabor. The replication.
|
||||||
|
- `highfreq` — the same at a frequency near the grid's resolution. Structured, not smooth.
|
||||||
|
- `knight` — 1 on the eight L-offsets, 0 elsewhere. Not smooth, and **rule-generated**. This is
|
||||||
|
`chess_reach.md`'s knight asked as a mechanism question.
|
||||||
|
- `noise` — iid per cell. **The negative control.** Without it, "the CPPN wins on non-smooth
|
||||||
|
kernels" cannot be told apart from "the setup favours the CPPN". Asserted to have neighbour
|
||||||
|
correlation < 0.2 where the smooth teacher's is > 0.8.
|
||||||
|
|
||||||
|
The hold-out also changed, and the change was forced by the knight teacher: most of its 225 cells
|
||||||
|
are exactly zero, so a uniform hold-out withholds cells carrying no signal, the target's variance
|
||||||
|
there is ~0 and the floor collapses. **`--holdout support` withholds cells the kernel actually
|
||||||
|
uses.** For the knight that is: *having seen six of the eight L-squares, can it infer the other
|
||||||
|
two?* The set is closed under negation, since a pair contributes r and −r.
|
||||||
|
|
||||||
|
## Result, 6 seeds
|
||||||
|
|
||||||
|
```
|
||||||
|
teacher omega arm seen unseen floor verdict
|
||||||
|
smooth 2 rp 0.00007 0.00007 0.01533
|
||||||
|
smooth 2 table 0.00005 0.00563 0.01533 +0.00556 +/- 0.00079 6/6 rp
|
||||||
|
smooth 2 table_interp 0.00005 0.00031 0.01533 +0.00024 +/- 0.00007 6/6 rp
|
||||||
|
highfreq 8 rp 0.00057 0.00126 0.01512
|
||||||
|
highfreq 8 table_interp 0.00015 0.00376 0.01512 +0.00251 +/- 0.00050 6/6 rp
|
||||||
|
knight 2 rp 0.00117 0.02359 0.02228 both AT OR ABOVE the floor
|
||||||
|
knight 2 table_interp 0.00002 0.02248 0.02228 -0.00112 +/- 0.00051 0/6 rp
|
||||||
|
noise 2 rp 0.00087 0.00157 0.00221 control: nothing generalises
|
||||||
|
noise 2 table_interp 0.00007 0.00150 0.00221 -0.00007 +/- 0.00007 2/6 rp
|
||||||
|
```
|
||||||
|
|
||||||
|
And psi re-checked with a corner box instead of an interior one, because if the hold-out
|
||||||
|
structure flipped the answer on the offset axis it could not be left untested on this one:
|
||||||
|
|
||||||
|
```
|
||||||
|
psi hold-out arm seen unseen floor params verdict
|
||||||
|
interior [0,0.5]^2 rp 0.00032 0.00038 0.00656 720
|
||||||
|
interior table_4_interp 0.00022 0.00034 0.00656 57600 table better
|
||||||
|
CORNER [0.5,1.0]^2 rp 0.00032 0.00073 0.00729 720
|
||||||
|
CORNER table_4_interp 0.00023 0.00086 0.00729 57600 +0.00013 5/6 rp
|
||||||
|
CORNER table_8_interp 0.00024 0.00069 0.00729 230400 -0.00004 ambiguous
|
||||||
|
```
|
||||||
|
|
||||||
|
## What this changes
|
||||||
|
|
||||||
|
**1. The CPPN does have a representational advantage, and it appears exactly where interpolation
|
||||||
|
is hard.** On the support hold-out it beats a lookup-plus-blur 4.4x on smooth and 3.0x on
|
||||||
|
high-frequency kernels, 6 seeds out of 6 in both. On the corner psi box it goes from losing to
|
||||||
|
winning 5/6 against the same-resolution table and tying the one with 320x its parameters.
|
||||||
|
|
||||||
|
**2. The earlier conclusion was an artefact of easy hold-outs, and this retro-explains the band
|
||||||
|
result rather than contradicting it.** `unseen.md`'s random hold-out withheld cells uniformly,
|
||||||
|
most of them peripheral, where the Gabor envelope has decayed and predicting ~0 is nearly
|
||||||
|
correct; its band hold-out was measured to have a kernel 4x weaker inside it and the RP lost
|
||||||
|
there 0/8. One sentence covers all three: **a blur wins where the kernel is near zero, the CPPN
|
||||||
|
wins where the kernel carries signal.** `unseen.md` and `psi.md` are not withdrawn — they are
|
||||||
|
correct for what they withheld — but their headline reading is superseded by this file.
|
||||||
|
|
||||||
|
**3. My prediction about the knight was wrong, and nothing generalises there.** I predicted the
|
||||||
|
CPPN would win on a rule-generated sparse kernel because a neighbour average cannot recover an
|
||||||
|
isolated spike. The average indeed cannot — and neither can the CPPN. Both sit at or above the
|
||||||
|
floor (1.06 and 1.01 of it). Having seen six of the eight L-squares, **the symmetry group is not
|
||||||
|
inferred by anything here.**
|
||||||
|
|
||||||
|
That has a direct consequence for a result of ours. `chess_reach.md` measured the knight going
|
||||||
|
from exactly 0.000 to 0.758 when the piece type entered the kernel, on 8/8 seeds for 1.8% more
|
||||||
|
parameters. That result stands as what it is — the kernel can **represent** eight cells once it
|
||||||
|
is conditioned by identity. What it does not support is the reading that the organism learned
|
||||||
|
*how a knight moves*. Shown six of the eight squares it does not find the other two. It
|
||||||
|
memorised a shape it was shown in full; it did not acquire a rule.
|
||||||
|
|
||||||
|
**4. The negative control behaves.** On `noise` both arms sit at ~0.7 of the floor — the part of
|
||||||
|
the target recoverable without the withheld relation at all, through the self-message and the
|
||||||
|
readout — and neither beats the other outside noise. The setup can produce a null.
|
||||||
|
|
||||||
|
## What this does not establish
|
||||||
|
|
||||||
|
The support and random hold-outs differ in more than their principle: `support` withholds ~25% of
|
||||||
|
the cells the kernel uses (2 of 8 for the knight, a few dozen for the smooth teacher) while
|
||||||
|
`random` withheld 56 of 225 regardless of magnitude. The comparison between this file's smooth
|
||||||
|
row and `unseen.md`'s is therefore indicative, not paired. What is paired, and unanimous, is
|
||||||
|
`rp` against `table_interp` **within** each row here.
|
||||||
|
|
||||||
|
`omega` was fixed at 2 except for the high-frequency family, where 8 is reported because a
|
||||||
|
band-limited model cannot fit a high-frequency teacher and reporting only omega=2 would have
|
||||||
|
handicapped the CPPN on the one family built to need bandwidth. Both values were run for every
|
||||||
|
family and both are in the json.
|
||||||
|
|
||||||
|
The knight null is one sparse family with one symmetry group. It says the group was not inferred
|
||||||
|
here; it does not say no relational architecture can infer one.
|
||||||
|
|
||||||
|
## Reproduce
|
||||||
|
|
||||||
|
```
|
||||||
|
for t in smooth highfreq knight noise; do
|
||||||
|
uv run python unseen.py --teacher $t --holdout support --arms rp,table,table_interp \
|
||||||
|
--omega 2 --steps 2500 --seeds 0,1,2,3,4,5 --out results/sharp_${t}_w2.json
|
||||||
|
uv run python unseen.py --teacher $t --holdout support --arms rp,table_interp \
|
||||||
|
--omega 8 --steps 2500 --seeds 0,1,2,3,4,5 --out results/sharp_${t}_w8.json
|
||||||
|
done
|
||||||
|
uv run python psi.py --arms rp,table_4,table_4_interp,table_8_interp --held 0.5,1.0 \
|
||||||
|
--omega 2 --steps 2500 --seeds 0,1,2,3,4,5 --out results/psi_corner.json
|
||||||
|
```
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
# Can the kernel answer for a relation it never saw?
|
# Can the kernel answer for a relation it never saw?
|
||||||
|
|
||||||
|
> **SUPERSEDED IN PART by `sharp.md`.** The hold-outs here withhold cells regardless of whether
|
||||||
|
> the kernel carries signal there, and the band hold-out was measured to sit where the kernel is
|
||||||
|
> 4x weaker. Under a hold-out that withholds cells the kernel actually uses, the CPPN beats
|
||||||
|
> table+interp 4.4x on 6/6 seeds. The numbers below stand; the reading "there is no accuracy
|
||||||
|
> advantage" does not.
|
||||||
|
|
||||||
|
|
||||||
The property that separates the RP from a **GNN** rather than from a perceptron, and the one
|
The property that separates the RP from a **GNN** rather than from a perceptron, and the one
|
||||||
row of `rp_properties.md` that had no evidence at all. A GNN holds fixed weights per edge type
|
row of `rp_properties.md` that had no evidence at all. A GNN holds fixed weights per edge type
|
||||||
— a lookup with one entry per discrete relation. The CPPN computes weights from continuous
|
— a lookup with one entry per discrete relation. The CPPN computes weights from continuous
|
||||||
|
|||||||
@@ -89,3 +89,46 @@ def test_diffusion_reaches_every_held_cell_in_both_holdouts():
|
|||||||
w[~held] = 1.0
|
w[~held] = 1.0
|
||||||
unseen.fill_by_diffusion(w, held)
|
unseen.fill_by_diffusion(w, held)
|
||||||
assert (w[held] > 0).all() # no held cell was left stranded at its init
|
assert (w[held] > 0).all() # no held cell was left stranded at its init
|
||||||
|
|
||||||
|
|
||||||
|
def _support(kind, frac=0.25, seed=0):
|
||||||
|
W = unseen.gabor_kernel(seed=seed, kind=kind)
|
||||||
|
return unseen.holdout_cells("support", frac, seed, W), W
|
||||||
|
|
||||||
|
|
||||||
|
def test_support_holdout_is_closed_under_negation():
|
||||||
|
# A pair contributes r and -r. An asymmetric hold-out would leave pair_batch with nothing
|
||||||
|
# to evaluate and it would spin forever rather than fail.
|
||||||
|
for kind in ("smooth", "knight", "highfreq"):
|
||||||
|
held, _ = _support(kind)
|
||||||
|
for c in held.nonzero().flatten().tolist():
|
||||||
|
dy, dx = divmod(c, unseen.G)
|
||||||
|
assert held[(2 * unseen.R - dy) * unseen.G + (2 * unseen.R - dx)]
|
||||||
|
|
||||||
|
|
||||||
|
def test_support_holdout_only_withholds_cells_that_carry_signal():
|
||||||
|
# The whole reason this hold-out exists: withholding a zero cell of the knight kernel asks
|
||||||
|
# nothing, the floor collapses, and the arms tie at a number that means nothing.
|
||||||
|
for kind in ("smooth", "knight"):
|
||||||
|
held, W = _support(kind)
|
||||||
|
mag = W.abs().mean(1)
|
||||||
|
assert (mag[held] > 0.2 * mag.max()).all()
|
||||||
|
|
||||||
|
|
||||||
|
def test_knight_kernel_lives_on_exactly_the_eight_l_squares():
|
||||||
|
W = unseen.gabor_kernel(kind="knight", seed=0)
|
||||||
|
live = (W.abs().mean(1) > 0).nonzero().flatten().tolist()
|
||||||
|
expect = {(dy + unseen.R) * unseen.G + (dx + unseen.R) for dx, dy in unseen.KNIGHT}
|
||||||
|
assert set(live) == expect and len(expect) == 8
|
||||||
|
|
||||||
|
|
||||||
|
def test_noise_teacher_has_no_neighbour_structure():
|
||||||
|
# The negative control is only a control if it really is unpredictable from neighbours:
|
||||||
|
# correlation between a cell and its right-hand neighbour should be near zero, where the
|
||||||
|
# smooth teacher's is high.
|
||||||
|
def neighbour_corr(kind):
|
||||||
|
W = unseen.gabor_kernel(seed=0, kind=kind).view(unseen.G, unseen.G, -1)
|
||||||
|
a, b = W[:, :-1].flatten(), W[:, 1:].flatten()
|
||||||
|
return abs(float(torch.corrcoef(torch.stack([a, b]))[0, 1]))
|
||||||
|
assert neighbour_corr("smooth") > 0.8
|
||||||
|
assert neighbour_corr("noise") < 0.2
|
||||||
@@ -48,15 +48,40 @@ def cell_of(r: torch.Tensor) -> torch.Tensor:
|
|||||||
return dy * G + dx
|
return dy * G + dx
|
||||||
|
|
||||||
|
|
||||||
def gabor_kernel(sigma: float = 3.0, seed: int = 0, kfreq: float = 0.35) -> torch.Tensor:
|
KNIGHT = [(1, 2), (2, 1), (-1, 2), (-2, 1), (1, -2), (2, -1), (-1, -2), (-2, -1)]
|
||||||
"""(CELLS, D) true kernel: a smooth, band-limited function of the displacement.
|
|
||||||
|
|
||||||
Smooth on purpose. A CPPN that cannot interpolate THIS has not failed a hard case, it has
|
|
||||||
failed the easy one -- which is what makes a null here worth recording.
|
def gabor_kernel(sigma: float = 3.0, seed: int = 0, kfreq: float = 0.35,
|
||||||
|
kind: str = "smooth") -> torch.Tensor:
|
||||||
|
"""(CELLS, D) true kernel. `kind` varies HOW PREDICTABLE IT IS FROM ITS NEIGHBOURS.
|
||||||
|
|
||||||
|
Every null in unseen.md, scale.md and psi.md was measured against a smooth teacher, and
|
||||||
|
smoothness is exactly what lets a lookup plus a blur compete. These four families vary that
|
||||||
|
and nothing else:
|
||||||
|
|
||||||
|
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 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.
|
||||||
|
noise iid per cell. THE CONTROL: nothing should generalise here, the CPPN included.
|
||||||
|
Without it, "the CPPN wins on non-smooth kernels" cannot be told apart from
|
||||||
|
"the setup favours the CPPN".
|
||||||
"""
|
"""
|
||||||
g = torch.Generator().manual_seed(seed)
|
g = torch.Generator().manual_seed(seed)
|
||||||
ys, xs = torch.meshgrid(torch.arange(-R, R + 1), torch.arange(-R, R + 1), indexing="ij")
|
ys, xs = torch.meshgrid(torch.arange(-R, R + 1), torch.arange(-R, R + 1), indexing="ij")
|
||||||
r = torch.stack([xs, ys], -1).reshape(CELLS, 2).float()
|
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":
|
||||||
|
w = torch.zeros(CELLS, D)
|
||||||
|
sign = torch.randint(0, 2, (D, 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]
|
||||||
|
return w
|
||||||
|
if kind == "highfreq":
|
||||||
|
kfreq = 1.5
|
||||||
k = torch.randn(D, 2, generator=g) * kfreq # spatial frequencies of the domain
|
k = torch.randn(D, 2, generator=g) * kfreq # spatial frequencies of the domain
|
||||||
phi = torch.rand(D, generator=g) * 6.2831853
|
phi = torch.rand(D, generator=g) * 6.2831853
|
||||||
env = torch.exp(-(r * r).sum(-1) / (2 * sigma * sigma))[:, None]
|
env = torch.exp(-(r * r).sum(-1) / (2 * sigma * sigma))[:, None]
|
||||||
@@ -120,21 +145,34 @@ def fill_by_diffusion(w: torch.Tensor, held: torch.Tensor) -> None:
|
|||||||
w.copy_(grid.view(CELLS, D))
|
w.copy_(grid.view(CELLS, D))
|
||||||
|
|
||||||
|
|
||||||
def teacher(seed: int, kfreq: float = 0.35) -> nn.Module:
|
def teacher(seed: int, kfreq: float = 0.35, kind: str = "smooth") -> nn.Module:
|
||||||
"""kfreq is the DOMAIN's length scale, not the model's. Sweeping it against the CPPN's omega
|
"""kfreq is the DOMAIN's length scale, not the model's. Sweeping it against the CPPN's omega
|
||||||
is what separates a knob that wants calibrating per domain from a defect in the
|
is what separates a knob that wants calibrating per domain from a defect in the
|
||||||
architecture: if the best omega tracks kfreq, core.py's own comment was right all along and
|
architecture: if the best omega tracks kfreq, core.py's own comment was right all along and
|
||||||
nobody had calibrated it; if it sits still, the default can simply be corrected."""
|
nobody had calibrated it; if it sits still, the default can simply be corrected."""
|
||||||
m = make_model("table", seed + 1000)
|
m = make_model("table", seed + 1000)
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
m["rp"].cppn.w.copy_(gabor_kernel(seed=seed, kfreq=kfreq))
|
m["rp"].cppn.w.copy_(gabor_kernel(seed=seed, kfreq=kfreq, kind=kind))
|
||||||
for p in m.parameters():
|
for p in m.parameters():
|
||||||
p.requires_grad_(False)
|
p.requires_grad_(False)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
def holdout_cells(kind: str, frac: float, seed: int) -> torch.Tensor:
|
def holdout_cells(kind: str, frac: float, seed: int, W: torch.Tensor | None = None
|
||||||
"""(CELLS,) bool, True = withheld from training."""
|
) -> torch.Tensor:
|
||||||
|
"""(CELLS,) bool, True = withheld from training.
|
||||||
|
|
||||||
|
`support` exists because the knight teacher broke the other two. Most of its 225 cells are
|
||||||
|
exactly zero, so a hold-out drawn uniformly withholds cells that carry no signal, the
|
||||||
|
target's variance there is ~0, and the floor collapses -- the question becomes vacuous
|
||||||
|
rather than hard. `support` withholds cells the kernel actually uses, which is the same
|
||||||
|
question for every family: having seen most of where the law lives, can the model infer the
|
||||||
|
rest? For the knight that is "seen six of the eight L-squares, infer the other two", and a
|
||||||
|
neighbour average cannot, because an isolated spike's neighbours are zero.
|
||||||
|
|
||||||
|
The set is closed under negation: a pair contributes displacements r and -r, so an
|
||||||
|
asymmetric hold-out would have no evaluable pairs.
|
||||||
|
"""
|
||||||
ys, xs = torch.meshgrid(torch.arange(-R, R + 1), torch.arange(-R, R + 1), indexing="ij")
|
ys, xs = torch.meshgrid(torch.arange(-R, R + 1), torch.arange(-R, R + 1), indexing="ij")
|
||||||
centre = R * G + R # r = 0: every entity messages itself, so it is in every configuration
|
centre = R * G + R # r = 0: every entity messages itself, so it is in every configuration
|
||||||
if kind == "random":
|
if kind == "random":
|
||||||
@@ -145,6 +183,24 @@ def holdout_cells(kind: str, frac: float, seed: int) -> torch.Tensor:
|
|||||||
m[idx] = True
|
m[idx] = True
|
||||||
m[centre] = False
|
m[centre] = False
|
||||||
return m
|
return m
|
||||||
|
if kind == "support":
|
||||||
|
assert W is not None, "support hold-out needs the teacher's kernel"
|
||||||
|
mag = W.abs().mean(1)
|
||||||
|
live = (mag > 0.2 * mag.max()).nonzero().flatten().tolist()
|
||||||
|
g = torch.Generator().manual_seed(seed)
|
||||||
|
order = torch.randperm(len(live), generator=g).tolist()
|
||||||
|
m = torch.zeros(CELLS, dtype=torch.bool)
|
||||||
|
want = max(2, int(round(frac * len(live))))
|
||||||
|
for idx in order:
|
||||||
|
c = live[idx]
|
||||||
|
if c == centre:
|
||||||
|
continue
|
||||||
|
dy, dx = divmod(c, G)
|
||||||
|
neg = (2 * R - dy) * G + (2 * R - dx) # the cell for -r
|
||||||
|
m[c] = m[neg] = True
|
||||||
|
if int(m.sum()) >= want:
|
||||||
|
break
|
||||||
|
return m
|
||||||
if kind == "band":
|
if kind == "band":
|
||||||
d = (xs.abs().float() + ys.abs().float()).reshape(-1) # L1 radius
|
d = (xs.abs().float() + ys.abs().float()).reshape(-1) # L1 radius
|
||||||
lo = torch.quantile(d, 1.0 - frac - 0.12)
|
lo = torch.quantile(d, 1.0 - frac - 0.12)
|
||||||
@@ -214,9 +270,11 @@ def floor_mse(tea, data) -> float:
|
|||||||
|
|
||||||
|
|
||||||
def one_seed(arm: str, kind: str, frac: float, steps: int, seed: int, omega: float = 1.0,
|
def one_seed(arm: str, kind: str, frac: float, steps: int, seed: int, omega: float = 1.0,
|
||||||
kfreq: float = 0.35) -> dict:
|
kfreq: float = 0.35, teacher_kind: str = "smooth") -> dict:
|
||||||
tea = teacher(seed, kfreq)
|
# `kind` is the HOLD-OUT structure and `teacher_kind` is the kernel family. They are
|
||||||
held = holdout_cells(kind, frac, seed)
|
# different axes and were briefly the same identifier, which Python caught.
|
||||||
|
tea = teacher(seed, kfreq, teacher_kind)
|
||||||
|
held = holdout_cells(kind, frac, seed, gabor_kernel(seed=seed, kfreq=kfreq, kind=teacher_kind))
|
||||||
gen = torch.Generator().manual_seed(seed)
|
gen = torch.Generator().manual_seed(seed)
|
||||||
model = make_model(arm, seed, omega)
|
model = make_model(arm, seed, omega)
|
||||||
opt = torch.optim.Adam(model.parameters(), lr=3e-3)
|
opt = torch.optim.Adam(model.parameters(), lr=3e-3)
|
||||||
@@ -233,7 +291,7 @@ def one_seed(arm: str, kind: str, frac: float, steps: int, seed: int, omega: flo
|
|||||||
ev = torch.Generator().manual_seed(seed + 5000)
|
ev = torch.Generator().manual_seed(seed + 5000)
|
||||||
seen = pair_batch(held, False, ev)
|
seen = pair_batch(held, False, ev)
|
||||||
unseen = pair_batch(held, True, ev)
|
unseen = pair_batch(held, True, ev)
|
||||||
return {"seed": seed, "arm": arm, "omega": omega, "kfreq": kfreq, "seen": evaluate(model, tea, seen),
|
return {"seed": seed, "arm": arm, "omega": omega, "kfreq": kfreq, "teacher": teacher_kind, "seen": evaluate(model, tea, seen),
|
||||||
"unseen": evaluate(model, tea, unseen),
|
"unseen": evaluate(model, tea, unseen),
|
||||||
"floor_seen": floor_mse(tea, seen), "floor_unseen": floor_mse(tea, unseen),
|
"floor_seen": floor_mse(tea, seen), "floor_unseen": floor_mse(tea, unseen),
|
||||||
"n_held": int(held.sum())}
|
"n_held": int(held.sum())}
|
||||||
@@ -241,25 +299,29 @@ def one_seed(arm: str, kind: str, frac: float, steps: int, seed: int, omega: flo
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("--holdout", default="random", choices=["random", "band"])
|
ap.add_argument("--holdout", default="random", choices=["random", "band", "support"])
|
||||||
ap.add_argument("--frac", type=float, default=0.25)
|
ap.add_argument("--frac", type=float, default=0.25)
|
||||||
ap.add_argument("--steps", type=int, default=1500)
|
ap.add_argument("--steps", type=int, default=1500)
|
||||||
ap.add_argument("--seeds", default="0,1,2,3,4,5,6,7")
|
ap.add_argument("--seeds", default="0,1,2,3,4,5,6,7")
|
||||||
ap.add_argument("--arms", default="rp,table")
|
ap.add_argument("--arms", default="rp,table")
|
||||||
ap.add_argument("--omega", type=float, default=1.0)
|
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("--kfreq", type=float, default=0.35, help="the DOMAIN's spatial frequency")
|
||||||
|
ap.add_argument("--teacher", default="smooth",
|
||||||
|
choices=["smooth", "highfreq", "knight", "noise"])
|
||||||
ap.add_argument("--out", default="results/unseen.json")
|
ap.add_argument("--out", default="results/unseen.json")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for arm in args.arms.split(","):
|
for arm in args.arms.split(","):
|
||||||
for s in (int(x) for x in args.seeds.split(",")):
|
for s in (int(x) for x in args.seeds.split(",")):
|
||||||
rows.append(one_seed(arm, args.holdout, args.frac, args.steps, s, args.omega, args.kfreq))
|
rows.append(one_seed(arm, args.holdout, args.frac, args.steps, s, args.omega, args.kfreq,
|
||||||
|
args.teacher))
|
||||||
r = rows[-1]
|
r = rows[-1]
|
||||||
print(f"{arm:6s} seed {s} seen {r['seen']:.5f} unseen {r['unseen']:.5f}"
|
print(f"{arm:6s} seed {s} seen {r['seen']:.5f} unseen {r['unseen']:.5f}"
|
||||||
f" floor {r['floor_unseen']:.5f}", flush=True)
|
f" floor {r['floor_unseen']:.5f}", flush=True)
|
||||||
|
|
||||||
print(f"\n{args.holdout} hold-out, frac={args.frac}, omega={args.omega}, {rows[0]['n_held']}/{CELLS} cells")
|
print(f"\n{args.teacher} teacher, {args.holdout} hold-out, frac={args.frac}, "
|
||||||
|
f"omega={args.omega}, {rows[0]['n_held']}/{CELLS} cells")
|
||||||
print(f"{'arm':6s} {'seen':>9s} {'unseen':>9s} {'floor':>9s} unseen/floor")
|
print(f"{'arm':6s} {'seen':>9s} {'unseen':>9s} {'floor':>9s} unseen/floor")
|
||||||
for arm in args.arms.split(","):
|
for arm in args.arms.split(","):
|
||||||
a = [r for r in rows if r["arm"] == arm]
|
a = [r for r in rows if r["arm"] == arm]
|
||||||
|
|||||||
Reference in new issue
Block a user