affine-god/1111 / levers.py
affine-god's picture
download
raw
2.99 kB
"""Which challenger-side quantity actually predicts the duel margin?
Ranks candidate levers by Spearman correlation with the paired margin, so a
miner knows what to optimise (and what is cheap to measure) before spending
GPU hours on a full 80-turn duel.
"""
from __future__ import annotations
import statistics as st
from analyze import load
def spearman(xs: list[float], ys: list[float]) -> float:
def rank(v):
order = sorted(range(len(v)), key=lambda i: v[i])
r = [0.0] * len(v)
i = 0
while i < len(order): # average ties
j = i
while j + 1 < len(order) and v[order[j + 1]] == v[order[i]]:
j += 1
for k in range(i, j + 1):
r[order[k]] = (i + j) / 2.0
i = j + 1
return r
rx, ry = rank(xs), rank(ys)
mx, my = st.mean(rx), st.mean(ry)
num = sum((a - mx) * (b - my) for a, b in zip(rx, ry))
den = (sum((a - mx) ** 2 for a in rx) * sum((b - my) ** 2 for b in ry)) ** 0.5
return num / den if den else 0.0
def main() -> None:
rows = [r for r in load() if r["se"] is not None]
y = [r["margin"] for r in rows]
levers = {
"Δλ2 (challenger − king)": lambda r: r["c"]["lambda2"] - r["k"]["lambda2"],
"ΔL1lift (clipped)": lambda r: r["c"]["l1_clipped"] - r["k"]["l1_clipped"],
"calibration ratio r": lambda r: r["c"]["r"] or 0.0,
"gate pass rate": lambda r: r["c"]["gate_rate"],
"bank fraction": lambda r: r["c"]["bank"],
"baseline / king baseline": lambda r: r["c"]["baseline"] / r["k"]["baseline"],
"raw (unclipped) L1lift": lambda r: r["c"]["l1_raw"],
"clip hit rate": lambda r: r["c"]["clip_hits"],
}
print(f"n = {len(rows)} scored duels\n")
print(f"{'lever':<30}{'Spearman ρ vs margin':>22}")
ranked = sorted(((k, spearman([f(r) for r in rows], y)) for k, f in levers.items()),
key=lambda kv: -abs(kv[1]))
for name, rho in ranked:
bar = "#" * int(abs(rho) * 40)
print(f"{name:<30}{rho:>22.3f} {bar}")
print("\n=== calibration ratio r, bucketed ===")
print(f"{'r range':<14}{'n':>4}{'mean margin':>14}{'mean z':>9}{'crowns':>8}")
buckets = [(0.0, 0.6), (0.6, 0.7), (0.7, 0.8), (0.8, 0.9), (0.9, 1.0),
(1.0, 1.3), (1.3, 9.9)]
allrows = load()
for lo, hi in buckets:
g = [r for r in allrows if r["c"]["r"] and lo <= r["c"]["r"] < hi]
if not g:
continue
scored = [r for r in g if r["se"] is not None]
print(f"[{lo:.1f},{hi:.1f})".ljust(14)
+ f"{len(g):>4}"
+ f"{st.mean(r['margin'] for r in scored):>14.4f}" if scored else ""
, end="")
print(f"{st.mean(r['z'] or 0 for r in scored):>9.2f}"
f"{sum(1 for r in g if r['wins']):>8}" if scored else "")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
2.99 kB
·
Xet hash:
f68cf2aa356025294a6dbfb0ec9bb29184e3dfb34a918d72e478d633fd88d69e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.