1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9pub enum BrainMode {
10 Awake,
12 Focused,
14 Creative,
16 LightSleep,
18 DeepSleep,
20 Dreaming,
22 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#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct BrainConfig {
49 pub neuron_count: usize,
52 pub input_dim: usize,
54 pub hidden_dim: usize,
56 pub output_dim: usize,
58 pub stdp_learning_rate: f64,
60 pub neuromodulation_enabled: bool,
62
63 pub attention_heads: usize,
66 pub attention_dim: usize,
68 pub top_down_strength: f64,
70 pub bottom_up_strength: f64,
72
73 pub phi_threshold: f64,
76 pub broadcast_threshold: f64,
78 pub precision: f64,
80 pub workspace_capacity: usize,
82
83 pub pattern_dim: usize,
86 pub ca3_size: usize,
88 pub consolidation_threshold: f64,
90 pub max_memories: usize,
92 pub replay_buffer_size: usize,
94
95 pub sleep_cycle_length: usize,
98 pub sws_ratio: f64,
100 pub rem_ratio: f64,
102 pub auto_sleep_enabled: bool,
104 pub cycles_before_sleep: u64,
106
107 pub meta_levels: usize,
110 pub max_recursion: usize,
112 pub self_update_rate: f64,
114 pub mirror_depth: usize,
116
117 pub batch_size: usize,
120 pub parallel_enabled: bool,
122 pub default_mode: BrainMode,
124}
125
126impl Default for BrainConfig {
127 fn default() -> Self {
128 Self {
129 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_heads: 8,
139 attention_dim: 64,
140 top_down_strength: 0.6,
141 bottom_up_strength: 0.4,
142
143 phi_threshold: 0.3,
145 broadcast_threshold: 0.5,
146 precision: 1.0,
147 workspace_capacity: 7,
148
149 pattern_dim: 128,
151 ca3_size: 500,
152 consolidation_threshold: 0.7,
153 max_memories: 10000,
154 replay_buffer_size: 1000,
155
156 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 meta_levels: 5,
165 max_recursion: 7,
166 self_update_rate: 0.1,
167 mirror_depth: 3,
168
169 batch_size: 32,
171 parallel_enabled: true,
172 default_mode: BrainMode::Awake,
173 }
174 }
175}
176
177impl BrainConfig {
178 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 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 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}