refactor(ml): remove 797 lines of commented-out code and disabled imports
Removed across 66 files:
- 49 instances of "// use crate::safe_operations; // DISABLED"
- 11 instances of "// use error_handling::{...}; // crate doesn't exist"
- 2 instances of "// use crate::Optimizer; // not available"
- 5 disabled test placeholder blocks (/* ... */) in ensemble/
- 1 disabled From impl in lib.rs (38 lines)
- 1 disabled test module in model.rs (113 lines)
- 1 disabled code block in integration/distillation.rs (41 lines)
- Various other disabled imports with explanation comments
All of this code references modules/crates that were removed during
prior refactoring waves and is preserved in git history. Removing it
reduces noise and makes the codebase easier to navigate.
1922 lib tests passing, compilation clean.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -282,7 +282,7 @@ impl CompressionStats {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_compression_manager() -> Result<(), MLError> {
|
||||
|
||||
@@ -872,7 +872,7 @@ impl CheckpointManager {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
// Mock model for testing
|
||||
struct MockModel {
|
||||
|
||||
@@ -375,7 +375,7 @@ impl Default for ValidationReport {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use chrono::Utc;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_checksum_validation() {
|
||||
|
||||
@@ -452,7 +452,7 @@ pub type MigrationHandler = fn(&[u8]) -> Result<Vec<u8>, MLError>;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_semantic_version_parsing() -> Result<(), MLError> {
|
||||
|
||||
@@ -9,7 +9,6 @@ use crate::Adam;
|
||||
use candle_core::Tensor;
|
||||
use candle_nn::{ops::leaky_relu, Module, VarBuilder};
|
||||
use candle_optimisers::adam::ParamsAdam; // Use our Adam wrapper from lib.rs
|
||||
// use crate::Optimizer; // Optimizer trait not available in candle v0.9
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::debug;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ use candle_nn::ops::leaky_relu;
|
||||
use candle_nn::Module;
|
||||
use candle_nn::{Linear, VarBuilder, VarMap};
|
||||
use candle_optimisers::adam::ParamsAdam;
|
||||
// use crate::Optimizer; // Optimizer trait not available in candle v0.9
|
||||
use rand::{thread_rng, Rng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::debug;
|
||||
@@ -2589,7 +2588,7 @@ impl DQN {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::dqn::Experience;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_working_dqn_creation() -> anyhow::Result<()> {
|
||||
|
||||
@@ -423,7 +423,7 @@ impl QNetwork {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_qnetwork_creation() -> anyhow::Result<()> {
|
||||
|
||||
@@ -105,7 +105,7 @@ impl DQNPerformanceValidator {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_performance_validator_creation() {
|
||||
|
||||
@@ -211,7 +211,7 @@ impl ReplayBuffer {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
fn create_test_experience(reward: f32) -> Experience {
|
||||
Experience::new(vec![1.0, 2.0, 3.0], 1, reward, vec![1.1, 2.1, 3.1], false)
|
||||
|
||||
@@ -1041,7 +1041,7 @@ pub fn calculate_batch_rewards(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
/// Create test state with proper 128-dim structure
|
||||
///
|
||||
|
||||
@@ -229,7 +229,7 @@ impl FinancialDatasetBuilder {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use candle_core::{DType, Device};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_financial_dataset_builder() {
|
||||
|
||||
@@ -11,139 +11,3 @@ impl ConfidenceCalculator {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// DISABLED: Tests require missing types (ConfidenceConfig, SignalStatistics, etc.)
|
||||
// Fix after implementing proper confidence calculation API
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use crate::ensemble::{ModelSignal, SignalMetadata};
|
||||
|
||||
fn create_test_signal(
|
||||
model_id: &str,
|
||||
signal: f32,
|
||||
confidence: f32,
|
||||
model_type: &str,
|
||||
) -> ModelSignal {
|
||||
ModelSignal {
|
||||
model_id: model_id.to_string(),
|
||||
signal,
|
||||
confidence,
|
||||
timestamp: std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_nanos() as u64)
|
||||
.unwrap_or(0),
|
||||
metadata: SignalMetadata {
|
||||
model_version: model_type.to_string(),
|
||||
features_used: vec![],
|
||||
prediction_horizon: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_confidence_calculation() {
|
||||
let config = ConfidenceConfig::default();
|
||||
let calculator = ConfidenceCalculator::new(config);
|
||||
|
||||
let signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", 0.7, 0.8, "lstm"),
|
||||
];
|
||||
|
||||
let statistics = SignalStatistics {
|
||||
model_count: 2,
|
||||
variance: 0.05,
|
||||
agreement_ratio: 1.0,
|
||||
avg_confidence: 0.85,
|
||||
..SignalStatistics::default()
|
||||
};
|
||||
|
||||
let confidence = calculator.calculate_ensemble_confidence(&signals, 0.75, &statistics)?;
|
||||
|
||||
assert!(confidence > 0.0);
|
||||
assert!(confidence <= 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_agreement_score() {
|
||||
let config = ConfidenceConfig::default();
|
||||
let calculator = ConfidenceCalculator::new(config);
|
||||
|
||||
// All signals agree (same direction)
|
||||
let agreeing_signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", 0.6, 0.8, "lstm"),
|
||||
];
|
||||
|
||||
let agreement_score = calculator.calculate_agreement_score(&agreeing_signals, 0.7);
|
||||
assert!(agreement_score > 0.8); // Should be high
|
||||
|
||||
// Conflicting signals
|
||||
let conflicting_signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", -0.6, 0.8, "lstm"),
|
||||
];
|
||||
|
||||
let conflict_score = calculator.calculate_agreement_score(&conflicting_signals, 0.1);
|
||||
assert!(conflict_score < 0.6); // Should be lower
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_diversity_score() {
|
||||
let config = ConfidenceConfig::default();
|
||||
let calculator = ConfidenceCalculator::new(config);
|
||||
|
||||
// High diversity (different model types)
|
||||
let diverse_signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", 0.6, 0.8, "lstm"),
|
||||
create_test_signal("model3", 0.7, 0.85, "transformer"),
|
||||
];
|
||||
|
||||
let diversity_score = calculator.calculate_diversity_score(&diverse_signals);
|
||||
assert!(diversity_score > 0.5);
|
||||
|
||||
// Low diversity (same model type)
|
||||
let similar_signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", 0.6, 0.8, "dqn"),
|
||||
create_test_signal("model3", 0.7, 0.85, "dqn"),
|
||||
];
|
||||
|
||||
let similar_score = calculator.calculate_diversity_score(&similar_signals);
|
||||
assert!(similar_score < diversity_score);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_model_performance_update() {
|
||||
let config = ConfidenceConfig::default();
|
||||
let mut calculator = ConfidenceCalculator::new(config);
|
||||
|
||||
calculator.update_model_performance("model1", 0.8, 0.1, 1.5);
|
||||
let performance = calculator.get_model_performance("model1")?;
|
||||
|
||||
assert_eq!(performance.accuracy, 0.08); // 0.0 * 0.9 + 0.8 * 0.1
|
||||
assert_eq!(performance.prediction_count, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_confidence_bounds() {
|
||||
let config = ConfidenceConfig::default();
|
||||
let calculator = ConfidenceCalculator::new(config);
|
||||
|
||||
let signals = vec![
|
||||
create_test_signal("model1", 0.8, 0.9, "dqn"),
|
||||
create_test_signal("model2", 0.6, 0.8, "lstm"),
|
||||
];
|
||||
|
||||
let (lower, upper) = calculator.calculate_confidence_bounds(&signals, 0.7);
|
||||
|
||||
assert!(lower < upper);
|
||||
assert!(lower >= -1.0);
|
||||
assert!(upper <= 1.0);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -386,174 +386,3 @@ fn current_timestamp() -> u64 {
|
||||
.unwrap_or_default()
|
||||
.as_millis() as u64
|
||||
}
|
||||
|
||||
/*
|
||||
// DISABLED: Tests require proper ensemble API implementation
|
||||
// Fix after completing ensemble model infrastructure
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn create_test_ensemble() -> EnsembleModel {
|
||||
let config = EnsembleConfig::default();
|
||||
EnsembleModel::new(config)?
|
||||
}
|
||||
|
||||
fn create_test_signal(model_id: &str, signal: f32, confidence: f32) -> ModelSignal {
|
||||
ModelSignal {
|
||||
model_id: model_id.to_string(),
|
||||
signal,
|
||||
confidence,
|
||||
timestamp: current_timestamp(),
|
||||
metadata: SignalMetadata {
|
||||
model_version: "1.0".to_string(),
|
||||
features_used: vec!["test_feature".to_string()],
|
||||
prediction_horizon: 50,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ensemble_creation() {
|
||||
let ensemble = create_test_ensemble();
|
||||
let metrics = ensemble.get_metrics()?;
|
||||
|
||||
assert_eq!(metrics.total_models, 0);
|
||||
assert_eq!(metrics.active_models, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_model_registration() {
|
||||
let ensemble = create_test_ensemble();
|
||||
|
||||
let result = ensemble.register_model(
|
||||
"test_model",
|
||||
"momentum",
|
||||
"1.0",
|
||||
vec!["price".to_string(), "volume".to_string()],
|
||||
100,
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(ensemble.list_models().len(), 1);
|
||||
assert_eq!(ensemble.list_models()[0], "test_model");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_signal_submission_and_aggregation() {
|
||||
let ensemble = create_test_ensemble();
|
||||
|
||||
// Register models
|
||||
ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?;
|
||||
ensemble.register_model(
|
||||
"model2",
|
||||
"mean_reversion",
|
||||
"1.0",
|
||||
vec!["price".to_string()],
|
||||
60,
|
||||
)?;
|
||||
|
||||
// Submit signals
|
||||
let signal1 = create_test_signal("model1", 0.8, 0.9);
|
||||
let signal2 = create_test_signal("model2", 0.6, 0.8);
|
||||
|
||||
ensemble.submit_signal(signal1)?;
|
||||
ensemble.submit_signal(signal2)?;
|
||||
|
||||
// Aggregate signals
|
||||
let result = ensemble.aggregate_signals();
|
||||
assert!(result.is_ok());
|
||||
|
||||
let ensemble_signal = result?;
|
||||
assert!(ensemble_signal.value > 0.0);
|
||||
assert!(ensemble_signal.confidence > 0.0);
|
||||
assert_eq!(ensemble_signal.contributing_models, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insufficient_models() {
|
||||
let mut config = EnsembleConfig::default();
|
||||
config.min_models = 3;
|
||||
let ensemble = EnsembleModel::new(config)?;
|
||||
|
||||
// Register only 2 models
|
||||
ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?;
|
||||
ensemble.register_model(
|
||||
"model2",
|
||||
"mean_reversion",
|
||||
"1.0",
|
||||
vec!["price".to_string()],
|
||||
60,
|
||||
)?;
|
||||
|
||||
let signal1 = create_test_signal("model1", 0.8, 0.9);
|
||||
let signal2 = create_test_signal("model2", 0.6, 0.8);
|
||||
|
||||
ensemble.submit_signal(signal1)?;
|
||||
ensemble.submit_signal(signal2)?;
|
||||
|
||||
// Should fail due to insufficient models
|
||||
let result = ensemble.aggregate_signals();
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_health_check() {
|
||||
let ensemble = create_test_ensemble();
|
||||
|
||||
// Initially should be critical (no models)
|
||||
let health = ensemble.health_check();
|
||||
assert_eq!(health.status, HealthStatus::Critical);
|
||||
|
||||
// Register enough models
|
||||
ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?;
|
||||
ensemble.register_model(
|
||||
"model2",
|
||||
"mean_reversion",
|
||||
"1.0",
|
||||
vec!["price".to_string()],
|
||||
60,
|
||||
)?;
|
||||
ensemble.register_model("model3", "momentum", "1.0", vec!["volume".to_string()], 70)?;
|
||||
|
||||
let health = ensemble.health_check();
|
||||
assert_eq!(health.status, HealthStatus::Healthy);
|
||||
assert_eq!(health.total_models, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_model_unregistration() {
|
||||
let ensemble = create_test_ensemble();
|
||||
|
||||
ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?;
|
||||
assert_eq!(ensemble.list_models().len(), 1);
|
||||
|
||||
ensemble.unregister_model("model1")?;
|
||||
assert_eq!(ensemble.list_models().len(), 0);
|
||||
|
||||
// Should fail to unregister non-existent model
|
||||
let result = ensemble.unregister_model("nonexistent");
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_market_regime_update() {
|
||||
let ensemble = create_test_ensemble();
|
||||
|
||||
ensemble.register_model("momentum", "momentum", "1.0", vec!["price".to_string()], 50)?;
|
||||
ensemble.register_model(
|
||||
"mean_rev",
|
||||
"mean_reversion",
|
||||
"1.0",
|
||||
vec!["price".to_string()],
|
||||
60,
|
||||
)?;
|
||||
|
||||
// Update regime and check that it's reflected in metrics
|
||||
ensemble.update_market_regime(MarketRegime::Trending);
|
||||
|
||||
let metrics = ensemble.get_metrics()?;
|
||||
assert_eq!(metrics.current_regime, MarketRegime::Trending);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -83,164 +83,3 @@ pub struct VotingResult {
|
||||
pub strategy_used: VotingStrategy,
|
||||
pub excluded_models: usize,
|
||||
}
|
||||
|
||||
/*
|
||||
// DISABLED: Tests require proper voting API implementation
|
||||
// Fix after completing voting system infrastructure
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn create_test_signals() -> Vec<ModelSignal> {
|
||||
vec![
|
||||
ModelSignal {
|
||||
model_id: "model1".to_string(),
|
||||
signal: 0.8,
|
||||
confidence: 0.9,
|
||||
timestamp: 1000,
|
||||
metadata: SignalMetadata {
|
||||
model_version: "1.0".to_string(),
|
||||
features_used: vec!["price".to_string(), "volume".to_string()],
|
||||
prediction_horizon: 50,
|
||||
},
|
||||
},
|
||||
ModelSignal {
|
||||
model_id: "model2".to_string(),
|
||||
signal: 0.6,
|
||||
confidence: 0.8,
|
||||
timestamp: 1001,
|
||||
metadata: SignalMetadata {
|
||||
model_version: "1.1".to_string(),
|
||||
features_used: vec!["price".to_string()],
|
||||
prediction_horizon: 30,
|
||||
},
|
||||
},
|
||||
ModelSignal {
|
||||
model_id: "model3".to_string(),
|
||||
signal: 0.9,
|
||||
confidence: 0.95,
|
||||
timestamp: 1002,
|
||||
metadata: SignalMetadata {
|
||||
model_version: "2.0".to_string(),
|
||||
features_used: vec![
|
||||
"price".to_string(),
|
||||
"volume".to_string(),
|
||||
"volatility".to_string(),
|
||||
],
|
||||
prediction_horizon: 80,
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_weighted_average_voting() -> Result<(), MLError> {
|
||||
let config = VotingConfig::default();
|
||||
let mut voter = EnsembleVoter::new(config);
|
||||
let signals = create_test_signals();
|
||||
|
||||
let mut weights = HashMap::new();
|
||||
weights.insert("model1".to_string(), 0.4);
|
||||
weights.insert("model2".to_string(), 0.3);
|
||||
weights.insert("model3".to_string(), 0.3);
|
||||
|
||||
let result = voter.aggregate_signals(&signals, &weights)?;
|
||||
|
||||
assert!(result.signal > 0.0);
|
||||
assert!(result.confidence > 0.0);
|
||||
assert_eq!(result.participating_models, 1);
|
||||
assert_eq!(result.strategy_used, VotingStrategy::WeightedAverage);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_confidence_weighted_voting() -> Result<(), MLError> {
|
||||
let mut config = VotingConfig::default();
|
||||
config.strategy = VotingStrategy::ConfidenceWeighted;
|
||||
config.dynamic_strategy = false;
|
||||
|
||||
let mut voter = EnsembleVoter::new(config);
|
||||
let signals = create_test_signals();
|
||||
let weights = HashMap::new(); // Empty weights for confidence-weighted
|
||||
|
||||
let result = voter.aggregate_signals(&signals, &weights)?;
|
||||
|
||||
// Model3 has highest confidence, so result should be closer to 0.9
|
||||
assert!(result.signal > 0.0);
|
||||
assert_eq!(result.strategy_used, VotingStrategy::ConfidenceWeighted);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_outlier_rejection() -> Result<(), MLError> {
|
||||
let mut config = VotingConfig::default();
|
||||
config.strategy = VotingStrategy::Robust;
|
||||
config.dynamic_strategy = false;
|
||||
config.outlier_threshold = 1.0; // Tight threshold
|
||||
|
||||
let mut voter = EnsembleVoter::new(config);
|
||||
|
||||
// Create signals with one outlier
|
||||
let mut signals = create_test_signals();
|
||||
signals.push(ModelSignal {
|
||||
model_id: "outlier".to_string(),
|
||||
signal: 5.0, // Clear outlier
|
||||
confidence: 0.9,
|
||||
timestamp: 1003,
|
||||
metadata: SignalMetadata {
|
||||
model_version: "2.0".to_string(),
|
||||
features_used: vec!["experimental".to_string()],
|
||||
prediction_horizon: 100,
|
||||
},
|
||||
});
|
||||
|
||||
let weights = HashMap::new();
|
||||
let result = voter.aggregate_signals(&signals, &weights)?;
|
||||
|
||||
// Should exclude the outlier
|
||||
// excluded_models is usize, so >= 0 is always true
|
||||
assert!(result.signal < 2.0); // Should not be influenced by outlier
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_strategy_selection() -> Result<(), MLError> {
|
||||
let mut config = VotingConfig::default();
|
||||
config.dynamic_strategy = true;
|
||||
|
||||
let mut voter = EnsembleVoter::new(config);
|
||||
let signals = create_test_signals();
|
||||
let weights = HashMap::new();
|
||||
|
||||
let result = voter.aggregate_signals(&signals, &weights)?;
|
||||
|
||||
// Strategy should be selected automatically
|
||||
assert!(matches!(
|
||||
result.strategy_used,
|
||||
VotingStrategy::WeightedAverage
|
||||
| VotingStrategy::ConfidenceWeighted
|
||||
| VotingStrategy::Adaptive
|
||||
| VotingStrategy::Robust
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minimum_confidence_threshold() -> Result<(), MLError> {
|
||||
let mut config = VotingConfig::default();
|
||||
config.minimum_confidence = 0.85; // High threshold
|
||||
config.dynamic_strategy = false;
|
||||
|
||||
let mut voter = EnsembleVoter::new(config);
|
||||
let signals = create_test_signals();
|
||||
let weights = HashMap::new();
|
||||
|
||||
let result = voter.aggregate_signals(&signals, &weights)?;
|
||||
|
||||
// Should exclude model2 (confidence 0.8) and possibly model1 (confidence 0.9)
|
||||
// excluded_models and participating_models are usize, so >= 0 is always true
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -134,107 +134,3 @@ pub fn calculate_entropy(weights: &HashMap<String, f64>) -> f64 {
|
||||
}
|
||||
entropy
|
||||
}
|
||||
|
||||
/*
|
||||
// DISABLED: Tests require proper weight management API implementation
|
||||
// Fix after completing weight management infrastructure
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn test_model_weights_initialization() {
|
||||
let weights = ModelWeights::new();
|
||||
let model_ids = vec![
|
||||
"model1".to_string(),
|
||||
"model2".to_string(),
|
||||
"model3".to_string(),
|
||||
];
|
||||
|
||||
weights.initialize_equal_weights(&model_ids);
|
||||
|
||||
assert_eq!(weights.model_count(), 3);
|
||||
assert!((weights.get_weight("model1") - 1.0 / 3.0).abs() < 1e-10);
|
||||
assert!((weights.get_weight("model2") - 1.0 / 3.0).abs() < 1e-10);
|
||||
assert!((weights.get_weight("model3") - 1.0 / 3.0).abs() < 1e-10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_performance_metrics_update() {
|
||||
let mut metrics = ModelPerformanceMetrics::new("test_model".to_string());
|
||||
let config = WeightConfig::default();
|
||||
|
||||
// Update with good performance
|
||||
metrics.update_performance(0.1, 100.0, &config);
|
||||
assert!(metrics.accuracy > 0.5);
|
||||
assert!(metrics.recent_pnl > 0.0);
|
||||
|
||||
// Update with bad performance
|
||||
metrics.update_performance(2.0, -50.0, &config);
|
||||
assert!(metrics.performance_score() > 0.0); // Should still be positive but lower
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dynamic_weight_manager() {
|
||||
let config = WeightConfig::default();
|
||||
let manager = DynamicWeightManager::new(config);
|
||||
|
||||
// Register models
|
||||
manager.register_model("momentum", "momentum")?;
|
||||
manager.register_model("mean_reversion", "mean_reversion")?;
|
||||
|
||||
// Update performance
|
||||
manager.update_model_performance("momentum", 0.1, 100.0)?;
|
||||
manager.update_model_performance("mean_reversion", 0.5, -20.0)?;
|
||||
|
||||
let weights = manager.get_weights();
|
||||
assert_eq!(weights.len(), 2);
|
||||
|
||||
// Momentum should have higher weight due to better performance
|
||||
assert!(weights["momentum"] >= weights["mean_reversion"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_regime_adaptation() {
|
||||
let mut config = WeightConfig::default();
|
||||
config.regime_adaptation = true;
|
||||
let manager = DynamicWeightManager::new(config);
|
||||
|
||||
manager.register_model("momentum", "momentum")?;
|
||||
manager.register_model("mean_reversion", "mean_reversion")?;
|
||||
|
||||
// Set trending regime - should favor momentum
|
||||
manager.update_market_regime(MarketRegime::Trending);
|
||||
let weights_trending = manager.get_weights();
|
||||
|
||||
// Set sideways regime - should favor mean reversion
|
||||
manager.update_market_regime(MarketRegime::Sideways);
|
||||
let weights_sideways = manager.get_weights();
|
||||
|
||||
// In trending markets, momentum models should get higher weights
|
||||
// In sideways markets, mean reversion models should get higher weights
|
||||
// (This test assumes the models have similar base performance)
|
||||
assert_ne!(weights_trending, weights_sideways);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_entropy_calculation() {
|
||||
let mut weights = HashMap::new();
|
||||
weights.insert("model1".to_string(), 1.0);
|
||||
weights.insert("model2".to_string(), 0.0);
|
||||
weights.insert("model3".to_string(), 0.0);
|
||||
|
||||
let entropy_concentrated = calculate_entropy(&weights);
|
||||
|
||||
weights.insert("model1".to_string(), 1.0 / 3.0);
|
||||
weights.insert("model2".to_string(), 1.0 / 3.0);
|
||||
weights.insert("model3".to_string(), 1.0 / 3.0);
|
||||
|
||||
let entropy_uniform = calculate_entropy(&weights);
|
||||
|
||||
// Uniform distribution should have higher entropy
|
||||
assert!(entropy_uniform > entropy_concentrated);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -53,17 +53,14 @@ mod tests {
|
||||
let error_str = inference_error.to_string();
|
||||
assert!(error_str.contains("Test inference error"));
|
||||
assert!(error_str.contains("test_model"));
|
||||
// assert_eq!(inference_error.severity(), ErrorSeverity::High); // Commented out - ErrorSeverity not available
|
||||
|
||||
let training_error = ml_training_error("Test training error", None);
|
||||
let error_str = training_error.to_string();
|
||||
assert!(error_str.contains("Test training error"));
|
||||
// assert_eq!(training_error.severity(), ErrorSeverity::High); // Commented out - ErrorSeverity not available
|
||||
|
||||
let validation_error = ml_validation_error("input", "Invalid input shape");
|
||||
let error_str = validation_error.to_string();
|
||||
assert!(error_str.contains("input"));
|
||||
assert!(error_str.contains("Invalid input shape"));
|
||||
// assert_eq!(validation_error.severity(), ErrorSeverity::Medium); // Commented out - ErrorSeverity not available
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,9 +237,6 @@ async fn run_basic_dqn_example(config: &ExampleConfig) -> Result<ExampleMetrics,
|
||||
|
||||
/// Run Rainbow `DQN` example with advanced `DQN` features
|
||||
async fn run_rainbow_dqn_example(config: &ExampleConfig) -> Result<ExampleMetrics, MLError> {
|
||||
// TEMPORARILY COMMENTED OUT - Rainbow types not yet available
|
||||
// use crate::dqn::{RainbowDQNConfig, RainbowDQNAgent};
|
||||
|
||||
// Configure Rainbow DQN with all advanced features
|
||||
#[derive(Debug, Clone)]
|
||||
struct RainbowDQNConfig {
|
||||
@@ -397,9 +394,6 @@ async fn run_rainbow_dqn_example(config: &ExampleConfig) -> Result<ExampleMetric
|
||||
|
||||
/// Run transformer example with actual attention-based model
|
||||
async fn run_transformer_example(_config: &ExampleConfig) -> Result<ExampleMetrics, MLError> {
|
||||
// TEMPORARILY COMMENTED OUT - TLOB transformer types not available
|
||||
// use crate::tlob::{TLOBTransformer, TlobTransformerConfig};
|
||||
|
||||
// PLACEHOLDER IMPLEMENTATION - Transformer types not yet available
|
||||
Ok(ExampleMetrics {
|
||||
score: Decimal::try_from(0.85).unwrap_or(Decimal::ZERO),
|
||||
|
||||
@@ -13,7 +13,7 @@ use candle_core::{Device, Tensor, DType, Result as CandleResult};
|
||||
use crate::error::ModelError;
|
||||
use super::*;
|
||||
use super::{FlashAttention3Config, SparsePatternType};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
//[test]
|
||||
fn test_block_sparse_pattern_creation() -> Result<(), ModelError> {
|
||||
|
||||
@@ -12,7 +12,7 @@ use candle_core::{Device, Tensor, DType, Result as CandleResult};
|
||||
use crate::error::ModelError;
|
||||
use super::*;
|
||||
use super::FlashAttention3Config;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
//[test]
|
||||
fn test_causal_mask_optimizer_creation() -> Result<(), ModelError> {
|
||||
|
||||
@@ -10,57 +10,16 @@
|
||||
mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_distillation_manager_creation() {
|
||||
// let config = IntegrationHubConfig::default();
|
||||
// let manager = DistillationManager::new(&config);
|
||||
//
|
||||
// let models = manager.list_student_models().await;
|
||||
// assert!(models.is_empty());
|
||||
assert!(true); // Production test
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_random_feature_generator() {
|
||||
// let generator = RandomFeatureGenerator::new(5);
|
||||
// let features = generator.generate_features().await?;
|
||||
// assert_eq!(features.len(), 5);
|
||||
//
|
||||
// for &feature in &features {
|
||||
// assert!(feature >= -1.0 && feature <= 1.0);
|
||||
// }
|
||||
//
|
||||
// let names = generator.get_feature_names();
|
||||
// assert_eq!(names.len(), 5);
|
||||
// assert_eq!(names[0], "feature_0");
|
||||
assert!(true); // Production test
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dataset_statistics() {
|
||||
// let samples = vec![
|
||||
// TrainingSample {
|
||||
// features: vec![1.0, 2.0],
|
||||
// teacher_predictions: vec![0.5],
|
||||
// teacher_confidence: 0.8,
|
||||
// hard_target: None,
|
||||
// sample_weight: 1.0,
|
||||
// },
|
||||
// TrainingSample {
|
||||
// features: vec![3.0, 4.0],
|
||||
// teacher_predictions: vec![0.7],
|
||||
// teacher_confidence: 0.9,
|
||||
// hard_target: None,
|
||||
// sample_weight: 1.0,
|
||||
// },
|
||||
// ];
|
||||
//
|
||||
// let config = IntegrationHubConfig::default();
|
||||
// let manager = DistillationManager::new(&config);
|
||||
// let stats = manager.calculate_dataset_statistics(&samples);
|
||||
//
|
||||
// assert_eq!(stats.num_samples, 2);
|
||||
// assert_eq!(stats.num_features, 2);
|
||||
// assert_eq!(stats.feature_means, vec![2.0, 3.0]); // (1+3)/2, (2+4)/2
|
||||
// assert!((stats.target_mean - 0.6).abs() < 1e-6); // (0.5+0.7)/2
|
||||
assert!(true); // Production test
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,44 +686,6 @@ impl From<labeling::gpu_acceleration::LabelingError> for MLError {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Commented out workspace dependency - will be re-enabled when workspace is available
|
||||
// impl From<error_handling::TradingError> for MLError {
|
||||
// fn from(err: error_handling::TradingError) -> Self {
|
||||
// match err {
|
||||
// error_handling::TradingError::InvalidPrice { value, reason } => {
|
||||
// MLError::ValidationError {
|
||||
// message: format!("Invalid price {}: {}", value, reason),
|
||||
// }
|
||||
// }
|
||||
// error_handling::TradingError::InvalidQuantity { value, reason } => {
|
||||
// MLError::ValidationError {
|
||||
// message: format!("Invalid quantity {}: {}", value, reason),
|
||||
// }
|
||||
// }
|
||||
// error_handling::TradingError::FinancialSafety { message, .. } => {
|
||||
// MLError::ValidationError {
|
||||
// message: format!("Financial safety error: {}", message),
|
||||
// }
|
||||
// }
|
||||
// error_handling::TradingError::DivisionByZero { operation } => {
|
||||
// MLError::ValidationError {
|
||||
// message: format!("Division by zero in {}", operation),
|
||||
// }
|
||||
// }
|
||||
// error_handling::TradingError::ModelInference { reason, model } => {
|
||||
// MLError::InferenceError(format!("Model inference error for {}: {}", model, reason))
|
||||
// }
|
||||
// error_handling::TradingError::GpuComputation { reason, operation } => {
|
||||
// let msg = match operation {
|
||||
// Some(op) => format!("GPU computation error ({}): {}", op, reason),
|
||||
// None => format!("GPU computation error: {}", reason),
|
||||
// };
|
||||
// MLError::ModelError(msg)
|
||||
// }
|
||||
// other => MLError::ModelError(format!("Trading error: {}", other)),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Implement From trait for anyhow::Error
|
||||
impl From<anyhow::Error> for MLError {
|
||||
fn from(err: anyhow::Error) -> Self {
|
||||
|
||||
@@ -191,7 +191,7 @@ pub mod derivatives {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::liquid::PRECISION;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_sigmoid() -> Result<()> {
|
||||
|
||||
@@ -426,7 +426,7 @@ mod tests {
|
||||
use crate::liquid::activation::ActivationType;
|
||||
use crate::liquid::ode_solvers::SolverType;
|
||||
use crate::liquid::PRECISION;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_ltc_cell_creation() -> Result<()> {
|
||||
|
||||
@@ -373,7 +373,7 @@ mod tests {
|
||||
use crate::liquid::ode_solvers::SolverType;
|
||||
use crate::liquid::PRECISION;
|
||||
use common::trading::MarketRegime;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_liquid_network_creation() -> Result<()> {
|
||||
|
||||
@@ -332,7 +332,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::liquid::PRECISION;
|
||||
use common::trading::MarketRegime;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_euler_solver() -> Result<()> {
|
||||
|
||||
@@ -535,7 +535,7 @@ impl TrainingUtils {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_training_batch_creation() -> Result<()> {
|
||||
|
||||
@@ -20,14 +20,13 @@ use std::time::{Duration, Instant};
|
||||
use candle_core::Device;
|
||||
use candle_core::{Tensor, Device, DType, Result as CandleResult};
|
||||
use candle_nn::{Linear, LayerNorm, Dropout, Module, VarBuilder};
|
||||
// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist
|
||||
use ndarray::{Array1, Array2, Array3, ArrayView1, ArrayView2, s!};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{MLAppResult, InferenceResult, ModelMetadata};
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_feature_extractor_creation() {
|
||||
|
||||
@@ -13,7 +13,6 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use candle_core::{Tensor, Device, DType, Result as CandleResult};
|
||||
use candle_nn::{Linear, LayerNorm, Dropout, Module, VarBuilder};
|
||||
// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist
|
||||
use ndarray::{Array1, Array2, Array3, ArrayView1, ArrayView2, s!};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -21,7 +20,7 @@ use crate::{MLAppResult, InferenceResult, ModelMetadata};
|
||||
use super::*;
|
||||
use super::advanced_models::{
|
||||
use super::{MicrostructureResult, MarketDataUpdate, TradeDirection, MAX_CALCULATION_LATENCY_US};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_market_regime_encoding() {
|
||||
|
||||
@@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_amihud_measure_creation() {
|
||||
|
||||
@@ -13,7 +13,7 @@ use tokio;
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
/// Generate realistic market data for testing (replaces synthetic generation)
|
||||
/// Based on realistic market microstructure patterns
|
||||
|
||||
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_hasbrouck_creation() {
|
||||
|
||||
@@ -13,7 +13,7 @@ use tokio;
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_microstructure_engine_creation() {
|
||||
|
||||
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_kyle_lambda_estimator_creation() {
|
||||
|
||||
@@ -10,7 +10,6 @@ use std::time::Instant;
|
||||
|
||||
use candle_core::Device;
|
||||
use candle_core::{Device, VarBuilder};
|
||||
// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::{RwLock, Mutex};
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
//! - Memory efficiency: Zero-allocation hot paths
|
||||
//! - Integer arithmetic: 10,000x scaling for financial precision
|
||||
|
||||
// use error_handling::{AppResult, ErrorSeverity, FoxhuntError}; // Commented out - crate doesn't exist
|
||||
|
||||
// VPIN Implementation Module
|
||||
pub mod vpin_implementation;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ use std::{
|
||||
use candle_core::Device;
|
||||
use candle_core::{Device, Tensor};
|
||||
use chrono::{DateTime, Utc};
|
||||
// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist
|
||||
use portfolio_management::advanced_black_litterman::{
|
||||
use serde::{Serialize, Deserialize};
|
||||
use tokio::sync::RwLock;
|
||||
@@ -26,7 +25,7 @@ use crate::portfolio_transformer::{PortfolioTransformer, PortfolioState, Portfol
|
||||
use crate::portfolio_transformer::{PortfolioTransformerConfig};
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
async fn create_test_integrator() -> Result<PortfolioMicrostructureIntegrator, Box<dyn std::error::Error>> {
|
||||
let portfolio_config = PortfolioTransformerConfig::nano();
|
||||
|
||||
@@ -25,7 +25,7 @@ use common::types::Price;
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_roll_spread_estimator_creation() {
|
||||
|
||||
@@ -16,7 +16,6 @@ use std::{
|
||||
use candle_core::{Device, Tensor, DType};
|
||||
use candle_nn::{VarBuilder, VarMap};
|
||||
use chrono::{DateTime, Duration, Duration as ChronoDuration, NaiveDate, Utc};
|
||||
// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist
|
||||
use ndarray::Array2;
|
||||
// REMOVED: Polygon imports - replaced with Databento{
|
||||
use serde::{Serialize, Deserialize};
|
||||
@@ -25,7 +24,7 @@ use tracing::{debug, info, warn, error, instrument};
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_training_pipeline_creation() {
|
||||
|
||||
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
use super::{
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_vpin_calculator_creation() {
|
||||
|
||||
114
ml/src/model.rs
114
ml/src/model.rs
@@ -2,117 +2,3 @@
|
||||
//!
|
||||
//! This module provides actual neural network implementations using the Candle framework
|
||||
//! for production-ready HFT models.
|
||||
|
||||
// DISABLED: Tests require ModelConfig, RealMLModel, Device, TrainingConfig types not available
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
// use anyhow::anyhow;
|
||||
//
|
||||
// #[tokio::test]
|
||||
// async fn test_real_model_creation() {
|
||||
// let config = ModelConfig::default();
|
||||
// let model =
|
||||
// RealMLModel::new(config).map_err(|e| anyhow!("Failed to create model: {:?}", e))?;
|
||||
//
|
||||
// assert!(!model.is_trained);
|
||||
// assert_eq!(
|
||||
// model.metadata.model_type,
|
||||
// MLModelType::Custom("MLP".to_string())
|
||||
// );
|
||||
// assert_eq!(model.network.config.input_dim, 16);
|
||||
// }
|
||||
//
|
||||
// #[tokio::test]
|
||||
// async fn test_synthetic_data_generation() {
|
||||
// let device = Device::Cpu;
|
||||
// let (inputs, targets) = create_synthetic_training_data(&device, 100, 16, 1)
|
||||
// .map_err(|e| anyhow!("Failed to create synthetic data: {:?}", e))?;
|
||||
//
|
||||
// assert_eq!(inputs.dims(), &[100, 16]);
|
||||
// assert_eq!(targets.dims(), &[1, 100]);
|
||||
// }
|
||||
//
|
||||
// #[tokio::test]
|
||||
// async fn test_model_training() {
|
||||
// let config = ModelConfig {
|
||||
// input_dim: 8,
|
||||
// hidden_dims: vec![16, 8],
|
||||
// output_dim: 1,
|
||||
// learning_rate: 0.01,
|
||||
// batch_size: 32,
|
||||
// };
|
||||
//
|
||||
// let mut model =
|
||||
// RealMLModel::new(config).map_err(|e| anyhow!("Failed to create model: {:?}", e))?;
|
||||
// let device = model.device.clone();
|
||||
//
|
||||
// // Create small dataset for quick test
|
||||
// let (train_x, train_y) = create_synthetic_training_data(&device, 64, 8, 1)
|
||||
// .map_err(|e| anyhow!("Failed to create training data: {:?}", e))?;
|
||||
//
|
||||
// // Train for few epochs
|
||||
// let metrics = model
|
||||
// .train(&train_x, &train_y, 10)
|
||||
// .await
|
||||
// .map_err(|e| anyhow!("Training failed: {:?}", e))?;
|
||||
//
|
||||
// assert!(model.is_trained);
|
||||
// assert_eq!(metrics.epochs_trained, 10);
|
||||
// assert!(metrics.train_loss >= 0.0);
|
||||
// assert!(metrics.training_time_seconds > 0.0);
|
||||
// }
|
||||
//
|
||||
// #[tokio::test]
|
||||
// async fn test_real_training_pipeline() {
|
||||
// let training_config = TrainingConfig {
|
||||
// epochs: 5,
|
||||
// learning_rate: 0.01,
|
||||
// ..Default::default()
|
||||
// };
|
||||
//
|
||||
// let mut pipeline = RealTrainingPipeline::new(training_config);
|
||||
//
|
||||
// // Add two models
|
||||
// let model1 = RealMLModel::new(ModelConfig {
|
||||
// input_dim: 4,
|
||||
// hidden_dims: vec![8],
|
||||
// output_dim: 1,
|
||||
// ..Default::default()
|
||||
// })
|
||||
// .map_err(|e| anyhow!("Failed to create model 1: {:?}", e))?;
|
||||
//
|
||||
// let model2 = RealMLModel::new(ModelConfig {
|
||||
// input_dim: 4,
|
||||
// hidden_dims: vec![8, 4],
|
||||
// output_dim: 1,
|
||||
// ..Default::default()
|
||||
// })
|
||||
// .map_err(|e| anyhow!("Failed to create model 2: {:?}", e))?;
|
||||
//
|
||||
// pipeline.add_model("model1".to_string(), model1);
|
||||
// pipeline.add_model("model2".to_string(), model2);
|
||||
//
|
||||
// // Create training data
|
||||
// let device = Device::Cpu;
|
||||
// let (train_x, train_y) = create_synthetic_training_data(&device, 32, 4, 1)
|
||||
// .map_err(|e| anyhow!("Failed to create training data: {:?}", e))?;
|
||||
//
|
||||
// // Train all models
|
||||
// let results = pipeline
|
||||
// .train_all(&train_x, &train_y)
|
||||
// .await
|
||||
// .map_err(|e| anyhow!("Pipeline training failed: {:?}", e))?;
|
||||
//
|
||||
// assert_eq!(results.len(), 2);
|
||||
// assert!(results.contains_key("model1"));
|
||||
// assert!(results.contains_key("model2"));
|
||||
//
|
||||
// // Test predictions
|
||||
// let predictions = pipeline
|
||||
// .predict_all(&train_x)
|
||||
// .map_err(|e| anyhow!("Prediction failed: {:?}", e))?;
|
||||
//
|
||||
// assert_eq!(predictions.len(), 2);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -405,7 +405,7 @@ impl ZeroCopyOps {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem::align_of;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_aligned_buffer() -> Result<(), MLError> {
|
||||
|
||||
@@ -289,7 +289,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::dqn::TradingAction;
|
||||
use crate::ppo::trajectories::{Trajectory, TrajectoryStep};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
fn create_test_trajectory() -> Trajectory {
|
||||
let mut trajectory = Trajectory::new();
|
||||
|
||||
@@ -527,7 +527,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_trajectory_creation() {
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
//! - Performance monitoring and rollback
|
||||
//! - Sub-100μs inference optimization
|
||||
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -18,8 +18,6 @@ use thiserror::Error;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{MLResult, MLError};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
/// Monte Carlo simulation for VaR calculation
|
||||
pub fn simulate_random_shock(volatility: f64) -> f64 {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
@@ -357,7 +357,7 @@ impl MLCircuitBreaker {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_circuit_breaker_creation() -> Result<()> {
|
||||
|
||||
@@ -25,7 +25,7 @@ use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_neural_evt_model_creation() {
|
||||
|
||||
@@ -210,7 +210,7 @@ impl KellyCriterionOptimizer {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_basic_kelly_calculation() -> Result<()> {
|
||||
|
||||
@@ -24,7 +24,7 @@ use super::*;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_lstm_layer_creation() {
|
||||
|
||||
@@ -137,7 +137,7 @@ impl RealTimeMonitor {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tokio::test;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
async fn test_monitor_creation() {
|
||||
|
||||
@@ -7,9 +7,7 @@ use ndarray::Array1;
|
||||
|
||||
use crate::MLResult as Result;
|
||||
|
||||
// Import and re-export canonical types
|
||||
// pub use common::position_sizing::PositionSizingRecommendation; // Commented out - module not available
|
||||
// Using placeholder type
|
||||
// Using placeholder type for PositionSizingRecommendation
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct PositionSizingRecommendation {
|
||||
pub recommended_size: f64,
|
||||
|
||||
@@ -308,7 +308,7 @@ impl FeatureScaler {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_neural_var_model_creation() -> Result<()> {
|
||||
|
||||
@@ -213,7 +213,7 @@ impl GRNStack {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use candle_core::{DType, Device};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_grn_creation() -> Result<(), MLError> {
|
||||
|
||||
@@ -779,7 +779,7 @@ pub struct LatencyPercentiles {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use candle_core::DType;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
//[test]
|
||||
fn test_memory_pool_allocation() {
|
||||
|
||||
@@ -252,7 +252,7 @@ impl QuantileLayer {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use candle_core::{DType, Device};
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_quantile_layer_creation() -> Result<(), MLError> {
|
||||
|
||||
@@ -198,7 +198,7 @@ impl VariableSelectionNetwork {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use candle_core::DType;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_variable_selection_network_creation() -> Result<(), MLError> {
|
||||
|
||||
@@ -316,7 +316,7 @@ impl TLOBTransformer {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::thread;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_tlob_transformer_creation() -> Result<(), MLError> {
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::collections::{HashMap, VecDeque};
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
// use error_handling::{FoxhuntError, AppResult, ErrorSeverity}; // Commented out - crate doesn't exist
|
||||
use rand::prelude::*; // Replace common::rng with standard rand
|
||||
use ndarray::{Array1, Array2, Axis, s};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::collections::{HashMap, VecDeque};
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
// use error_handling::{FoxhuntError, AppResult, ErrorSeverity}; // Commented out - crate doesn't exist
|
||||
use rand::prelude::*; // Replace common::rng with standard rand
|
||||
use ndarray::{Array1, Array2, Array3, Axis, s};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
@@ -23,8 +23,7 @@ use tracing::{debug, info};
|
||||
use crate::safety::MLSafetyManager;
|
||||
use crate::{MLError, MLResult};
|
||||
use common::types::{Price, Symbol, Volume};
|
||||
// use adaptive_strategy::microstructure::OrderLevel; // Commented out - crate not available
|
||||
// Using placeholder OrderLevel type instead
|
||||
// Using placeholder OrderLevel type
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct OrderLevel {
|
||||
pub price: f64,
|
||||
|
||||
@@ -21,8 +21,6 @@ use tokio::sync::{Mutex, RwLock};
|
||||
use tracing::{error, info, warn};
|
||||
use uuid::Uuid;
|
||||
|
||||
// use error_handling::{AppResult, TradingError}; // Commented out - crate doesn't exist
|
||||
|
||||
use crate::safety::{
|
||||
GradientSafetyConfig, GradientSafetyManager, GradientStatistics, MLSafetyConfig,
|
||||
MLSafetyManager, SafetyResult,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tft::temporal_attention::AttentionConfig;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_attention_config() {
|
||||
|
||||
@@ -26,7 +26,7 @@ use chrono::{DateTime, Datelike, Timelike, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_feature_config_default() {
|
||||
|
||||
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{MLAppResult, TrainingMetrics};
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_financial_transformer_creation() {
|
||||
|
||||
@@ -21,13 +21,11 @@ use async_trait::async_trait;
|
||||
use candle_core::Device;
|
||||
use candle_core::{Device, Tensor, DType, Result as CandleResult, Module};
|
||||
use candle_nn::{Linear, LayerNorm, Activation, VarBuilder, VarMap};
|
||||
// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist
|
||||
use serde::{Serialize, Deserialize};
|
||||
use tracing::{info, debug, warn, error};
|
||||
|
||||
use crate::{traits::MLModel, ModelMetadata, InferenceResult, TrainingMetrics, ValidationMetrics};
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_hft_transformer_creation() {
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
|
||||
use candle_core::Device;
|
||||
use candle_core::{Device, Result as CandleResult, Tensor};
|
||||
// use error_handling::AppResult; // Commented out - crate doesn't exist
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{info, warn};
|
||||
use tracing::{info, warn};
|
||||
use tracing::{info, warn};
|
||||
|
||||
use super::*;
|
||||
// use crate::safe_operations; // DISABLED - module not found
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_quantization_config() {
|
||||
|
||||
Reference in New Issue
Block a user