tools/elm_bench: ring label experiment — the ring label is NOT learnable

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.
This commit is contained in:
2026-10-05 22:59:41 +02:00
parent 8e6af386fc
commit 16c71c527a
10 changed files with 1663 additions and 1 deletions
+221
View File
@@ -1250,3 +1250,224 @@ variable; it would only buy more capacity to overfit the 40 round-groups.
Ship `0.87 × lead`, not a network.
---
# RING LABEL EXPERIMENT (2025-10-05)
The gate before the ring was: **is a ring label learnable?** A ring is `N`
rays fired simultaneously from a belief centre at bullet speed; the label is the
2-D offset between the belief centre and where the ring touches the enemy circle.
`tools/ring_spike/spike.py` claimed this works (100% interception at bullet
power ≤ 1.5, independent of ray count and ring radius, collapsing to ~0.2% at
power 3.0). This section answers the learnability question, and it also shows
that the spike's headline number is an artifact.
**Answer up front: no. The ring label is worse, not richer.** It is either
degenerate (same-tick: it is an algebraic restatement of one feature the model
is already given) or unpredictable (everything else). It never beats the
incumbent 1-D aim-error label on the part that matters.
## 1. What was measured
```
python3 extract_ring.py ring_drussgt.ndjson ../../data/drussgt_raw --base samples_realistic.ndjson
nim c -r --path:../../DevControlBot_garage/DevControlBot bench_ring.nim ring_drussgt.ndjson.merged
```
`extract_ring.py` emits one row per (scan tick, enemy). It imports `collect`
and `ring_contact` from `spike.py`, so the ring geometry and the belief
reconstruction have exactly one definition. With `--base` it MERGES into an
existing `samples_*.ndjson`: every base row keeps its own features untouched
and gains `ringK / ringLat / ringRad / ringMag / ringLatAng / ringRadAng`,
`label` becomes the ring label and `label1d` keeps the incumbent aim error.
`bench_ring.nim` then scores **both labels on the same rows, the same features
and the same round-group folds**, so the comparison is row-for-row, not
corpus-for-corpus. 8119 of the 8676 DrussGT shot rows get a ring label (93.6%).
Two variants, both with and without `--prev` (strictly-prior-scan semantics):
| variant | contact tick `k` |
|---|---|
| **literal** (the spike's rule) | first `k` where some ray point is within BotRadius of the enemy |
| **`--kintercept`** (this section's repair) | `k = round(believed range / bullet speed)`, i.e. the bullet flight time — fully observable |
`label = atan2(lateral, beliefDist)` in radians, where `lateral` is the
component of (enemy true position at contact − belief dead-reckoned to contact)
perpendicular to the believed line of sight. Same units and same sign as the
incumbent aim-error label, which is what makes the head-to-head fair.
## 2. Label distribution (rad)
DrussGT corpus, literal variant, same-tick:
| column | mean | sd | \|p1\| | \|p50\| | \|p90\| | max\|·\| |
|---|---|---|---|---|---|---|
| **ring label** | −0.00023 | **0.01044** | 0.0217 | 0.00008 | 0.0148 | 0.0270 |
| 1-D aim error | +0.11074 | **1.17266** | 2.9010 | 0.0067 | 1.8073 | 3.1414 |
In pixels the ring label is `ringLat` mean −0.09 px, sd **4.26 px**, hard
clipped to ±8.00 px; `ringMag` mean 5.45 px, sd 2.66 px, **max 8.00 px**.
Two things stand out. The ring label is **112× smaller in scale** than the
incumbent one, and it is **clipped**: sd 4.26 px on a label that saturates at
±8 px is a censored distribution, not a well-behaved regression target.
`--prev`: ring sd 0.01341, `ringLat` sd 5.46 px, range −29.5…+25.2 px.
`--kintercept`: ring sd 0.14282, `ringLat` sd 59.5 px (mean `k` = 42.2 ticks).
**The cause of the clipping is the headline finding of this section.**
`ringK = 1.0000` for **all 172 723** extracted scan events, and the spike's own
output says why:
```
belief-vs-truth offset px: mean=0.75 std=0.64 p50=0.56 p90=2.00 max=3.00
BELIEF 1.0 360 400 100.00% kMean 1.00 | L1 10.00 0.00 | L2 3.19 2.24 | L3 2.10 1.75
```
The belief is already accurate to **under 3 px**, i.e. well inside the 18 px
`BotRadius`. A ring anchored at that centre therefore touches the enemy on its
very first ray step, at every power the spike recommends. The "100% at power
≤ 1.5, 0.2% at power 3.0" pattern is not ray geometry at all: it is simply
whether `k·bulletSpeed` for `k = 1` (10 or 15 px) falls inside the ±18 px
belief-error ball. At power 3.0 it does not, and no later step ever does either,
because the enemy's distance from the anchor barely changes. The spike's
"independent of ray count and ring radius" is likewise an artifact: it was never
measuring contact.
So the literal ring label is the **1-tick belief extrapolation error**, clipped
to the BotRadius. It is not a richer measurement of anything.
## 3. Learnability (same rows, same features, same 5 round-group folds)
Constant baseline, ridge ablation and ELM sweep
(H{16,32,64,128} × λ{1e-6,1e-4,1e-2,1,100}, decay 1.0, 20 configs × 5 folds,
ALL-21, λ=1e-8 ridge). Ratios are against each label's own constant.
### literal ring, same-tick
| model | pooled RMSE | MAE | medAE | vs const |
|---|---|---|---|---|
| constant | 0.01044 | 0.0083 | 0.0069 | — |
| ridge ALL 21 | 0.0026 | 0.0018 | 0.0012 | −75% |
| ridge **beliefTgtLatVel alone** | **0.00294** | | | **−71.8%** |
| ridge beliefPredErr alone | 0.00803 | | | +23.1% |
| **ELM best (H=128, λ=1e-2)** | **0.00274** | 0.00190 | 0.00136 | **ratio 0.2628, −73.7%, 5/5 folds** |
That looks like a win — until you see that one feature gets 71.8 of the 73.7
points, and it gets them for a *tautological* reason. With `k = 1` and scan
age ≈ 0, `ringLatAng ≈ beliefTgtLatVel × age / beliefDist` ≈
`beliefLosRate`. The network is re-deriving arithmetic on its own inputs. The
clipped distribution explains why the RMSE ratio (0.26) is *better* than the 1-D
one (0.36): a censored, low-variance target is easier to regress, not more
informative.
### literal ring, `--prev` (the check that matters)
| model | ring | 1-D aim |
|---|---|---|
| constant | 0.0134 | 1.1638 |
| ridge ALL 21 | 0.0133 (−0.0001) | 1.1500 |
| best single feature (beliefTgtLatVel) | +1.04% | — |
| **ELM best (H=128, λ=1)** | **ratio 0.9819, −1.8%** | **ratio 0.9899, −1.0%** |
**The ring label's apparent learnability does not survive `--prev`.** The
−73.7% collapses to −1.8%, and every single-feature ridge collapses to ≤ 1%.
It depends on the same-tick assumption *more* than the 1-D label does, not
less: it is only ever a restatement of a quantity computed from a scan taken in
the current tick. The 1-D label's `beliefPredErr` signal degrades too
(−63.7% → −1.0%), but that is a documented property of the corpora, not of the
label's construction.
### `--kintercept` (the repaired label, no clipping, mean k = 42)
| model | ring | 1-D aim |
|---|---|---|
| constant | 0.1429 | 1.1661 |
| ridge ALL 21 | 0.1426 (−0.0002) | 0.4419 |
| best single feature (cosRel) | **+0.50%** | — |
| **ELM best** | **ratio 0.9956, −0.4%, 4/5 folds** | ratio 0.3632, −63.7% |
| ELM best, `--prev` | **ratio 0.9990, −0.1%, 2/5 folds** | ratio 0.9896 |
This is the honest version of the ring label: no degenerate contact, a real
42-tick extrapolation, a 60 px spread. **It is completely unpredictable.** No
feature exceeds 0.5%, the network is 0.4% better than a constant, and the best
single Pearson correlation between any of the 21 features and the label is
**0.09** (`ringK`/`beliefDist`). Under `--prev` it is 0.09 too. A 60 px
positional error at intercept time is not a function of what we believed; it is
the opponent's unmodelled acceleration, and nothing in our own state carries it.
## 4. Head-to-head (ELM pooled RMSE ÷ constant pooled RMSE)
| dataset | ring label | 1-D aim-error label |
|---|---|---|
| same-tick, literal | **0.2628** | 0.3629 |
| `--prev`, literal | 0.9819 | 0.9899 |
| same-tick, k-intercept | 0.9956 | 0.3632 |
| `--prev`, k-intercept | 0.9990 | 0.9896 |
## VERDICT
**The ring label is not richer than the 1-D aim-error label. It is strictly
worse, and the one number that made it look better is a bug in the spike.**
1. **Not richer.** The literal ring label carries *less* information than the
incumbent: it is one linear combination of two features the model already
has (`beliefTgtLatVel`, `beliefDist`), it is censored at ±8 px, and the ELM
adds 1.9 points over that single ridge (−73.7% vs −71.8%). The 1-D label is
a genuinely behavioural quantity — the opponent's *decision*, not our own
arithmetic — and it is the only one of the two whose structure is still
visible after you hand the model everything.
2. **The gain is not bigger; it is fake.** Same-tick, the ring label's ratio
(0.2628) is nominally better than the 1-D label's (0.3629). That difference
is entirely the consequence of a smaller, clipped target: the same ELM, the
same features, a label with a hundredth of the spread (sd 0.0104 vs 1.1727). It buys no
capability.
3. **It depends MORE on the same-tick assumption, not less.** −73.7% → −1.8%
under `--prev`, versus −63.7% → −1.0% for the 1-D label. The ring label is
built out of the current tick's scan; take that away and there is nothing
left.
4. **The repaired label is pure noise.** Removing the `k = 1` degeneracy
(`--kintercept`) gives a well-posed 60 px, 42-tick-ahead target that **no**
feature and **no** ELM can predict (best 0.4%, best |corr| 0.09). This is
the actual answer to "is the ring label learnable": the belief-extrapolation
error at intercept time is not learnable from the shooter's own state.
5. **What to do with it.** Do not ship a ring label. `common_libs/guns/
waveelm.nim` is the right shape for the same idea and it is not the same
thing: it fires the ring **from the shooter**, not from the belief centre,
so the ring measures an interception *radius and bearing* (a real
measurement) and the ELM learns a bias correction to it — the ring is the
instrument, not the label. That construction is unaffected by the
`k = 1` degeneracy above and should be the one benchmarked next.
### Files (ring experiment)
```
extract_ring.py ring labels per scan tick; --prev, --kintercept,
--base (merge into samples_*.ndjson)
ring_dist.py distribution + per-feature correlation report
bench_ring.nim both labels, same rows/folds: constant, ridge
ablation, single-feature ridge, ELM sweep
ring_same.log literal ring, same-tick + 1-D on the same rows
ring_prev.log literal ring, --prev + 1-D on the same rows
ring_ki.log k-intercept ring, same-tick + 1-D
ring_ki_prev.log k-intercept ring, --prev + 1-D
```
Rebuild:
```
python3 extract_ring.py ring_drussgt.ndjson ../../data/drussgt_raw --base samples_realistic.ndjson
python3 extract_ring.py ring_prev.ndjson ../../data/drussgt_raw --prev --base samples_realistic_prev.ndjson
python3 extract_ring.py ring_ki.ndjson ../../data/drussgt_raw --kintercept --base samples_realistic.ndjson
python3 extract_ring.py ring_ki_prev.ndjson ../../data/drussgt_raw --kintercept --prev --base samples_realistic_prev.ndjson
nim c -r --path:../../DevControlBot_garage/DevControlBot bench_ring.nim ring_*.ndjson.merged
```
`bench_ring.nim` imports the ELM by relative path
(`../../DevControlBot_garage/DevControlBot/modules/ELM/elm`) and reads its input
path from `paramStr(1)`; run it from `tools/elm_bench`. No project-local import
workaround is needed — the ELM module is self-contained (stdlib only), so the
project-local loader is only an issue for callers inside the bot.
`ring_*.ndjson` and the `.merged` files are generated (40 s each) and are
gitignored; the four `.log` files are committed.