From 84ccf7b27cc603b841577752c0eb95eaedc0a437 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Fri, 27 Mar 2026 10:31:11 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20stale=20comments=20=E2=80=94=209-bit=20m?= =?UTF-8?q?ask,=20CVaR=20examples,=20module=20doc,=20entropy=20max?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gpu_backtest_evaluator: "5-bit mask" → "9-bit mask" (9 exposure levels) - dqn.rs CVaR ramp: updated examples to match current formula (excess*100).min(3.0) - dqn.rs module doc: "maximizes" → "minimizes", weights match actual code - entropy max_entropy: log2(3) → log2(9) in both occurrences Co-Authored-By: Claude Opus 4.6 (1M context) --- .../ml/src/cuda_pipeline/gpu_backtest_evaluator.rs | 2 +- crates/ml/src/hyperopt/adapters/dqn.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs b/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs index f3c41baa7..7d594c2b4 100644 --- a/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs +++ b/crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs @@ -157,7 +157,7 @@ pub struct WindowMetrics { pub buy_count: f32, pub sell_count: f32, pub hold_count: f32, - // Unique action IDs observed (popcount of 5-bit mask, index 13) + // Unique action IDs observed (popcount of 9-bit mask, index 13) pub unique_actions: f32, } diff --git a/crates/ml/src/hyperopt/adapters/dqn.rs b/crates/ml/src/hyperopt/adapters/dqn.rs index 3b25ef679..ae13fa3f3 100644 --- a/crates/ml/src/hyperopt/adapters/dqn.rs +++ b/crates/ml/src/hyperopt/adapters/dqn.rs @@ -10,11 +10,12 @@ //! //! ## Optimization Objective //! -//! **WAVE 17**: This adapter maximizes `backtest_sharpe_ratio` (production metric). +//! **WAVE 17**: This adapter minimizes a composite loss from `backtest_sharpe_ratio` (production metric). //! The objective uses a weighted combination: -//! - 60% Exponential Sharpe+Drawdown incentive (production metric) +//! - 50% Exponential Sharpe+Drawdown incentive (production metric) //! - 25% HFT activity score (rewards active BUY/SELL trading) //! - 15% Stability penalty (penalizes gradient explosion) +//! - 10% CVaR tail risk penalty //! //! Fallback to avg_episode_reward only if backtest is disabled or fails. //! @@ -2083,7 +2084,7 @@ fn calculate_diversity_penalty(action_distribution: &[f64; 3]) -> f64 { .collect(); let entropy = calculate_action_entropy(&*action_counts); - let max_entropy = (3.0_f64).log2(); // ~1.585 + let max_entropy = (9.0_f64).log2(); // ~3.170 // Smooth quadratic penalty: -5.0 * (1 - entropy/max_entropy)² // At entropy=0: -5.0, at entropy=max: 0.0 @@ -3376,7 +3377,7 @@ impl HyperparameterOptimizable for DQNTrainer { info!( "Action entropy: {:.4} (max_entropy={:.4}, threshold=0.5)", entropy, - (3.0_f64).log2() + (9.0_f64).log2() ); // Stability penalty raw — used directly in objective (0.15 weight in WAVE 11) @@ -3425,8 +3426,8 @@ impl HyperparameterOptimizable for DQNTrainer { // // Penalty ramp: // CVaR = -0.002 → no penalty (normal) - // CVaR = -0.005 → penalty ≈ 2.8 (elevated) - // CVaR = -0.010 → penalty ≈ 9.8 (max, dangerous) + // CVaR = -0.005 → penalty ≈ 0.25 (elevated) + // CVaR = -0.010 → penalty ≈ 0.75 (max, saturates at ~-0.033) let cvar_threshold = 0.05 / (common::thresholds::time::BARS_PER_DAY).sqrt(); // Softer ramp: cap at 3.0 instead of 10.0 to prevent CVaR // from dominating the objective for under-trained models.