Files
sim-numerics/table_wins_losses.py
T

58 lines
2.3 KiB
Python

"""Comparative table of our wins and losses (server results only).
Variants of the proposed rule (tent, 3-point, projection) against the library Chandrupatla,
Brent (brentq) and TOMS748: totals per set, both sets, and per-problem wins/ties/losses with
the sign test; then the wide-bracket set per family.
python -u table_wins_losses.py
"""
from __future__ import annotations
import json
from analyze_extrap import h2h, sign_p
from where_we_lose import per_family
def load(p):
with open(p, encoding="utf8") as fh:
return {r["label"]: r for r in json.load(fh)}
def main():
full = load("sweep_full.json")
dc = load("sweep_defcontra.json")
rivals = {"Chandrupatla": full["chandrupatla"], "Brent": full["brent"],
"TOMS748": full["toms748"]}
ours = {
"proposed rule": full["pure.ratio.derived3.project"],
"+ G2 (step pattern)": dc["pure+extP.ratio.derived3.project"],
"+ G2 + analogy entry": dc["pure+extP+flatanalog.ratio.derived3.project"],
"+ contra + remembered analogy": dc["contra+flatanalogmem.ratio.derived3.project"],
"+ defect + remembered analogy": dc["defect+flatanalogmem.ratio.derived3.project"],
}
print("TOTALS (evaluations of f, failures charged 200)")
print(f" {'method':<32} {'APS':>6} {'CHA':>6} {'both':>6}")
for name, r in list(ours.items()) + list(rivals.items()):
print(f" {name:<32} {r['APS']['total']:6d} {r['CHA']['total']:6d} "
f"{r['APS']['total'] + r['CHA']['total']:6d}")
print("\nPER PROBLEM, ours against each rival: wins/ties/losses (sign-test p)")
for s in ("APS", "CHA"):
print(f" {s}")
for name, r in ours.items():
cells = []
for rn, rv in rivals.items():
w, t, l = h2h(r, rv, s)
cells.append(f"{rn} {w}/{t}/{l} p={sign_p(w, l):.2g}")
print(f" {name:<32} " + " ".join(cells))
print("\nCHA PER FAMILY (ours / Chandrupatla)")
fams = sorted(per_family(rivals["Chandrupatla"], "CHA"))
print(" " + " " * 32 + "".join(f"{f:>9}" for f in fams))
for name, r in list(ours.items()) + [("Chandrupatla", rivals["Chandrupatla"])]:
pf = per_family(r, "CHA")
print(f" {name:<32}" + "".join(f"{pf[f]:9d}" for f in fams))
if __name__ == "__main__":
main()