use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NestedConfig {
pub meta_update_interval: u64,
pub optimizer_update_interval: u64,
pub feature_dim: usize,
pub fast_path_enabled: bool,
pub fast_path_threshold: f32,
pub learning_rate: f32,
pub parallel_validation: bool,
pub max_parallel_group: usize,
}
impl Default for NestedConfig {
fn default() -> Self {
Self {
meta_update_interval: 1000,
optimizer_update_interval: 100,
feature_dim: 16,
fast_path_enabled: true,
fast_path_threshold: 0.9,
learning_rate: 0.01,
parallel_validation: true,
max_parallel_group: 10,
}
}
}
impl NestedConfig {
pub fn iot() -> Self {
Self {
meta_update_interval: 5000, optimizer_update_interval: 500,
feature_dim: 8, fast_path_enabled: true,
fast_path_threshold: 0.95, learning_rate: 0.001,
parallel_validation: false, max_parallel_group: 1,
}
}
pub fn full_power() -> Self {
Self {
meta_update_interval: 100, optimizer_update_interval: 10,
feature_dim: 32, fast_path_enabled: true,
fast_path_threshold: 0.8, learning_rate: 0.05,
parallel_validation: true,
max_parallel_group: 100,
}
}
pub fn validate(&self) -> Result<(), String> {
if self.meta_update_interval == 0 {
return Err("meta_update_interval must be > 0".to_string());
}
if self.optimizer_update_interval == 0 {
return Err("optimizer_update_interval must be > 0".to_string());
}
if self.feature_dim == 0 {
return Err("feature_dim must be > 0".to_string());
}
if self.fast_path_threshold < 0.0 || self.fast_path_threshold > 1.0 {
return Err("fast_path_threshold must be between 0.0 and 1.0".to_string());
}
if self.learning_rate < 0.0 || self.learning_rate > 1.0 {
return Err("learning_rate must be between 0.0 and 1.0".to_string());
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = NestedConfig::default();
assert!(config.validate().is_ok());
}
#[test]
fn test_iot_config() {
let config = NestedConfig::iot();
assert!(config.validate().is_ok());
assert!(config.meta_update_interval > NestedConfig::default().meta_update_interval);
}
}