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.
135 lines
4.7 KiB
Python
135 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Side analyses for the realistic-feature experiment (see README).
|
|
|
|
1. Is the label predictable from the SHOOTER-side belief features? (ridge, CV)
|
|
2. LEAKAGE AUDIT: re-extract with the belief built ONLY from scans strictly
|
|
BEFORE the fire tick (samples_realistic_prev.ndjson) -- if the gain survives
|
|
without the same-tick scan, it is robust; if it vanishes, the whole effect
|
|
is the shooter's fresh same-tick scan.
|
|
3. Which feature subsets carry the signal.
|
|
|
|
run: python3 analyse_realistic.py
|
|
"""
|
|
import json, math, sys, os
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
F64 = ["dS", "lat", "clo", "tofS", "sp", "bs"]
|
|
ALL20 = ["dS", "invD", "beliefSinRelBearing", "beliefCosRelBearing", "sp", "bs",
|
|
"age", "lat", "clo", "beliefLosRate", "tofS", "beliefSinPredRelBearing",
|
|
"beliefCosPredRelBearing", "beliefPredErr", "gunHeat", "power",
|
|
"ownSpeed", "beliefDisp", "round", "tick"]
|
|
|
|
|
|
def prep(path):
|
|
d = [json.loads(l) for l in open(path)]
|
|
for r in d:
|
|
r["lat"] = r["beliefTgtLatVel"] / 10
|
|
r["clo"] = r["beliefClosing"] / 10
|
|
r["tofS"] = r["beliefTof"] / 30
|
|
r["bs"] = r["bulletSpeed"] / 20
|
|
r["dS"] = r["beliefDist"] / 1000
|
|
r["invD"] = 1.0 / (1.0 + r["beliefDist"] / 100.0)
|
|
r["sp"] = r["beliefTgtSpeed"] / 10
|
|
r["age"] = min(r["beliefScanAge"], 30) / 30
|
|
return d
|
|
|
|
|
|
def fit(rows, feats):
|
|
p = len(feats) + 1
|
|
A = [[0.0] * p for _ in range(p)]
|
|
B = [0.0] * p
|
|
for r in rows:
|
|
x = [r[f] for f in feats] + [1.0]
|
|
for a in range(p):
|
|
B[a] += x[a] * r["label"]
|
|
for b in range(p):
|
|
A[a][b] += x[a] * x[b]
|
|
for a in range(p):
|
|
A[a][a] += 1e-8
|
|
for c in range(p):
|
|
piv = max(range(c, p), key=lambda i: abs(A[i][c]))
|
|
A[c], A[piv] = A[piv], A[c]
|
|
B[c], B[piv] = B[piv], B[c]
|
|
dd = A[c][c]
|
|
for j in range(c, p):
|
|
A[c][j] /= dd
|
|
B[c] /= dd
|
|
for i in range(p):
|
|
if i != c and A[i][c]:
|
|
f = A[i][c]
|
|
for j in range(c, p):
|
|
A[i][j] -= f * A[c][j]
|
|
B[i] -= f * B[c]
|
|
return B
|
|
|
|
|
|
def pred(B, r, feats):
|
|
return sum(w * v for w, v in zip(B, [r[f] for f in feats] + [1.0]))
|
|
|
|
|
|
def cv(d, feats):
|
|
groups = []
|
|
for r in d:
|
|
if r["group"] not in groups:
|
|
groups.append(r["group"])
|
|
fold = {g: i % 5 for i, g in enumerate(groups)}
|
|
se = n = 0
|
|
per = []
|
|
for f in range(5):
|
|
tr = [r for r in d if fold[r["group"]] != f]
|
|
te = [r for r in d if fold[r["group"]] == f]
|
|
B = fit(tr, feats)
|
|
s = 0.0
|
|
for r in te:
|
|
s += (pred(B, r, feats) - r["label"]) ** 2
|
|
per.append(math.sqrt(s / len(te)))
|
|
se += s
|
|
n += len(te)
|
|
return math.sqrt(se / n), per
|
|
|
|
|
|
def const(d):
|
|
m = sum(r["label"] for r in d) / len(d)
|
|
return math.sqrt(sum((r["label"] - m) ** 2 for r in d) / len(d))
|
|
|
|
|
|
def main():
|
|
d = prep(os.path.join(HERE, "samples_realistic.ndjson"))
|
|
p = os.path.join(HERE, "samples_realistic_prev.ndjson")
|
|
print("== 5-fold-by-round-group ridge, realistic features (pooled held-out RMSE) ==")
|
|
print(f" constant mean {const(d):.4f}")
|
|
for name, fs in [("predErr alone", ["beliefPredErr"]),
|
|
("our-state only (dist,lat,closing,tof,spd)", F64),
|
|
("our-state + predErr", F64 + ["beliefPredErr"]),
|
|
("ALL realistic (20)", ALL20)]:
|
|
r, per = cv(d, fs)
|
|
print(f" {name:38s} {r:.4f} per-fold " + " ".join(f"{x:.4f}" for x in per))
|
|
|
|
if os.path.exists(p):
|
|
dp = prep(p)
|
|
print("\n== LEAKAGE AUDIT: belief built ONLY from scans strictly before the fire tick ==")
|
|
n = sum(1 for r in dp if r.get("prevOnly") == 1.0)
|
|
print(f" rows with a strictly-prior scan: {n}/{len(dp)}")
|
|
print(f" constant mean {const(dp):.4f}")
|
|
for name, fs in [("predErr alone", ["beliefPredErr"]),
|
|
("our-state only", F64),
|
|
("our-state + predErr", F64 + ["beliefPredErr"]),
|
|
("ALL realistic (20)", ALL20)]:
|
|
r, _ = cv(dp, fs)
|
|
print(f" {name:38s} {r:.4f}")
|
|
|
|
print("\n== law check: label ~ a*predErr + b ==")
|
|
B = fit(d, ["beliefPredErr"])
|
|
print(f" slope {B[0]:.4f} intercept {B[1]:.4f}"
|
|
" -> DrussGT aims at (current bearing + ~%.0f%% of the correct lead)"
|
|
% (100 * (1 - B[0])))
|
|
ages = {}
|
|
for r in d:
|
|
ages[r["beliefScanAge"]] = ages.get(r["beliefScanAge"], 0) + 1
|
|
print(" scan-age histogram (ticks since the shooter last scanned us):",
|
|
dict(sorted(ages.items())))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|