Gate question: can a ring-based label (a 2-D offset from the belief centre to
where a ray ring touches the enemy) be predicted from our own belief state?
extract_ring.py + bench_ring.nim answer it by MERGING the ring label into
samples_realistic.ndjson, so the ring label and the incumbent 1-D aim-error
label are scored on the SAME rows, the SAME features and the SAME round-group
folds. 8119 of 8676 DrussGT shot rows get a ring label.
Verdict: worse, not richer.
* The spike's headline is an artifact. The belief is already accurate to
under 3 px, so a belief-anchored ring touches the enemy on its FIRST ray
step: ringK = 1.0000 for all 172723 extracted events. The "100% at power
<= 1.5, 0.2% at power 3.0" pattern is just whether 1 * bulletSpeed fits
inside the +-18 px belief-error ball. The literal ring label is the 1-tick
belief extrapolation error, clipped to BotRadius.
* Same-tick it scores better than the 1-D label (ELM/const 0.2628 vs 0.3629)
but a single feature, beliefTgtLatVel, already gets -71.8 of the -73.7
points: the model is re-deriving beliefTgtLatVel * age / beliefDist, i.e.
its own inputs.
* Under --prev it collapses to ratio 0.9819 (-1.8%). It depends MORE on the
same-tick assumption than the 1-D label (-63.7% -> -1.0%), not less.
* Repaired (--kintercept: k = round(believed range / bullet speed), mean k 42,
no clipping, 60 px spread) the label is well posed and completely
unpredictable: best feature +0.5%, best ELM -0.4%, best |corr| 0.09.
So: the belief-extrapolation error at intercept time is not a function of what
we believed, it is the opponent's unmodelled acceleration. Do not ship a ring
label. common_libs/guns/waveelm.nim is the right shape for the same idea and
is a different thing: it fires the ring from the SHOOTER, so the ring measures
an interception radius and bearing and the ELM learns a bias correction to it.
58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Label distribution report for a merged ring dataset.
|
|
|
|
python3 ring_dist.py ring_drussgt.ndjson.merged
|
|
"""
|
|
import json, math, sys
|
|
|
|
|
|
def stats(x):
|
|
n = len(x)
|
|
if not n:
|
|
return None
|
|
m = sum(x) / n
|
|
sd = math.sqrt(sum((a - m) ** 2 for a in x) / (n - 1)) if n > 1 else 0.0
|
|
y = sorted(x)
|
|
q = lambda p: y[min(n - 1, max(0, int(round(p / 100 * (n - 1)))))]
|
|
return m, sd, q(1), q(10), q(25), q(50), q(75), q(90), q(99), y[0], y[-1]
|
|
|
|
|
|
def main():
|
|
rows = [json.loads(l) for l in open(sys.argv[1]) if l.strip()]
|
|
print(f"rows {len(rows)} groups {len(set(r['group'] for r in rows))}")
|
|
cols = ["label", "label1d", "ringLat", "ringRad", "ringMag", "ringLatAng",
|
|
"ringRadAng", "ringDist", "ringK"]
|
|
print(f"{'column':<12}{'mean':>10}{'sd':>10}{'p1':>10}{'p10':>10}{'p25':>10}"
|
|
f"{'p50':>10}{'p75':>10}{'p90':>10}{'p99':>10}{'min':>10}{'max':>10}")
|
|
for c in cols:
|
|
s = stats([r[c] for r in rows])
|
|
print(f"{c:<12}" + "".join(f"{v:>10.4f}" for v in s))
|
|
|
|
# correlation between the two labels, and the single best linear feature
|
|
def corr(a, b):
|
|
n = len(a)
|
|
ma, mb = sum(a) / n, sum(b) / n
|
|
sxy = sum((x - ma) * (y - mb) for x, y in zip(a, b))
|
|
sxx = sum((x - ma) ** 2 for x in a)
|
|
syy = sum((y - mb) ** 2 for y in b)
|
|
return sxy / math.sqrt(sxx * syy) if sxx > 0 and syy > 0 else 0.0
|
|
|
|
ring = [r["label"] for r in rows]
|
|
one = [r["label1d"] for r in rows]
|
|
print(f"\ncorr(ring label, 1-D aim error) = {corr(ring, one):+.4f}")
|
|
print("\nper-feature Pearson corr with each label (|corr| descending):")
|
|
feats = ["beliefPredErr", "beliefScanAge", "beliefTgtSpeed", "beliefTof",
|
|
"beliefRelBearing", "beliefDist", "beliefDisp", "beliefScanGap",
|
|
"beliefTgtLatVel", "beliefClosing", "beliefLosRate",
|
|
"oracleDist", "gunHeat", "power", "ownSpeed", "ringK", "ringDist"]
|
|
tab = []
|
|
for f in feats:
|
|
x = [r[f] for r in rows]
|
|
tab.append((f, corr(x, ring), corr(x, one)))
|
|
for f, cr, c1 in sorted(tab, key=lambda t: -abs(t[1])):
|
|
print(f" {f:<18} ring {cr:+.4f} 1-D {c1:+.4f}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|