omega_brain/
config.rs

1//! Brain Configuration
2//!
3//! Unified configuration for all brain components.
4
5use serde::{Deserialize, Serialize};
6
7/// Brain operating mode
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9pub enum BrainMode {
10    /// Normal waking cognition
11    Awake,
12    /// Focused attention mode
13    Focused,
14    /// Creative/divergent thinking
15    Creative,
16    /// Light sleep (N1-N2)
17    LightSleep,
18    /// Deep sleep (N3 SWS)
19    DeepSleep,
20    /// REM dreaming
21    Dreaming,
22    /// Low power mode
23    Idle,
24}
25
26impl Default for BrainMode {
27    fn default() -> Self {
28        Self::Awake
29    }
30}
31
32impl std::fmt::Display for BrainMode {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        match self {
35            BrainMode::Awake => write!(f, "Awake"),
36            BrainMode::Focused => write!(f, "Focused"),
37            BrainMode::Creative => write!(f, "Creative"),
38            BrainMode::LightSleep => write!(f, "LightSleep"),
39            BrainMode::DeepSleep => write!(f, "DeepSleep"),
40            BrainMode::Dreaming => write!(f, "Dreaming"),
41            BrainMode::Idle => write!(f, "Idle"),
42        }
43    }
44}
45
46/// Configuration for the Omega Brain
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct BrainConfig {
49    // === Neural Substrate ===
50    /// Number of neurons in the spiking network
51    pub neuron_count: usize,
52    /// Input dimension
53    pub input_dim: usize,
54    /// Hidden dimension
55    pub hidden_dim: usize,
56    /// Output dimension
57    pub output_dim: usize,
58    /// STDP learning rate
59    pub stdp_learning_rate: f64,
60    /// Enable neuromodulation
61    pub neuromodulation_enabled: bool,
62
63    // === Attention ===
64    /// Number of attention heads
65    pub attention_heads: usize,
66    /// Attention dimension
67    pub attention_dim: usize,
68    /// Top-down attention strength
69    pub top_down_strength: f64,
70    /// Bottom-up attention strength
71    pub bottom_up_strength: f64,
72
73    // === Consciousness ===
74    /// IIT integration threshold
75    pub phi_threshold: f64,
76    /// GWT broadcast threshold
77    pub broadcast_threshold: f64,
78    /// Free energy precision
79    pub precision: f64,
80    /// Number of workspace slots
81    pub workspace_capacity: usize,
82
83    // === Memory ===
84    /// Hippocampal pattern dimension
85    pub pattern_dim: usize,
86    /// CA3 network size
87    pub ca3_size: usize,
88    /// Memory consolidation threshold
89    pub consolidation_threshold: f64,
90    /// Maximum memories to retain
91    pub max_memories: usize,
92    /// Replay buffer size
93    pub replay_buffer_size: usize,
94
95    // === Sleep ===
96    /// Sleep cycle duration (in processing cycles)
97    pub sleep_cycle_length: usize,
98    /// SWS duration ratio (0-1)
99    pub sws_ratio: f64,
100    /// REM duration ratio (0-1)
101    pub rem_ratio: f64,
102    /// Enable automatic sleep
103    pub auto_sleep_enabled: bool,
104    /// Cycles before auto-sleep
105    pub cycles_before_sleep: u64,
106
107    // === Self-Awareness ===
108    /// Number of meta-cognitive levels
109    pub meta_levels: usize,
110    /// Maximum recursion depth
111    pub max_recursion: usize,
112    /// Self-model update rate
113    pub self_update_rate: f64,
114    /// Mirror reflection depth
115    pub mirror_depth: usize,
116
117    // === Processing ===
118    /// Processing batch size
119    pub batch_size: usize,
120    /// Enable parallel processing
121    pub parallel_enabled: bool,
122    /// Default brain mode
123    pub default_mode: BrainMode,
124}
125
126impl Default for BrainConfig {
127    fn default() -> Self {
128        Self {
129            // Neural
130            neuron_count: 1000,
131            input_dim: 64,
132            hidden_dim: 256,
133            output_dim: 64,
134            stdp_learning_rate: 0.01,
135            neuromodulation_enabled: true,
136
137            // Attention
138            attention_heads: 8,
139            attention_dim: 64,
140            top_down_strength: 0.6,
141            bottom_up_strength: 0.4,
142
143            // Consciousness
144            phi_threshold: 0.3,
145            broadcast_threshold: 0.5,
146            precision: 1.0,
147            workspace_capacity: 7,
148
149            // Memory
150            pattern_dim: 128,
151            ca3_size: 500,
152            consolidation_threshold: 0.7,
153            max_memories: 10000,
154            replay_buffer_size: 1000,
155
156            // Sleep
157            sleep_cycle_length: 1000,
158            sws_ratio: 0.6,
159            rem_ratio: 0.25,
160            auto_sleep_enabled: true,
161            cycles_before_sleep: 10000,
162
163            // Self-awareness
164            meta_levels: 5,
165            max_recursion: 7,
166            self_update_rate: 0.1,
167            mirror_depth: 3,
168
169            // Processing
170            batch_size: 32,
171            parallel_enabled: true,
172            default_mode: BrainMode::Awake,
173        }
174    }
175}
176
177impl BrainConfig {
178    /// Create a minimal configuration (for testing)
179    pub fn minimal() -> Self {
180        Self {
181            neuron_count: 100,
182            input_dim: 16,
183            hidden_dim: 32,
184            output_dim: 16,
185            attention_heads: 2,
186            attention_dim: 16,
187            pattern_dim: 32,
188            ca3_size: 50,
189            meta_levels: 3,
190            max_recursion: 3,
191            mirror_depth: 2,
192            batch_size: 8,
193            max_memories: 100,
194            replay_buffer_size: 50,
195            ..Default::default()
196        }
197    }
198
199    /// Create a high-capacity configuration
200    pub fn high_capacity() -> Self {
201        Self {
202            neuron_count: 10000,
203            input_dim: 256,
204            hidden_dim: 1024,
205            output_dim: 256,
206            attention_heads: 16,
207            attention_dim: 256,
208            pattern_dim: 512,
209            ca3_size: 2000,
210            meta_levels: 7,
211            max_recursion: 10,
212            mirror_depth: 5,
213            max_memories: 100000,
214            replay_buffer_size: 10000,
215            ..Default::default()
216        }
217    }
218
219    /// Validate configuration
220    pub fn validate(&self) -> Result<(), String> {
221        if self.input_dim == 0 {
222            return Err("input_dim must be > 0".to_string());
223        }
224        if self.neuron_count == 0 {
225            return Err("neuron_count must be > 0".to_string());
226        }
227        if self.meta_levels == 0 {
228            return Err("meta_levels must be > 0".to_string());
229        }
230        if self.phi_threshold < 0.0 || self.phi_threshold > 1.0 {
231            return Err("phi_threshold must be in [0, 1]".to_string());
232        }
233        if self.sws_ratio + self.rem_ratio > 1.0 {
234            return Err("sws_ratio + rem_ratio must be <= 1".to_string());
235        }
236        Ok(())
237    }
238}
239
240#[cfg(test)]
241mod tests {
242    use super::*;
243
244    #[test]
245    fn test_default_config() {
246        let config = BrainConfig::default();
247        assert!(config.validate().is_ok());
248    }
249
250    #[test]
251    fn test_minimal_config() {
252        let config = BrainConfig::minimal();
253        assert!(config.validate().is_ok());
254    }
255
256    #[test]
257    fn test_brain_mode_display() {
258        assert_eq!(BrainMode::Awake.to_string(), "Awake");
259        assert_eq!(BrainMode::Dreaming.to_string(), "Dreaming");
260    }
261}