use std::fmt::Debug;
use scirs2_core::numeric::Float;
use std::collections::HashMap;
use super::super::architecture::ArchitectureCandidate;
#[derive(Debug)]
pub struct DifferentiableNASState<T: Float + Debug + Send + Sync + 'static> {
pub arch_parameters: Vec<T>,
pub model_weights: Vec<T>,
pub mixed_op_weights: HashMap<String, Vec<T>>,
pub config: DARTSConfig,
pub current_epoch: usize,
pub loss_history: Vec<T>,
}
#[derive(Debug, Clone)]
pub struct DARTSConfig {
pub arch_lr: f64,
pub weight_lr: f64,
pub weight_decay: f64,
pub momentum: f64,
pub temperature: f64,
pub epochs: usize,
}
impl Default for DARTSConfig {
fn default() -> Self {
Self {
arch_lr: 3e-4,
weight_lr: 0.025,
weight_decay: 3e-4,
momentum: 0.9,
temperature: 1.0,
epochs: 50,
}
}
}
impl<T: Float + Debug + Default + std::fmt::Debug + Send + Sync> DifferentiableNASState<T> {
pub fn new() -> Self {
Self {
arch_parameters: Vec::new(),
model_weights: Vec::new(),
mixed_op_weights: HashMap::new(),
config: DARTSConfig::default(),
current_epoch: 0,
loss_history: Vec::new(),
}
}
pub fn generate_architecture(&self) -> Result<ArchitectureCandidate, super::SearchError> {
use super::super::architecture::{ArchitectureSpec, LayerSpec, LayerDimensions, LayerType, ActivationType, GlobalArchitectureConfig};
let layers = vec![
LayerSpec::new(
LayerType::Linear,
LayerDimensions { input_dim: 128, output_dim: 64, hidden_dims: vec![] },
ActivationType::ReLU,
)
];
let arch_spec = ArchitectureSpec::new(layers, GlobalArchitectureConfig::default());
Ok(ArchitectureCandidate::new("darts_arch".to_string(), arch_spec))
}
}
#[derive(Debug)]
pub struct ProgressiveSearchState<T: Float + Debug + Send + Sync + 'static> {
pub current_phase: usize,
pub phases: Vec<SearchPhase>,
pub phase_candidates: HashMap<usize, Vec<ArchitectureCandidate>>,
_phantom: std::marker::PhantomData<T>,
}
#[derive(Debug, Clone)]
pub struct SearchPhase {
pub name: String,
pub search_space_size: usize,
pub num_candidates: usize,
pub duration: usize,
}
impl<T: Float + Debug + Default + std::fmt::Debug + Send + Sync> ProgressiveSearchState<T> {
pub fn new() -> Self {
let phases = vec![
SearchPhase {
name: "coarse".to_string(),
search_space_size: 1000,
num_candidates: 100,
duration: 10,
},
SearchPhase {
name: "fine".to_string(),
search_space_size: 10000,
num_candidates: 50,
duration: 20,
},
];
Self {
current_phase: 0,
phases,
phase_candidates: HashMap::new(),
_phantom: std::marker::PhantomData,
}
}
}
#[derive(Debug)]
pub struct MultiObjectiveState<T: Float + Debug + Send + Sync + 'static> {
pub pareto_front: Vec<ArchitectureCandidate>,
pub objectives: Vec<String>,
pub algorithm: MultiObjectiveAlgorithm,
_phantom: std::marker::PhantomData<T>,
}
#[derive(Debug, Clone, Copy)]
pub enum MultiObjectiveAlgorithm {
NSGA2,
SPEA2,
MOEAD,
ParEGO,
}
impl<T: Float + Debug + Default + std::fmt::Debug + Send + Sync> MultiObjectiveState<T> {
pub fn new() -> Self {
Self {
pareto_front: Vec::new(),
objectives: vec!["performance".to_string(), "efficiency".to_string()],
algorithm: MultiObjectiveAlgorithm::NSGA2,
_phantom: std::marker::PhantomData,
}
}
}