fix: stale comments — 9-bit mask, CVaR examples, module doc, entropy max

- 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) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-03-27 10:31:11 +01:00
parent 25ee24aff4
commit 84ccf7b27c
2 changed files with 8 additions and 7 deletions

View File

@@ -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,
}

View File

@@ -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.