Skip to content

fix(ml): DQN train/test split + OOS Sharpe + per-step DirAcc (#703) - #729

Merged
jsboige merged 2 commits into
mainfrom
fix/ml-dqn-train-test-split-703
May 5, 2026
Merged

jsboige merged 2 commits into
mainfrom
fix/ml-dqn-train-test-split-703

Conversation

@jsboige

@jsboige jsboige commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes Issue fix(ml-training): train_dqn_rl.py — pas de train/test split, Sharpe in-sample (data leakage) #703: DQN train/test split now honored with proper OOS evaluation
  • evaluate_dqn() now computes per-step direction accuracy (was: fold-level reward sign match)
  • Walk-forward mode reports per-fold OOS Sharpe and aggregate OOS Sharpe
  • Simple split mode now prominently reports OOS metrics, marking in-sample Sharpe as "NOT reliable"
  • Walk-forward checkpoint metadata now has correct state_size/hidden_size/n_actions (was state_size=0)

Changes

scripts/train_dqn_rl.py

  • evaluate_dqn(): Added per-step direction tracking — counts steps where reward>0 (position aligned with price move) vs reward<0 (misaligned). Returns oos_direction_accuracy and oos_direction_total.
  • train_walk_forward_dqn():
    • Aggregates direction accuracy across all test steps (not fold-level sign match)
    • Reports oos_sharpe (aggregate across folds) in metrics
    • Per-fold details now include oos_sharpe and oos_direction_accuracy
    • Best model selection uses OOS direction accuracy instead of reward
    • Returns state_size, hidden_size, n_actions for proper checkpoint saving
  • main(): Walk-forward checkpoint saves proper architecture info. Print output now includes OOS Sharpe.

scripts/tests/test_walk_forward_training.py

  • 3 new TestDQNEvaluateOOS tests: direction accuracy present, greedy deterministic
  • 1 new TestDQNSimpleSplit test: verifies OOS metrics from train/test split
  • 2 updated TestWalkForwardDQN tests: verify oos_sharpe, oos_direction_accuracy in fold details, architecture info, non-NaN metrics

Test plan

  • 19/19 walk-forward tests pass (Classification + LSTM + Transformer + DQN)
  • --dry-run --walk-forward produces OOS DirAcc, OOS Sharpe, majority-class baseline
  • Greedy policy is deterministic (same model + env → same result)
  • GPU walk-forward on SPY panier assets (Track D — requires GPU time)

Addresses

🤖 Generated with Claude Code

@jsboige jsboige left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review #729 — DQN OOS DirAcc + Sharpe

Fix: SOLID

  • Per-step direction accuracy in evaluate_dqn() (reward > 0 = correct direction)
  • Model selection changed from reward to OOS diracc
  • Aggregate Sharpe across folds
  • IS Sharpe clearly labeled as unreliable in output
  • Tests cover oos_sharpe and architecture info

Note: PR is DIRTY (mergeable: false) — needs rebase before merge.

Verdict: APPROVE (pending rebase)

Fix addresses the core issues. Rebase needed.

…on accuracy (#703)

- evaluate_dqn() now tracks per-step direction accuracy (position aligned with
  price move) instead of just aggregate reward sign
- train_walk_forward_dqn() reports per-fold OOS Sharpe and aggregates direction
  accuracy across all test steps (not just fold-level reward sign)
- Walk-forward result now includes state_size/hidden_size/n_actions for proper
  checkpoint metadata (was state_size=0 before)
- Simple split mode now prominently reports OOS Sharpe + DirAcc, marking
  in-sample Sharpe as "NOT reliable"
- Best model selection uses OOS direction accuracy instead of reward
- 8 new/updated tests: DQN architecture info, OOS metrics non-NaN, greedy
  policy deterministic, simple split OOS validation

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@clusterManager-Myia clusterManager-Myia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review #729 — DQN OOS DirAcc + Sharpe tests

Scope: tests only (1 file, +137 lines)

All changes are in test_walk_forward_training.py — no production code modified.

Tests added (5 new test methods across 3 classes):

  1. TestWalkForwardDQN — existing class extended:

    • oos_sharpe assertion in required metrics
    • oos_sharpe + oos_direction_accuracy in fold details
    • test_walk_forward_returns_architecture_info — validates state/hidden/action sizes
    • test_walk_forward_oos_metrics_not_nan — NaN guard for key metrics
  2. TestDQNEvaluateOOS (new class):

    • test_evaluate_dqn_returns_direction_accuracy — validates output schema + bounds
    • test_evaluate_dqn_greedy_no_exploration — determinism check (greedy policy = same results)
  3. TestDQNSimpleSplit (new class):

    • test_simple_split_reports_oos_metrics — end-to-end train→eval on split data, IS vs OOS Sharpe comparison

Quality: GOOD

  • Proper normalization (train-only mean/std for test features)
  • Deterministic greedy evaluation verified
  • NaN guards on critical metrics
  • IS vs OOS separation validated

Note: PR self-review (COMMENT) from author is NOT an external review. This is the first external review.

Verdict: APPROVE

Solid test coverage for #703 DQN OOS evaluation. Clean, well-structured.

— clusterManager-Myia

…after rebase

After rebasing fix/ml-dqn-train-test-split-703 on main, the --ours
conflict resolution dropped PR #729's additions. This commit restores:
- oos_sharpe, oos_direction_accuracy per fold in walk-forward results
- state_size, hidden_size, n_actions in return dict
- evaluate_dqn now reports oos_direction_accuracy and oos_direction_total
- Fixed classification test assertion (accuracy -> oos_accuracy)

All 19/19 walk-forward tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jsboige
jsboige merged commit b6750fe into main May 5, 2026
1 check passed
@jsboige
jsboige deleted the fix/ml-dqn-train-test-split-703 branch May 5, 2026 02:05
myia-po-2023 pushed a commit that referenced this pull request Aug 15, 2026
…tale/needs rebase)

18 flags / 249 PRs triaged on #11044. 11 FLAG-OK (0 DEFECT-ALIVE on main),
7 FLAG-FP of which 3 mechanized as CITERS:

- "pas": FP #860 « **COMMENTED** (pas CHANGES_REQUESTED) » — French
  negation without « de » (bare form not covered by "pas de").
- "stale": FP #977 « pending dismissal of stale CHANGES_REQUESTED » —
  re-review request narrating a past reserve.
- "needs rebase": FP #887 « CONFLICTING — needs rebase before merge » —
  procedural demand satisfied by the merge itself (recidive of #729,
  window 05-01..05-07, retroactively covered).

Acceptance: 28 tests pass; harness replays 51 corpus PRs — 11 FP
unflagged, 40 NON-LEVE still flagged.

Co-Authored-By: Claude-Code <noreply@anthropic.com>
jsboige added a commit that referenced this pull request Aug 15, 2026
… flag (+9 regression tests) (#11084)

* feat(guard,#11044): recalibrate FP organ — cited verdicts no longer flag as concerns

Measured defect (triage po-2024:CoursIA-2, window 07-14..07-20): 11/64 flagged
signals were positive reviews quoting a verdict they did not emit ("No
CHANGES_REQUESTED", "Verdict : COMMENT_WITHOUT_CONCERNS", "the CHANGES_REQUESTED
reflects a pre-fix state"). An organ crying wolf 17% of the time is an organ
that gets ignored — the exact mechanism by which the 42 real nits slipped
through.

Four calibrated layers, each anchored to named PRs:
- CITERS (occurrence-level citation guard): negation ("No", "Pas de",
  "without"), definite-article narration ("the"), hypothetical modals
  ("would") in the 30 chars before a marker kill that occurrence.
- VERDICT_POSITIVE ("COMMENT_WITHOUT_CONCERNS"): formal verdict overrides
  prose concern counts (#7583/#7593 resolution narrations).
- POSITIVE_MARKERS (soft: "SAFE/Safe to merge", "Verdict : OK"): rescue only
  bodies with no live concern — mixed Hermes reviews keep flagging.
- New CONCERN_MARKERS "SCOPE FLAG"/"scope mismatch": #7298 was caught only by
  accident; the class was invisible. Recovered 7 true positives on 07-18 alone.

Acceptance (falsifiable, per ai-01 Phase 2): the 11 named FPs (#6291 #6699
#6986 #7233 #7243 #7248 #7252 #7284 #7286 #7583 #7593) no longer flag; the 42
NON-LEVE still flag (40 distinct PRs replayed, all >=1 signal kept); founder
#10761 still flags (2 signals). End-to-end audit 07-14..07-20 (saturated 400,
07-18->07-20): 26 -> 25 flagged, -8 FP, +7 genuine SCOPE FLAGs.

Tests: 13 -> 22 (FP classes, mixed-review and emitted-verdict guards).

Co-Authored-By: Claude-Code <noreply@anthropic.com>

* fix(#11045): cover English 'before merge' demand phrasing (2 measured FNs #594/#590)

Window 04-23..04-30 triage (Epic #11044) exposed 2 false negatives: PRs
merged with zero lift while reviews demanded 'issues that should be
addressed before merge' (#594) and 'CRITICAL - Must fix before merge'
(#590). 'avant merge' was already a marker; its English mirror was not.
One marker covers both FNs. Acceptance re-run: 11 FP unflagged, 40
NON-LEVE still flagged, both FN PRs now flag, 24/24 tests.

Co-Authored-By: Claude-Code <noreply@anthropic.com>

* fix(#11045): treat 'previous' as citation word (narrated retraction FP #748)

Window 05-01..05-07 triage (Epic #11044): PR #748's flagged signals were
the retraction itself - 'CORRECTION - Previous CHANGES_REQUESTED was
incorrect... Revised verdict: APPROVE' plus the bot's 'APPROVE -
previous CHANGES_REQUESTED retracted'. 'previous' can only narrate a
past demand, never issue one. Acceptance re-run: 11 FP unflagged, 40
NON-LEVE still flagged, #748 unflagged, FN corpus #594/#590 and the 5
FLAG-OK of the window still flagged, 25/25 tests.

Co-Authored-By: Claude-Code <noreply@anthropic.com>

* feat(nits,#11044): 3 narration citers from window 05-08..05-14 (pas/stale/needs rebase)

18 flags / 249 PRs triaged on #11044. 11 FLAG-OK (0 DEFECT-ALIVE on main),
7 FLAG-FP of which 3 mechanized as CITERS:

- "pas": FP #860 « **COMMENTED** (pas CHANGES_REQUESTED) » — French
  negation without « de » (bare form not covered by "pas de").
- "stale": FP #977 « pending dismissal of stale CHANGES_REQUESTED » —
  re-review request narrating a past reserve.
- "needs rebase": FP #887 « CONFLICTING — needs rebase before merge » —
  procedural demand satisfied by the merge itself (recidive of #729,
  window 05-01..05-07, retroactively covered).

Acceptance: 28 tests pass; harness replays 51 corpus PRs — 11 FP
unflagged, 40 NON-LEVE still flagged.

Co-Authored-By: Claude-Code <noreply@anthropic.com>

* feat(nits,#11044): arrow-citer for conditional verdicts from window 05-15..05-21

8 flags / 194 PRs triaged on #11044. 6 FLAG-OK (1 DEFECT-UNMEASURED
visual QA #1253, rest DEFECT-NONE), 2 FLAG-FP:

- #1247 « Si Static validation rouge → CHANGES_REQUESTED » : conditional
  future verdict. An arrow immediately before a marker is a derivation,
  never an emission — handled in _is_cited (not CITERS) since the arrow
  is not a word.
- #1138 « Awaiting ... review before merge » : procedural note, accepted
  as residual FP (the awaited review flags on its own concerns).

Acceptance: 30 tests pass; harness replays 51 corpus PRs — 11 FP
unflagged, 40 NON-LEVE still flagged.

Co-Authored-By: Claude-Code <noreply@anthropic.com>

---------

Co-authored-by: jsboige <jsboige@gmail.com>
Co-authored-by: Claude-Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants