"""Does one parameter set still WORK at an entity count it never trained on? Read against the ORACLE, never down the N axis. `y_i` is a mean over neighbours, so the target's variance falls as N rises and any error-over-floor ratio climbs with N for a model that is doing nothing wrong. The oracle -- trained over the full range [2,32] -- absorbs all of that: at each N, `forward / oracle` is the cost of never having seen that entity count, and nothing else. Both directions are reported. A cost in BOTH is the degree distribution shifting under the mean pooling; a cost in ONE is the extrapolation that was actually asked for. """ import json, statistics as st def load(tag, arm): rs = json.load(open(f"results/scale_{tag}.json"))["rows"] return [r for r in rs if r["arm"] == arm] def per_n(rows, n): return st.mean([r["per_n"][str(n)]["mse"] for r in rows]) def paired(a, b, n): d = [x["per_n"][str(n)]["mse"] - y["per_n"][str(n)]["mse"] for x, y in zip(a, b)] return st.mean(d), st.stdev(d) / len(d) ** 0.5, sum(1 for v in d if v > 0), len(d) NS = [2, 4, 8, 12, 16, 20, 24, 28, 32] for arm in ("rp", "table"): fwd, rev, orc = (load(t, arm) for t in ("forward", "reverse", "oracle")) print(f"\n{'=' * 78}\n{arm.upper()} raw MSE, and cost against the oracle trained on [2,32]\n{'=' * 78}") print(f"{'N':>4} {'fwd[2,16]':>10} {'rev[17,32]':>11} {'oracle':>10} " f"{'fwd/orc':>8} {'rev/orc':>8} trained on N?") for n in NS: f, r, o = per_n(fwd, n), per_n(rev, n), per_n(orc, n) tag = "fwd" if n <= 16 else "rev" print(f"{n:>4} {f:10.5f} {r:11.5f} {o:10.5f} {f / o:8.2f} {r / o:8.2f} {tag} only") print() for label, arms_, ns in (("forward, unseen N (17-32)", fwd, [20, 24, 28, 32]), ("reverse, unseen N (2-16)", rev, [2, 4, 8, 12])): ms = [paired(orc, arms_, n) for n in ns] tot = st.mean([m for m, _, _, _ in ms]) won = sum(w for _, _, w, _ in ms) print(f" {label}: mean cost over oracle {tot:+.5f} " f"{won}/{sum(k for _, _, _, k in ms)} seed-points worse than oracle")