use crate::learned_optimizers::few_shot_optimizer::EvaluationMetric;
pub mod nas_engine;
pub use nas_engine::*;
pub use nas_engine::{
create_example_nas_config,
create_minimal_nas_config,
};
pub fn create_production_nas_config<T: scirs2_core::numeric::Float>() -> NASConfig<T> {
NASConfig {
search_strategy: SearchStrategyType::Hybrid,
search_space: SearchSpaceConfig {
component_types: vec![
ComponentTypeConfig {
component_type: ComponentType::Adam,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.25).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::AdamW,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.25).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::SGD,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::RMSprop,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::Momentum,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.1).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::Nesterov,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.1).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
],
max_components: 15,
min_components: 3,
max_connections: 30,
min_connections: 2,
allow_cycles: false,
max_depth: 7,
enable_skip_connections: true,
connection_probability: scirs2_core::numeric::NumCast::from(0.6).unwrap_or_else(|| T::zero()),
},
evaluation_config: EvaluationConfig {
metrics: vec![
EvaluationMetric::FinalPerformance,
EvaluationMetric::ConvergenceSpeed,
EvaluationMetric::Stability,
EvaluationMetric::Efficiency,
EvaluationMetric::Robustness,
],
num_trials: 10,
max_iterations: 2000,
convergence_threshold: scirs2_core::numeric::NumCast::from(1e-6).unwrap_or_else(|| T::zero()),
stability_window: 100,
timeout_seconds: 3600.0,
parallel_trials: true,
cache_results: true,
early_termination: true,
confidence_level: scirs2_core::numeric::NumCast::from(0.95).unwrap_or_else(|| T::zero()),
statistical_significance: true,
},
multi_objective_config: MultiObjectiveConfig {
objectives: vec![
ObjectiveConfig {
name: "performance".to_string(),
objective_type: ObjectiveType::Performance,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.4).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::High,
tolerance: Some(scirs2_core::numeric::NumCast::from(0.01).unwrap_or_else(|| T::zero())),
},
ObjectiveConfig {
name: "efficiency".to_string(),
objective_type: ObjectiveType::Efficiency,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Medium,
tolerance: Some(scirs2_core::numeric::NumCast::from(0.05).unwrap_or_else(|| T::zero())),
},
ObjectiveConfig {
name: "robustness".to_string(),
objective_type: ObjectiveType::Robustness,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Medium,
tolerance: Some(scirs2_core::numeric::NumCast::from(0.05).unwrap_or_else(|| T::zero())),
},
],
algorithm: MultiObjectiveAlgorithm::NSGA3,
pareto_front_size: 100,
enable_preferences: true,
user_preferences: Some(UserPreferences::default()),
diversity_strategy: DiversityStrategy::HyperVolume,
constraint_handling: ConstraintHandlingMethod::PenaltyFunction,
},
search_budget: 2000,
early_stopping: EarlyStoppingConfig {
enabled: true,
patience: 100,
min_improvement: scirs2_core::numeric::NumCast::from(0.001).unwrap_or_else(|| T::zero()),
metric: EvaluationMetric::FinalPerformance,
target_performance: None,
convergence_detection: ConvergenceDetectionStrategy::RelativeImprovement,
},
progressive_search: true,
population_size: 100,
enable_transfer_learning: true,
encoding_strategy: ArchitectureEncodingStrategy::Direct,
enable_performance_prediction: true,
parallelization_factor: 8,
auto_hyperparameter_tuning: true,
resource_constraints: ResourceConstraints {
max_memory_gb: scirs2_core::numeric::NumCast::from(32.0).unwrap_or_else(|| T::zero()),
max_computation_hours: scirs2_core::numeric::NumCast::from(48.0).unwrap_or_else(|| T::zero()),
max_energy_kwh: scirs2_core::numeric::NumCast::from(200.0).unwrap_or_else(|| T::zero()),
max_cost_usd: scirs2_core::numeric::NumCast::from(2000.0).unwrap_or_else(|| T::zero()),
hardware_resources: HardwareResources {
cpu_cores: 32,
ram_gb: 128,
num_gpus: 8,
gpu_memory_gb: 80,
storage_gb: 2000,
network_bandwidth_mbps: 2000.0,
},
enable_monitoring: true,
violation_handling: ResourceViolationHandling::Penalty,
},
}
}
pub fn create_research_nas_config<T: scirs2_core::numeric::Float>() -> NASConfig<T> {
NASConfig {
search_strategy: SearchStrategyType::Bayesian,
search_space: SearchSpaceConfig {
component_types: vec![
ComponentTypeConfig {
component_type: ComponentType::Adam,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.2).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::AdamW,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.2).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::SGD,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::RMSprop,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::AdaGrad,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.1).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::AdaDelta,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.1).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
ComponentTypeConfig {
component_type: ComponentType::Custom,
enabled: true,
probability: scirs2_core::numeric::NumCast::from(0.1).unwrap_or_else(|| T::zero()),
hyperparameter_ranges: std::collections::HashMap::new(),
constraints: ArchitectureConstraints::default(),
dependencies: Vec::new(),
},
],
max_components: 20,
min_components: 1,
max_connections: 50,
min_connections: 0,
allow_cycles: true,
max_depth: 10,
enable_skip_connections: true,
connection_probability: scirs2_core::numeric::NumCast::from(0.7).unwrap_or_else(|| T::zero()),
},
evaluation_config: EvaluationConfig {
metrics: vec![
EvaluationMetric::FinalPerformance,
EvaluationMetric::ConvergenceSpeed,
EvaluationMetric::Stability,
EvaluationMetric::Efficiency,
EvaluationMetric::Robustness,
EvaluationMetric::Generalization,
EvaluationMetric::MemoryUsage,
EvaluationMetric::ComputationTime,
],
num_trials: 20,
max_iterations: 5000,
convergence_threshold: scirs2_core::numeric::NumCast::from(1e-8).unwrap_or_else(|| T::zero()),
stability_window: 200,
timeout_seconds: 7200.0,
parallel_trials: true,
cache_results: true,
early_termination: false, confidence_level: scirs2_core::numeric::NumCast::from(0.99).unwrap_or_else(|| T::zero()),
statistical_significance: true,
},
multi_objective_config: MultiObjectiveConfig {
objectives: vec![
ObjectiveConfig {
name: "performance".to_string(),
objective_type: ObjectiveType::Performance,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.3).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::High,
tolerance: None, },
ObjectiveConfig {
name: "convergence".to_string(),
objective_type: ObjectiveType::ConvergenceSpeed,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.2).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Medium,
tolerance: None,
},
ObjectiveConfig {
name: "efficiency".to_string(),
objective_type: ObjectiveType::Efficiency,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.2).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Medium,
tolerance: None,
},
ObjectiveConfig {
name: "robustness".to_string(),
objective_type: ObjectiveType::Robustness,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Medium,
tolerance: None,
},
ObjectiveConfig {
name: "generalization".to_string(),
objective_type: ObjectiveType::Generalization,
direction: OptimizationDirection::Maximize,
weight: scirs2_core::numeric::NumCast::from(0.15).unwrap_or_else(|| T::zero()),
priority: ObjectivePriority::Low,
tolerance: None,
},
],
algorithm: MultiObjectiveAlgorithm::NSGA3,
pareto_front_size: 200,
enable_preferences: false, user_preferences: None,
diversity_strategy: DiversityStrategy::HyperVolume,
constraint_handling: ConstraintHandlingMethod::PenaltyFunction,
},
search_budget: 5000,
early_stopping: EarlyStoppingConfig {
enabled: false, patience: 200,
min_improvement: scirs2_core::numeric::NumCast::from(0.0001).unwrap_or_else(|| T::zero()),
metric: EvaluationMetric::FinalPerformance,
target_performance: None,
convergence_detection: ConvergenceDetectionStrategy::RelativeImprovement,
},
progressive_search: true,
population_size: 200,
enable_transfer_learning: true,
encoding_strategy: ArchitectureEncodingStrategy::Direct,
enable_performance_prediction: true,
parallelization_factor: 16,
auto_hyperparameter_tuning: true,
resource_constraints: ResourceConstraints {
max_memory_gb: scirs2_core::numeric::NumCast::from(64.0).unwrap_or_else(|| T::zero()),
max_computation_hours: scirs2_core::numeric::NumCast::from(168.0).unwrap_or_else(|| T::zero()), max_energy_kwh: scirs2_core::numeric::NumCast::from(1000.0).unwrap_or_else(|| T::zero()),
max_cost_usd: scirs2_core::numeric::NumCast::from(10000.0).unwrap_or_else(|| T::zero()),
hardware_resources: HardwareResources {
cpu_cores: 64,
ram_gb: 256,
num_gpus: 16,
gpu_memory_gb: 160,
storage_gb: 10000,
network_bandwidth_mbps: 10000.0,
},
enable_monitoring: true,
violation_handling: ResourceViolationHandling::Warning, },
}
}