use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NeuralGateConfig {
pub hysteresis: HysteresisConfig,
pub workspace: WorkspaceConfig,
pub oscillator: OscillatorConfig,
pub hdc_dimension: usize,
pub memory_capacity: usize,
pub coincidence_window_us: u64,
pub num_branches: usize,
pub enable_oscillatory_routing: bool,
}
impl Default for NeuralGateConfig {
fn default() -> Self {
Self {
hysteresis: HysteresisConfig::default(),
workspace: WorkspaceConfig::default(),
oscillator: OscillatorConfig::default(),
hdc_dimension: 10000, memory_capacity: 10000,
coincidence_window_us: 5000, num_branches: 8,
enable_oscillatory_routing: true,
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct HysteresisConfig {
pub low_threshold: f32,
pub high_threshold: f32,
pub min_dwell_time_ms: u64,
pub smoothing_factor: f32,
}
impl Default for HysteresisConfig {
fn default() -> Self {
Self {
low_threshold: 0.3,
high_threshold: 0.7,
min_dwell_time_ms: 100,
smoothing_factor: 0.2,
}
}
}
impl HysteresisConfig {
#[must_use]
pub fn sensitive() -> Self {
Self {
low_threshold: 0.4,
high_threshold: 0.6,
min_dwell_time_ms: 50,
smoothing_factor: 0.1,
}
}
#[must_use]
pub fn stable() -> Self {
Self {
low_threshold: 0.2,
high_threshold: 0.8,
min_dwell_time_ms: 200,
smoothing_factor: 0.3,
}
}
#[must_use]
pub fn is_valid(&self) -> bool {
self.low_threshold >= 0.0
&& self.high_threshold <= 1.0
&& self.low_threshold < self.high_threshold
&& self.smoothing_factor >= 0.0
&& self.smoothing_factor <= 1.0
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceConfig {
pub buffer_capacity: usize,
pub broadcast_threshold: f32,
pub attention_selection: bool,
pub competition_decay: f32,
pub num_competitors: usize,
}
impl Default for WorkspaceConfig {
fn default() -> Self {
Self {
buffer_capacity: 100,
broadcast_threshold: 0.6,
attention_selection: true,
competition_decay: 0.9,
num_competitors: 8,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OscillatorConfig {
pub num_oscillators: usize,
pub natural_frequency: f32,
pub coupling_strength: f32,
pub phase_noise: f32,
pub sync_threshold: f32,
}
impl Default for OscillatorConfig {
fn default() -> Self {
Self {
num_oscillators: 64,
natural_frequency: 40.0, coupling_strength: 0.5,
phase_noise: 0.1,
sync_threshold: 0.8,
}
}
}
impl OscillatorConfig {
#[must_use]
pub fn beta_band() -> Self {
Self {
num_oscillators: 64,
natural_frequency: 20.0, coupling_strength: 0.4,
phase_noise: 0.15,
sync_threshold: 0.75,
}
}
#[must_use]
pub fn theta_band() -> Self {
Self {
num_oscillators: 32,
natural_frequency: 6.0, coupling_strength: 0.6,
phase_noise: 0.05,
sync_threshold: 0.85,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hysteresis_validity() {
assert!(HysteresisConfig::default().is_valid());
assert!(HysteresisConfig::sensitive().is_valid());
assert!(HysteresisConfig::stable().is_valid());
let invalid = HysteresisConfig {
low_threshold: 0.8,
high_threshold: 0.3, min_dwell_time_ms: 100,
smoothing_factor: 0.2,
};
assert!(!invalid.is_valid());
}
#[test]
fn test_default_configs() {
let config = NeuralGateConfig::default();
assert_eq!(config.hdc_dimension, 10000);
assert!(config.hysteresis.is_valid());
}
}