"""The protocol tables under the single criterion of sweep_uniform.json (revision point 3), next to the numbers the paper printed under the published-root criterion. python -u report_uniform.py """ from __future__ import annotations import json from rescore_uniform import load_uniform APRIME = "pure+extP+contra+flatanalogmempt+exp+half+close+sub.ratio.derived3" def rows(path): return {r["label"]: r for r in load_uniform(path)} def old(path): with open(path, encoding="utf8") as fh: return {r["label"]: r for r in json.load(fh)} def cost(v): return v[0] if v[1] else 200 def wtl(a, b, s): ps = list(a[s]["per"]) w = sum(cost(a[s]["per"][p]) < cost(b[s]["per"][p]) for p in ps) l = sum(cost(a[s]["per"][p]) > cost(b[s]["per"][p]) for p in ps) return w, len(ps) - w - l, l def rank(R, s): return sorted(R.values(), key=lambda r: (r[s]["n"] - r[s]["solved"], r[s]["total"])) def main(): U, O = rows("sweep_full.json"), old("sweep_full.json") for s in ("APS", "CHA"): print(f"\n== {s}: top 12 of {len(U)} under the single criterion (old total in brackets)") for i, r in enumerate(rank(U, s)[:12], 1): lb = r["label"] print(f" {i:2d}. {lb:<34} solved {r[s]['solved']:3d}/{r[s]['n']} total {r[s]['total']:5d}" f" ({O[lb][s]['total']}) over {r[s]['over']}") pos = {r["label"]: i for i, r in enumerate(rank(U, s), 1)} for lb in ("pure.ratio.derived3.project", "chandrupatla", "toms748", "brent", "itp_oracle", "itp", "bisection"): print(f" place {pos[lb]:3d}: {lb:<30} {U[lb][s]['total']:5d} ({O[lb][s]['total']})" f" solved {U[lb][s]['solved']}") base, ch = U["pure.ratio.derived3.project"], U["chandrupatla"] print("\nbase rule vs Chandrupatla, failures charged:", {s: wtl(base, ch, s) for s in ("APS", "CHA")}) A = rows("sweep_aprime.json") ap = A[f"{APRIME}.project"] print(f"\nTable 8 under the single criterion: A' {ap['APS']['total']} / {ap['CHA']['total']}" f" earned {A[APRIME + '.credit']['APS']['total']} / {A[APRIME + '.credit']['CHA']['total']}") for opp in ("chandrupatla", "toms748", "brent", "itp_oracle", "itp", "bisection"): o = U[opp] print(f" {opp:<14} {o['APS']['total']:5d} {o['CHA']['total']:5d} " f"A' vs: APS {wtl(ap, o, 'APS')} CHA {wtl(ap, o, 'CHA')}") print("\nTable 5 cells (single criterion / old):") for path, lb in (("sweep_full.json", "pure.ratio.derived3.credit"), ("sweep_slope.json", "slope.ratio.derived3.project"), ("sweep_points.json", "pure+shape+slope.ratio.derived3.safe"), ("sweep_direction.json", "pure+dissim+slope.ratio.derived3.project"), ("sweep_combo.json", "pure+shape+dissim+slope.ratio.derived3.safe")): try: r, o = rows(path)[lb], old(path)[lb] print(f" {lb:<46} {r['APS']['total']:5d} {r['CHA']['total']:5d} " f"({o['APS']['total']} {o['CHA']['total']}) over {r['APS']['over'] + r['CHA']['over']}") except KeyError: print(f" {lb}: label not in {path}") S = rows("sweep_aprime_s.json") print("\nTable 9a protocol column (single criterion / old):") So = old("sweep_aprime_s.json") for lb, r in S.items(): print(f" {r['spec'][1]:<11} {r['APS']['total'] + r['CHA']['total']:6d} " f"({So[lb]['APS']['total'] + So[lb]['CHA']['total']})") if __name__ == "__main__": main()