Prototype: GA evolution loop on toy prediction problem #66

Closed
opened 2026-08-23 23:26:57 +02:00 by SirStone · 2 comments
Owner

Parent: #61

Question

Build a minimal throwaway prototype in Nim: a GA that evolves a small ANN (e.g., 10→4→1) to predict a simple periodic function (like sin(x) sampled with noise). Purpose: validate the GA→ANN→fitness pipeline works before wiring it into a bot. Tests: population init, fitness eval, selection, crossover, mutation, champion tracking. Throwaway — not production code, just proof the mechanism works.

Parent: #61 ## Question Build a minimal throwaway prototype in Nim: a GA that evolves a small ANN (e.g., 10→4→1) to predict a simple periodic function (like sin(x) sampled with noise). Purpose: validate the GA→ANN→fitness pipeline works before wiring it into a bot. Tests: population init, fitness eval, selection, crossover, mutation, champion tracking. Throwaway — not production code, just proof the mechanism works.
SirStone added the wayfinder:prototype label 2026-08-23 23:26:57 +02:00
Author
Owner

Blocked by #65 — GA parameters from research inform the prototype's hyperparameters.

Blocked by #65 — GA parameters from research inform the prototype's hyperparameters.
Author
Owner

Resolution

Built: prototypes/ga_gun_spike/ga_spike.nim — 111-line pure-Nim GA that evolves a 10-4-1 tanh ANN (49 weights) to predict sin(x) from a sliding window.

Pipeline validated:

  • Population init (200 individuals, random weights)
  • Fitness eval (negative MSE on 50 random samples)
  • Truncation selection (top 20%)
  • Gaussian mutation on ALL weights (sigma=0.01), per #65 research
  • Single elite preservation (best network unchanged)
  • No crossover, per #65 research
  • Champion tracking (fitness printed every 20 gens)

Results:

  • Compiled and ran cleanly (nim c -r, Nim 2.2.4)
  • Final champion MSE: 0.000181 (fitness = -0.000181)
  • Average absolute prediction error: 0.0126 (well under 0.1 assert threshold)
  • Convergence clearly visible: MSE dropped from 0.095 (gen 0) to 0.0002 (gen 199) — monotonic improvement across all 200 generations

Commit: eee48de on research/goto-controller

## Resolution **Built:** `prototypes/ga_gun_spike/ga_spike.nim` — 111-line pure-Nim GA that evolves a 10-4-1 tanh ANN (49 weights) to predict sin(x) from a sliding window. **Pipeline validated:** - Population init (200 individuals, random weights) - Fitness eval (negative MSE on 50 random samples) - Truncation selection (top 20%) - Gaussian mutation on ALL weights (sigma=0.01), per #65 research - Single elite preservation (best network unchanged) - No crossover, per #65 research - Champion tracking (fitness printed every 20 gens) **Results:** - Compiled and ran cleanly (`nim c -r`, Nim 2.2.4) - Final champion MSE: **0.000181** (fitness = -0.000181) - Average absolute prediction error: **0.0126** (well under 0.1 assert threshold) - Convergence clearly visible: MSE dropped from 0.095 (gen 0) to 0.0002 (gen 199) — monotonic improvement across all 200 generations **Commit:** `eee48de` on `research/goto-controller`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#66