Files
sim-numerics/analyze_order.py

107 lines
4.5 KiB
Python

"""Verdicts L1-L5 for PREREG 2026-09-21 slot 1, read off sweep_order.json.
Nothing here selects a winner by hunting: L1 is a PAIRED comparison inside each
(similarity, guard) cell, which is the only comparison the pre-registration licenses.
python -u analyze_order.py
"""
from __future__ import annotations
import json
import math
REF = {"APS_base": 2806, "APS_best": 2527, "CHA_best": 2683, "BOTH_best": 5511,
"falsepos": (127, 10560), "illinois": (153, 7045), "bisect": (153, 7530)}
def load():
with open("sweep_order.json", encoding="utf8") as fh:
return json.load(fh)
def key(r):
s = r["spec"]
return (s[1], s[2], s[3], s[8] if len(s) > 8 else "none")
def main():
res = load()
by = {key(r): r for r in res}
print("L1 PAIRED: does the measured order improve the FAR reading? "
"(the only licensed comparison)")
print(f"{'similarity':<11} {'guard':<9} {'APS none':>9} {'APS ord':>8} "
f"{'CHA none':>9} {'CHA ord':>8} {'solved n/o':>12}")
wins = losses = 0
for (sim, sc, gu, ex) in sorted(by):
if sc != "far" or ex != "none":
continue
a, b = by[(sim, sc, gu, "none")], by.get((sim, sc, gu, "order"))
if b is None:
continue
d = (a["APS"]["total"] + a["CHA"]["total"]) - (b["APS"]["total"] + b["CHA"]["total"])
wins += d > 0
losses += d < 0
print(f"{sim:<11} {gu:<9} {a['APS']['total']:9d} {b['APS']['total']:8d} "
f"{a['CHA']['total']:9d} {b['CHA']['total']:8d} "
f"{a['APS']['solved']}+{a['CHA']['solved']}/"
f"{b['APS']['solved']}+{b['CHA']['solved']:>2}")
print(f" -> order cheaper in {wins} of {wins + losses} far cells\n")
print("L1b same pairing on the DERIVED3 reading")
for (sim, sc, gu, ex) in sorted(by):
if sc != "derived3" or ex != "none" or gu not in ("safe", "project", "none"):
continue
a, b = by[(sim, sc, gu, "none")], by.get((sim, sc, gu, "order"))
if b is None:
continue
print(f"{sim:<11} {gu:<9} {a['APS']['total']:9d} {b['APS']['total']:8d} "
f"{a['CHA']['total']:9d} {b['CHA']['total']:8d} "
f"{a['APS']['solved']}+{a['CHA']['solved']}/"
f"{b['APS']['solved']}+{b['CHA']['solved']:>2}")
print("\nL2/L3 best cells in the grid, by the paper's per-set rule "
"(solved first, then cost)")
for setname, target in (("APS", REF["APS_best"]), ("CHA", REF["CHA_best"])):
rows = sorted(res, key=lambda r: (r[setname]["n"] - r[setname]["solved"],
r[setname]["total"]))
for r in rows[:3]:
s = r["spec"]
print(f" {setname} {r['label']:<38} {r[setname]['solved']}/"
f"{r[setname]['n']} {r[setname]['total']:6d} "
f"over2x={r[setname]['over']} "
f"(target {target}) exponent={s[8] if len(s) > 8 else 'none'}")
print("\nL4 guarantee: cells with over2x > 0 (any set)")
bad = [r["label"] for r in res if r["APS"]["over"] or r["CHA"]["over"]]
print(f" {len(bad)} of {len(res)}" + (f": {bad[:6]}" if bad else " -> intact"))
print("\nFALSE POSITION, unguarded: is the measured order the parameter-free Illinois?")
print(f" {'cell':<34} {'solved':>7} {'APS fev':>9}")
print(f" {'false position (paper)':<34} {REF['falsepos'][0]}/154 "
f"{REF['falsepos'][1]:9d}")
print(f" {'Illinois (constant 1/2)':<34} {REF['illinois'][0]}/154 "
f"{REF['illinois'][1]:9d}")
for ex in ("none", "order"):
r = by.get(("rational", "far", "none", ex))
if r:
print(f" {'far+rational, guard=none, ' + ex:<34} "
f"{r['APS']['solved']}/154 {r['APS']['total']:9d}")
for ex in ("none", "order"):
r = by.get(("rational", "far", "safe", ex))
if r:
print(f" {'far+rational, guard=safe, ' + ex:<34} "
f"{r['APS']['solved']}/154 {r['APS']['total']:9d}")
print("\nBOTH SETS, best order cell against the reference 5511")
rows = [r for r in res if len(r["spec"]) > 8 and r["spec"][8] == "order"]
rows.sort(key=lambda r: (398 - r["APS"]["solved"] - r["CHA"]["solved"],
r["APS"]["total"] + r["CHA"]["total"]))
for r in rows[:3]:
print(f" {r['label']:<38} {r['APS']['solved'] + r['CHA']['solved']}/199 "
f"{r['APS']['total'] + r['CHA']['total']:6d} (reference {REF['BOTH_best']})")
if __name__ == "__main__":
main()