tools/elm_bench: aim-error ELM benchmark suite + findings
Extractors, benchmarks and analysis for "can we predict an opponent's aim error from our own belief state?". All labels come from BulletFiredEvents; all features come only from the shooter's own state and its ScannedBotEvent history (the target's true state is used for the label and never for a feature, verified by a ground-truth-poisoning re-extraction). extract.py / extract_realistic.py label + oracle features / realistic ones gen_analysis.py, analyse_realistic.py, audit_independent.py bench.nim, bench_realistic.nim, cross_opponent.nim, online.nim gen/*.ndjson the per-opponent sample tables README.md the write-up, ~1200 lines Headline: DrussGT applies about 13% of the correct lead, and that 13% is computable from one feature (beliefPredErr) as label ~ 0.8663*predErr + 0.0418. ELM ALL-21 pools to RMSE 0.4220 against a constant 1.1463 (-63%). The network is not the finding; the single linear term is. Cross-opponent, --prev leakage audit and an independent re-derivation are in the README. The top-level samples_realistic*.ndjson are byte-identical to gen/DrussGT* and are gitignored; gen/ is the authoritative copy.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Per-opponent generalisation stats: the label~lead law, the ridge baselines and
|
||||
the strictly-prior-scan leakage audit, for every corpus passed on the command line.
|
||||
|
||||
python3 gen_analysis.py gen/DrussGT.ndjson gen/Dookious.ndjson ...
|
||||
|
||||
Reuses analyse_realistic.py's prep/fit/cv (same labels, same 5-fold round-group
|
||||
split, same ridge) and additionally reports the fitted slope on beliefPredErr,
|
||||
i.e. (1 - slope) = fraction of the correct lead the opponent actually applies.
|
||||
"""
|
||||
import math, os, sys
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from analyse_realistic import prep, fit, cv, const, F64, ALL20
|
||||
|
||||
|
||||
def law(d):
|
||||
B = fit(d, ["beliefPredErr"])
|
||||
n = len(d)
|
||||
mx = sum(r["beliefPredErr"] for r in d) / n
|
||||
my = sum(r["label"] for r in d) / n
|
||||
sxy = sum((r["beliefPredErr"] - mx) * (r["label"] - my) for r in d)
|
||||
sxx = sum((r["beliefPredErr"] - mx) ** 2 for r in d)
|
||||
syy = sum((r["label"] - my) ** 2 for r in d)
|
||||
corr = sxy / math.sqrt(sxx * syy) if sxx > 0 and syy > 0 else 0.0
|
||||
return B[0], B[1], corr
|
||||
|
||||
|
||||
def scan_stats(d):
|
||||
h = {}
|
||||
for r in d:
|
||||
a = r["beliefScanAge"]
|
||||
h[a] = h.get(a, 0) + 1
|
||||
same = h.get(0.0, 0) + h.get(1.0, 0) * 0 # exact 0
|
||||
return h, same / len(d)
|
||||
|
||||
|
||||
def main():
|
||||
print("== per-opponent: constant, predErr law, ridge baselines, leakage audit ==")
|
||||
hdr = (f"{'opponent':<14}{'n':>6}{'const':>8}{'predErr':>9}{'corr':>7}"
|
||||
f"{'slope':>8}{'intcpt':>8}{'lead%':>7}{'ALL20':>8}"
|
||||
f"{'|prev|':>7}{'prevConst':>10}{'prevPredErr':>12}{'prevALL20':>10}"
|
||||
f"{'sameTick%':>11}{'everScanned%':>14}")
|
||||
print(hdr)
|
||||
for p in sys.argv[1:]:
|
||||
d = prep(p)
|
||||
s, b, corr = law(d)
|
||||
r_pred = cv(d, ["beliefPredErr"])[0]
|
||||
r_all = cv(d, ALL20)[0]
|
||||
pp = p.replace(".ndjson", "_prev.ndjson")
|
||||
if os.path.exists(pp):
|
||||
dp = prep(pp)
|
||||
pc, ppd, pa = const(dp), cv(dp, ["beliefPredErr"])[0], cv(dp, ALL20)[0]
|
||||
else:
|
||||
pc = ppd = pa = float("nan")
|
||||
h, samefrac = scan_stats(d)
|
||||
ever = sum(1 for r in d if r["beliefEverScanned"] > 0) / len(d)
|
||||
print(f"{os.path.basename(p).replace('.ndjson',''):<14}{len(d):>6}"
|
||||
f"{const(d):>8.4f}{r_pred:>9.4f}{corr:>7.3f}{s:>8.3f}{b:>8.4f}"
|
||||
f"{100*(1-s):>7.1f}{r_all:>8.4f}"
|
||||
f"{sum(1 for r in prep(pp) if r.get('prevOnly')==1.0) if os.path.exists(pp) else 0:>7}"
|
||||
f"{pc:>10.4f}{ppd:>12.4f}{pa:>10.4f}"
|
||||
f"{100*samefrac:>11.1f}{100*ever:>14.1f}")
|
||||
print(f"{'':<14}scan-age histogram: " +
|
||||
", ".join(f"{int(k)}:{v}" for k, v in sorted(h.items())[:6]) +
|
||||
(" ..." if len(h) > 6 else ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user