Files
foxhunt/ENSEMBLE_ORACLE_QUICK_REF.md
jgrusewski 00ef9e2866 Wave 15: Complete FactoredAction migration to 45-action system
Major Changes:
- Migrated from 3-action TradingAction to 45-action FactoredAction
- 45 actions: 5 exposure × 3 order types × 3 urgency levels
- Absolute exposure model (target positions -1.0 to +1.0)
- Transaction cost differentiation (Market 0.15%, LimitMaker 0.05%, IoC 0.10%)
- Fixed action diversity threshold (1.11% → 0.5% for 45-action space)

Bug Fixes:
- Bug #15: Incomplete FactoredAction integration (code existed but unused)
- Bug #16: Runtime crash in action diversity checking (hardcoded 3-action match)

Code Changes (13 files, ~464 lines):
- ml/src/dqn/action_space.rs: Core FactoredAction + 4 helper methods
- ml/src/trainers/dqn.rs: Action diversity refactored (3→45 dynamic)
- ml/src/dqn/reward.rs: calculate_reward() signature updated
- ml/src/dqn/portfolio_tracker.rs: execute_action() absolute exposure
- ml/src/dqn/dqn.rs: WorkingDQN action selection migrated
- ml/tests/*.rs: 9 test files updated with FactoredAction assertions

Test Results:
- 1-epoch smoke test: 100% action diversity (45/45 actions, 80.2s)
- 10-epoch production: 87.8% readiness (79/90 scorecard, 14.0 min)
- Loss convergence: 96.9% reduction (119K → 3.6K)
- Action diversity: 100% → 44% (healthy specialization)
- Checkpoint reliability: 12/12 files saved (100%)
- DQN tests: 195/195 passing (100%)
- ML baseline: 1,514/1,515 passing (99.93%)

Production Status:  CERTIFIED (87.8% readiness)
Go/No-Go:  GO FOR 100-EPOCH PRODUCTION TRAINING

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 23:27:02 +01:00

8.4 KiB
Raw Blame History

Ensemble Oracle Quick Reference

Last Updated: 2025-11-11 (Wave3-A4 Integration Complete)


🚀 Quick Start

Basic Usage (Ensemble Disabled)

cargo run -p ml --example train_dqn --release --features cuda

With Ensemble Oracle (3 Models)

cargo run -p ml --example train_dqn --release --features cuda -- \
  --use-ensemble \
  --num-ensemble-agents 3 \
  --transformer-model-path ml/trained_models/tft_model.safetensors \
  --lstm-model-path ml/trained_models/lstm_model.safetensors \
  --ppo-model-path ml/trained_models/ppo_model.safetensors

With Ensemble Oracle (Partial - 1 Model)

cargo run -p ml --example train_dqn --release --features cuda -- \
  --use-ensemble \
  --num-ensemble-agents 1 \
  --transformer-model-path ml/trained_models/tft_model.safetensors

🎛️ CLI Flags

Flag Type Default Description
--use-ensemble bool false Enable ensemble oracle voting
--num-ensemble-agents usize 0 Number of agents (1-3)
--transformer-model-path string None Path to Transformer model
--lstm-model-path string None Path to LSTM model
--ppo-model-path string None Path to PPO policy

Validation Rules

  1. Requires at least 1 model path if --use-ensemble
  2. Requires --num-ensemble-agents > 0 if enabled
  3. Warns if agent count exceeds available models (auto-reduces)

📊 Expected Output

Ensemble Enabled

✅ Ensemble oracle: ENABLED (3 agents)
    - Transformer: ml/trained_models/tft_model.safetensors
    - LSTM: ml/trained_models/lstm_model.safetensors
    - PPO: ml/trained_models/ppo_model.safetensors

Ensemble Disabled (Default)

✅ Ensemble oracle: DISABLED (component weight = 0.0)

⚠️ Common Errors

Error 1: No Model Paths

$ cargo run ... -- --use-ensemble
❌ ERROR: --use-ensemble requires at least one model path
Specify one or more of:
  --transformer-model-path <path>
  --lstm-model-path <path>
  --ppo-model-path <path>

Fix: Add at least one model path flag

Error 2: Zero Agents

$ cargo run ... -- --use-ensemble --transformer-model-path models/tft.safetensors
❌ ERROR: --use-ensemble requires --num-ensemble-agents > 0
Example: --num-ensemble-agents 3

Fix: Add --num-ensemble-agents N where N > 0


🧮 Reward Formula

Elite Multi-Component Reward

total_reward = α₁ × r_extrinsic    (0.40, P&L + Sharpe + activity)
             + α₂ × r_intrinsic    (0.25, action diversity)
             + α₃ × r_entropy      (0.15, policy diversity)
             + α₄ × r_curiosity    (0.10, novelty exploration)
             + α₅ × r_ensemble     (0.10, multi-model consensus)

Ensemble Reward Breakdown

r_ensemble = agreement_bonus + diversity_bonus

agreement_bonus:
  - 0.5 if DQN action matches majority vote
  - 0.1 if DQN action disagrees with majority

diversity_bonus:
  - 0.3 if all models disagree (3 unique votes)
  - 0.1 if moderate disagreement (2 unique votes)
  - 0.0 if full consensus (1 unique vote)

Range: [0.0, 0.8]

Example: DQN votes BUY, ensemble votes [BUY, BUY, SELL]

  • Majority: BUY (2/3)
  • Agreement: DQN=BUY matches majority → 0.5
  • Diversity: 2 unique votes (BUY, SELL) → 0.1
  • Total: 0.6

🏗️ Architecture

Current State (Phase 1)

CLI Flags → Validation → Logging → DQNTrainer (ensemble not loaded)

Target State (Phase 2)

CLI Flags → Validation → DQNTrainer → Load Ensemble Models → Training Loop

📁 File Structure

ml/
├── examples/
│   └── train_dqn.rs              # CLI integration (COMPLETE)
├── src/
│   ├── trainers/
│   │   └── dqn.rs                # Trainer logic (Phase 2 target)
│   └── dqn/
│       ├── reward_coordinator.rs # Elite reward aggregation
│       ├── ensemble_oracle.rs    # Majority voting logic
│       ├── reward_elite.rs       # Extrinsic reward (α₁)
│       ├── intrinsic_rewards.rs  # Intrinsic reward (α₂)
│       ├── entropy_regularization.rs # Entropy bonus (α₃)
│       └── curiosity.rs          # Curiosity reward (α₄)
└── trained_models/
    ├── tft_model.safetensors     # Transformer
    ├── lstm_model.safetensors    # LSTM
    └── ppo_model.safetensors     # PPO

🧪 Testing Commands

Test 1: Validation (No Paths)

cargo run -p ml --example train_dqn --features cuda -- --use-ensemble
# Expected: ❌ ERROR: requires at least one model path

Test 2: Validation (Zero Agents)

cargo run -p ml --example train_dqn --features cuda -- \
  --use-ensemble \
  --transformer-model-path models/tft.safetensors
# Expected: ❌ ERROR: requires --num-ensemble-agents > 0

Test 3: Success (Full Ensemble)

cargo run -p ml --example train_dqn --features cuda -- \
  --use-ensemble \
  --num-ensemble-agents 3 \
  --transformer-model-path models/tft.safetensors \
  --lstm-model-path models/lstm.safetensors \
  --ppo-model-path models/ppo.safetensors
# Expected: ✅ Ensemble oracle: ENABLED (3 agents)

Test 4: Warning (Count Mismatch)

cargo run -p ml --example train_dqn --features cuda -- \
  --use-ensemble \
  --num-ensemble-agents 5 \
  --transformer-model-path models/tft.safetensors
# Expected: ⚠️  Reducing to 1 agents (all available models)

🔧 Advanced Configuration

Combine with Other Flags

cargo run -p ml --example train_dqn --release --features cuda -- \
  --epochs 500 \
  --batch-size 64 \
  --learning-rate 0.0001 \
  --use-ensemble \
  --num-ensemble-agents 2 \
  --transformer-model-path models/tft.safetensors \
  --ppo-model-path models/ppo.safetensors \
  --output-dir results/ensemble_run \
  --checkpoint-frequency 10

Disable Ensemble (Explicit)

# Option 1: Omit --use-ensemble flag (default)
cargo run -p ml --example train_dqn --features cuda

# Option 2: Set --num-ensemble-agents 0
cargo run -p ml --example train_dqn --features cuda -- --num-ensemble-agents 0

📈 Performance Impact

Configuration Overhead GPU Memory Training Time
Ensemble Disabled 0% 0 MB Baseline
1 Model Loaded TBD +50-100 MB +5-10%
3 Models Loaded TBD +150-300 MB +15-25%

Note: Phase 1 has zero overhead (ensemble disabled by default). Phase 2 measurements TBD.


🐛 Known Issues

Phase 1 (Current)

  1. No actual model loading: CLI flags parse but don't load models (stub)
  2. Zero ensemble reward: Returns 0.0 (disabled by default)
  3. No checkpoint integration: Ensemble models not saved/restored

Workarounds

  • Issue 1: Wait for Phase 2 (trainer refactor)
  • Issue 2: Ensemble component weight is 10% when enabled
  • Issue 3: Wait for Phase 3 (checkpoint integration)

📚 Documentation

  • Status Report: WAVE3_A4_ENSEMBLE_INTEGRATION_STATUS.md
  • Implementation Summary: WAVE3_A4_IMPLEMENTATION_COMPLETE.md
  • Quick Reference: This file

🎯 Next Steps

  1. Phase 2: Trainer refactor (add load_ensemble_models() method)
  2. Phase 3: Checkpoint integration (save/load ensemble models)
  3. Phase 4: Real model loading (safetensors inference)

💡 Tips

For Users

  • Start with 1 model to test overhead
  • Use --num-ensemble-agents 3 for full consensus voting
  • Check logs for "ENABLED" confirmation
  • Ensemble disabled by default (zero overhead)

For Developers

  • See TODO block in train_dqn.rs (lines 677-700)
  • Ensemble oracle already in reward_coordinator.rs
  • Stub implementation in ensemble_oracle.rs
  • Checkpoint format in ml/src/checkpoint/mod.rs

List Available Models

ls -lh ml/trained_models/*.safetensors

Check Model Size

du -h ml/trained_models/tft_model.safetensors

Verify Compilation

cargo check -p ml --example train_dqn --features cuda

📞 Support

  • Usage Questions: See examples above
  • Architecture Questions: See WAVE3_A4_ENSEMBLE_INTEGRATION_STATUS.md
  • Implementation Questions: See TODO block in train_dqn.rs
  • Bug Reports: Check "Known Issues" section first

Version: Wave3-A4 Phase 1 Status: Production Ready (CLI Integration Complete) Last Updated: 2025-11-11