T6: Extract Tsetlin Machine as gun module #184

Open
opened 2026-09-19 14:49:12 +02:00 by SirStone · 1 comment
Owner

Parent

#165 (ModularBot wayfinder map)

What to build

Extract TM predictor from BNNBot_garage and adapt it as a Gun module. The TM gun is a learning gun — it uses onResult() to train on miss corrections.

  • Extract tsetlin_predictor.nim and binary_encoding.nim into a gun module at common_libs/guns/tsetlin.nim
  • Adapt to Gun interface: predict() runs TM forward pass + correction on extrapolated position, onResult() matches tick via internal eligibility traces and calls learn()
  • Manages own frame history window
  • Configurable: clauses, T, s, states

Register in ModularBot. The learning gun competes with analytical ones — should eventually outperform against complex movement patterns.

Acceptance criteria

  • TM gun implements Gun interface
  • predict() returns absolute (x, y) using TM correction on linear extrapolation
  • onResult() triggers TM learning via eligibility traces
  • Registered in ModularBot — four guns competing
  • TM gun's fitness improves over rounds (visible in virtual bullet stats)

Blocked by

#179 (T1)

## Parent #165 (ModularBot wayfinder map) ## What to build Extract TM predictor from BNNBot_garage and adapt it as a Gun module. The TM gun is a learning gun — it uses onResult() to train on miss corrections. - Extract `tsetlin_predictor.nim` and `binary_encoding.nim` into a gun module at `common_libs/guns/tsetlin.nim` - Adapt to Gun interface: predict() runs TM forward pass + correction on extrapolated position, onResult() matches tick via internal eligibility traces and calls learn() - Manages own frame history window - Configurable: clauses, T, s, states Register in ModularBot. The learning gun competes with analytical ones — should eventually outperform against complex movement patterns. ## Acceptance criteria - [ ] TM gun implements Gun interface - [ ] predict() returns absolute (x, y) using TM correction on linear extrapolation - [ ] onResult() triggers TM learning via eligibility traces - [ ] Registered in ModularBot — four guns competing - [ ] TM gun's fitness improves over rounds (visible in virtual bullet stats) ## Blocked by #179 (T1)
SirStone added the ready-for-agent label 2026-09-19 14:49:12 +02:00
Author
Owner

TsetlinGun implemented and wired into ModularBot. Build passes.

What was done:

  • Created common_libs/guns/tsetlin.nim — self-contained: binary encoding and TM predictor inlined, no dependency on BNNBot_garage.
  • Implements Gun interface: predict(state, bulletSpeed) → GunPrediction and onResult(FeedbackEvent).
  • predict(): encodes WorldState into 870-bit binary vector (sliding window of 10 frames × 83 bits + 40 self bits), runs TM forward pass, applies (cx, cy) correction on top of linear extrapolation, returns clamped absolute (x, y). Falls back to pure linear during warm-up (first 10 frames).
  • onResult(): matches the resolved bullet back to its stored trace via prediction coords, computes shaped residual from miss distance, calls TM learn on both output dimensions.
  • Internal ring buffer of 64 trace slots for eligibility matching.
  • TM config: 50 clauses, T=25.0, s=1.5, states=32 (int16).
  • Registered in ModularBot as gun 2 (tracker: vb.initTracker(3)); headOn=0, linear=1, tsetlin=2.

Design notes:

  • onResult receives miss distance but not direction. Residual is split equally across x/y axes (√2 factor). Upgrade path: add enemyX/Y to FeedbackEvent for directional residuals.
  • circular import stays in ModularBot (other work), CircularGun field retained but not wired to tracker yet.
  • ponytail: comment in tsetlin.nim marks the 50/50 residual split as a deliberate simplification.
TsetlinGun implemented and wired into ModularBot. Build passes. **What was done:** - Created `common_libs/guns/tsetlin.nim` — self-contained: binary encoding and TM predictor inlined, no dependency on BNNBot_garage. - Implements Gun interface: `predict(state, bulletSpeed) → GunPrediction` and `onResult(FeedbackEvent)`. - `predict()`: encodes WorldState into 870-bit binary vector (sliding window of 10 frames × 83 bits + 40 self bits), runs TM forward pass, applies (cx, cy) correction on top of linear extrapolation, returns clamped absolute (x, y). Falls back to pure linear during warm-up (first 10 frames). - `onResult()`: matches the resolved bullet back to its stored trace via prediction coords, computes shaped residual from miss distance, calls TM learn on both output dimensions. - Internal ring buffer of 64 trace slots for eligibility matching. - TM config: 50 clauses, T=25.0, s=1.5, states=32 (int16). - Registered in ModularBot as gun 2 (`tracker: vb.initTracker(3)`); headOn=0, linear=1, tsetlin=2. **Design notes:** - `onResult` receives miss distance but not direction. Residual is split equally across x/y axes (√2 factor). Upgrade path: add `enemyX/Y` to `FeedbackEvent` for directional residuals. - `circular` import stays in ModularBot (other work), `CircularGun` field retained but not wired to tracker yet. - `ponytail:` comment in tsetlin.nim marks the 50/50 residual split as a deliberate simplification.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#184