feat: omega curve and unseen-N, the two steps before psi
omega.md: a plateau at [1,4] that does not track the domain across a 4.7x range, so the bandwidth is a knob that was set wrong rather than a defect to design around. omega=8 is an optimisation cliff, not a mis-tune. The project default of 10 is outside the plateau. scale.md: one parameter set works at an entity count it never trained on -- trained on N<=16 it beats the oracle at N=32 -- and a lookup table does it too. Read against an oracle because the mse/floor ratio is not comparable across N, which is asserted as a test rather than claimed in prose. The cost runs large->small only, at 2.28x, which makes it the pooling's 1/deg dilution rather than a degree-distribution shift. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HCydQraDSoZ9WoTm2v23Eb
This commit is contained in:
8 files changed
+467
-19
No files matched your search
@@ -0,0 +1,124 @@
|
||||
"""One parameter set, an entity count it never trained on.
|
||||
|
||||
Row 1 of `rp_properties.md`, second half. That the RP is *defined* at any N is structural and
|
||||
already asserted in the library's tests; a fixed-weight layer is not worse there, it has no
|
||||
input dimension to use. What is not established is whether it still WORKS at an N it never saw,
|
||||
and defined is not competent.
|
||||
|
||||
THE TABLE ARM IS HERE ON PURPOSE. A lookup kernel generalises over N for the same reason the
|
||||
CPPN does -- neither has a parameter tied to the entity count. If it holds up, this property
|
||||
separates the RP from a perceptron and NOT from a GNN, which is what the property card already
|
||||
claims and what should be measured rather than argued.
|
||||
|
||||
THE CONFOUND THIS IS BUILT TO SEPARATE. `h_i` is a mean over neighbours, so raising N raises the
|
||||
degree and changes the pooled statistics. Degradation at large N could be that, not a failure to
|
||||
generalise over entity count. Hence the reverse direction: train large and evaluate small. A
|
||||
failure in BOTH directions is about the degree distribution shifting; a failure in one is about
|
||||
the direction it was asked to extrapolate.
|
||||
|
||||
MEASUREMENT NOTE, found in the smoke run and worth more than the run that found it. Dividing by
|
||||
a per-N floor does NOT make the axis comparable. `y_i` is a mean over neighbours, so raising N
|
||||
averages more terms, the target's variance falls, the floor falls with it, and the ratio climbs
|
||||
even for a model that is doing fine. The ratio is reported because it is informative WITHIN one
|
||||
N, across arms -- never read down a column as a trend.
|
||||
|
||||
What makes the axis comparable is an ORACLE, which is this repo's rule anyway: a model trained
|
||||
over the FULL range [2,32] and evaluated at the same N. Degradation from an unseen entity count
|
||||
is then (model trained on [2,16]) against (model trained on [2,32]) at the same N, and every
|
||||
N-dependent difficulty cancels. Three runs, compared in `analyse_scale.py`:
|
||||
|
||||
--train 2,16 forward: small seen, large unseen
|
||||
--train 17,32 reverse: large seen, small unseen
|
||||
--train 2,32 the oracle both are read against
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import statistics
|
||||
from pathlib import Path
|
||||
|
||||
import torch
|
||||
|
||||
from unseen import ATTR, D, make_model, run_model, teacher
|
||||
|
||||
|
||||
def configs(n: int, count: int, gen: torch.Generator):
|
||||
out = []
|
||||
for _ in range(count):
|
||||
c = torch.randint(0, 8, (n, 2), generator=gen).float()
|
||||
out.append((torch.randn(n, ATTR, generator=gen), c[None, :, :] - c[:, None, :],
|
||||
torch.ones(n, n)))
|
||||
return out
|
||||
|
||||
|
||||
def mixed_batch(lo: int, hi: int, gen: torch.Generator, size=24):
|
||||
out = []
|
||||
for _ in range(size):
|
||||
n = int(torch.randint(lo, hi + 1, (1,), generator=gen))
|
||||
out += configs(n, 1, gen)
|
||||
return out
|
||||
|
||||
|
||||
def evaluate(model, tea, data):
|
||||
with torch.no_grad():
|
||||
err = sum(((run_model(model, a, r, m) - run_model(tea, a, r, m)) ** 2).sum().item()
|
||||
for a, r, m in data)
|
||||
ys = torch.cat([run_model(tea, a, r, m) for a, r, m in data])
|
||||
n = sum(a.shape[0] * D for a, _, _ in data)
|
||||
return err / n, ((ys - ys.mean(0)) ** 2).mean().item()
|
||||
|
||||
|
||||
def one_seed(arm, lo, hi, evals, steps, seed, omega):
|
||||
tea = teacher(seed)
|
||||
gen = torch.Generator().manual_seed(seed)
|
||||
model = make_model(arm, seed, omega)
|
||||
opt = torch.optim.Adam(model.parameters(), lr=3e-3)
|
||||
for _ in range(steps):
|
||||
data = mixed_batch(lo, hi, gen)
|
||||
loss = sum(((run_model(model, a, r, m) - run_model(tea, a, r, m)) ** 2).mean()
|
||||
for a, r, m in data) / len(data)
|
||||
opt.zero_grad(); loss.backward(); opt.step()
|
||||
|
||||
ev = torch.Generator().manual_seed(seed + 5000)
|
||||
per_n = {}
|
||||
for n in evals:
|
||||
mse, floor = evaluate(model, tea, configs(n, 24, ev))
|
||||
per_n[n] = {"mse": mse, "floor": floor, "ratio": mse / floor}
|
||||
return {"seed": seed, "arm": arm, "omega": omega, "train_lo": lo, "train_hi": hi,
|
||||
"per_n": per_n}
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--train", default="2,16", help="lo,hi entity count seen in training")
|
||||
ap.add_argument("--evals", default="2,4,8,12,16,20,24,28,32")
|
||||
ap.add_argument("--arms", default="rp,table")
|
||||
ap.add_argument("--omega", type=float, default=1.0)
|
||||
ap.add_argument("--steps", type=int, default=2000)
|
||||
ap.add_argument("--seeds", default="0,1,2,3,4,5,6,7")
|
||||
ap.add_argument("--out", default="results/scale.json")
|
||||
args = ap.parse_args()
|
||||
|
||||
lo, hi = (int(x) for x in args.train.split(","))
|
||||
evals = [int(x) for x in args.evals.split(",")]
|
||||
rows = []
|
||||
for arm in args.arms.split(","):
|
||||
for s in (int(x) for x in args.seeds.split(",")):
|
||||
rows.append(one_seed(arm, lo, hi, evals, args.steps, s, args.omega))
|
||||
print(f"{arm:6s} seed {s} " + " ".join(
|
||||
f"N{n}:{rows[-1]['per_n'][n]['ratio']:.4f}" for n in evals), flush=True)
|
||||
|
||||
print(f"\ntrained on N in [{lo},{hi}], omega={args.omega} (mse / per-N floor)")
|
||||
print(f"{'arm':6s} " + " ".join(f"{('N' + str(n)) + ('*' if lo <= n <= hi else ''):>9s}"
|
||||
for n in evals))
|
||||
for arm in args.arms.split(","):
|
||||
a = [r for r in rows if r["arm"] == arm]
|
||||
print(f"{arm:6s} " + " ".join(
|
||||
f"{statistics.mean([r['per_n'][n]['ratio'] for r in a]):9.4f}" for n in evals))
|
||||
print("* = inside the training range")
|
||||
Path(args.out).write_text(json.dumps({"args": vars(args), "rows": rows}, indent=1))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user