Files
foxhunt/ml/trained_models
jgrusewski 9aa953b2b9 fix(dqn): Fix adaptive C51 bounds buffer ordering bug (P0)
Fixed critical ordering bug preventing adaptive bounds from triggering
at epoch 10 normalization transition.

**Root Cause:**
Buffer was cleared BEFORE Q-value statistics collection, causing
"Replay buffer is empty" error even with 23,590+ experiences stored.

**Problem Sequence (BROKEN):**
1. Collect feature statistics (epochs 1-10)
2. Clear replay buffer → removes all 23k+ experiences
3. Adaptive C51 tries to sample → FAILS: buffer empty!
4. Falls back to fixed bounds (-2.0, +2.0)

**Fixed Sequence:**
1. Collect feature statistics (epochs 1-10)
2. Adaptive C51 samples from buffer → SUCCESS: 45k samples from 92k buffer
3. Calculate new bounds → (-3.18, +3.10) with 160% coverage
4. Clear replay buffer → safe after stats extracted
5. Continue training with normalized features

**Changes (ml/src/trainers/dqn.rs lines 1958-2010):**
- Moved adaptive C51 block BEFORE buffer clear
- Added buffer state diagnostics (size, min_required)
- Updated sequence comments

**Validation Results (15-epoch test):**
 Epoch 10 trigger: SUCCESS
 Buffer state: 92,399 experiences available
 Q-value stats: 45,000 samples collected
 Bounds adapted: (-2, 2) → (-3.18, 3.10)
 Coverage: 102% → 160% (+58% improvement)
 Q-value normalization: ±400 → ±0.88 (450x reduction)

**Technical Validity:**
Pre-normalized Q-values are valid for bounds calculation:
- Q-values represent learned value function, not raw features
- Feature norm (x_norm = (x - μ) / σ) doesn't affect Q distribution
- 23k+ experiences provide sufficient statistical sample
- Adaptive bounds use Q-value range, not feature range

**Impact:**
- Fixes P0 blocker preventing feature from working
- Enables 160% C51 coverage (vs 102% with fixed bounds)
- Maintains gradient stability after normalization
- No performance degradation

**Files Modified:**
- ml/src/trainers/dqn.rs (lines 1958-2010, code reordering + diagnostics)

**Logs:**
- /tmp/adaptive_c51_fix_validation.log (15-epoch successful validation)
- /tmp/ADAPTIVE_C51_VALIDATION_RESULTS.md (detailed analysis)

Refs: P0 blocker, adaptive C51 bounds, two-phase training

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 19:43:30 +01:00
..