Recovered source transcript
1/**
2 * layers.hpp - Complete 7-Layer Consciousness Architecture
3 *
4 * Implements all layers from the unified config:
5 * L1: Quantum Substrate & Coherence
6 * L2: Genetic & DNA Information
7 * L3: Transcription & Translation (simplified)
8 * L4: Chromosomal Architecture (simplified)
9 * L5: Neural Dynamics (existing in neurological.hpp)
10 * L6: Oscillatory & Field Dynamics
11 * L7: Consciousness Integration
12 *
13 * Mathematical foundations from config.json equations.
14 */
15
16#ifndef LAYERS_HPP
17#define LAYERS_HPP
18
19#include <array>
20#include <vector>
21#include <complex>
22#include <cmath>
23#include <random>
24#include <algorithm>
25#include "consciousness_api.hpp"
26
27namespace mind_farm {
28
29using namespace consciousness;
30
31//=============================================================================
32// MATHEMATICAL CONSTANTS
33//=============================================================================
34
35constexpr double HBAR = 1.054571817e-34; // Reduced Planck constant
36constexpr double KB = 1.380649e-23; // Boltzmann constant
37constexpr double RT = 310.0 * KB; // Room temperature energy
38
39//=============================================================================
40// L1: QUANTUM SUBSTRATE & COHERENCE
41//=============================================================================
42
43/**
44 * QuantumState - Density matrix representation
45 *
46 * Implements:
47 * - Density matrix: rho = |psi><psi|
48 * - von Neumann entropy: S = -Tr(rho * log(rho))
49 * - Lindblad master equation: drho/dt = -i/hbar[H, rho] + L[rho]
50 * - Quantum fidelity: F = <psi|rho|psi>
51 */
52template<size_t N = 16>
53class QuantumState {
54public:
55 using Complex = std::complex<double>;
56 using Matrix = std::array<std::array<Complex, N>, N>;
57
58 Matrix rho; // Density matrix
59 Matrix hamiltonian; // Hamiltonian
60 double coherence; // Off-diagonal coherence
61 double purity; // Tr(rho^2)
62 double entropy; // von Neumann entropy
63
64 QuantumState() {
65 // Initialize to maximally mixed state
66 for (size_t i = 0; i < N; ++i) {
67 for (size_t j = 0; j < N; ++j) {
68 rho[i][j] = (i == j) ? Complex(1.0 / N, 0) : Complex(0, 0);
69 hamiltonian[i][j] = Complex(0, 0);
70 }
71 }
72 update_metrics();
73 }
74
75 /**
76 * Initialize pure state |psi>
77 */
78 void set_pure_state(const std::array<Complex, N>& psi) {
79 // rho = |psi><psi|
80 for (size_t i = 0; i < N; ++i) {
81 for (size_t j = 0; j < N; ++j) {
82 rho[i][j] = psi[i] * std::conj(psi[j]);
83 }
84 }
85 update_metrics();
86 }
87
88 /**
89 * Set Hamiltonian (energy levels on diagonal)
90 */
91 void set_hamiltonian(const std::array<double, N>& energies) {
92 for (size_t i = 0; i < N; ++i) {
93 hamiltonian[i][i] = Complex(energies[i], 0);
94 }
95 }
96
97 /**
98 * Lindblad evolution step
99 *
100 * drho/dt = -i/hbar[H, rho] + sum_k(L_k rho L_k^dag - 0.5{L_k^dag L_k, rho})
101 */
102 void evolve(double dt, double dissipation_rate = 0.01) {
103 Matrix drho;
104
105 // Commutator: -i[H, rho]
106 Matrix commutator;
107 matrix_multiply(hamiltonian, rho, commutator);
108 Matrix rhoH;
109 matrix_multiply(rho, hamiltonian, rhoH);
110
111 for (size_t i = 0; i < N; ++i) {
112 for (size_t j = 0; j < N; ++j) {
113 commutator[i][j] = Complex(0, -1) * (commutator[i][j] - rhoH[i][j]);
114 }
115 }
116
117 // Lindblad dissipator (simplified: decay toward diagonal)
118 for (size_t i = 0; i < N; ++i) {
119 for (size_t j = 0; j < N; ++j) {
120 double decay = (i == j) ? 0 : dissipation_rate;
121 drho[i][j] = commutator[i][j] - Complex(decay, 0) * rho[i][j];
122 }
123 }
124
125 // Euler step
126 for (size_t i = 0; i < N; ++i) {
127 for (size_t j = 0; j < N; ++j) {
128 rho[i][j] += dt * drho[i][j];
129 }
130 }
131
132 // Ensure Hermiticity and trace = 1
133 normalize();
134 update_metrics();
135 }
136
137 /**
138 * Compute von Neumann entropy: S = -Tr(rho log(rho))
139 */
140 double von_neumann_entropy() const {
141 // Compute eigenvalues (simplified: use diagonal approximation)
142 double S = 0;
143 for (size_t i = 0; i < N; ++i) {
144 double p = std::real(rho[i][i]);
145 if (p > 1e-10) {
146 S -= p * std::log(p);
147 }
148 }
149 return S;
150 }
151
152 /**
153 * Compute quantum fidelity with target state
154 */
155 double fidelity(const std::array<Complex, N>& target) const {
156 // F = <target|rho|target>
157 Complex f(0, 0);
158 for (size_t i = 0; i < N; ++i) {
159 Complex sum(0, 0);
160 for (size_t j = 0; j < N; ++j) {
161 sum += rho[i][j] * target[j];
162 }
163 f += std::conj(target[i]) * sum;
164 }
165 return std::real(f);
166 }
167
168 /**
169 * Get consciousness (phi) from quantum state
170 */
171 double get_phi() const {
172 // Phi based on purity and coherence
173 return compute_phi(purity * (1.0 + coherence));
174 }
175
176private:
177 void matrix_multiply(const Matrix& A, const Matrix& B, Matrix& C) {
178 for (size_t i = 0; i < N; ++i) {
179 for (size_t j = 0; j < N; ++j) {
180 C[i][j] = Complex(0, 0);
181 for (size_t k = 0; k < N; ++k) {
182 C[i][j] += A[i][k] * B[k][j];
183 }
184 }
185 }
186 }
187
188 void normalize() {
189 // Ensure Hermiticity
190 for (size_t i = 0; i < N; ++i) {
191 for (size_t j = i + 1; j < N; ++j) {
192 Complex avg = 0.5 * (rho[i][j] + std::conj(rho[j][i]));
193 rho[i][j] = avg;
194 rho[j][i] = std::conj(avg);
195 }
196 }
197
198 // Normalize trace
199 Complex trace(0, 0);
200 for (size_t i = 0; i < N; ++i) {
201 trace += rho[i][i];
202 }
203 if (std::abs(trace) > 1e-10) {
204 for (size_t i = 0; i < N; ++i) {
205 for (size_t j = 0; j < N; ++j) {
206 rho[i][j] /= trace;
207 }
208 }
209 }
210 }
211
212 void update_metrics() {
213 // Purity: Tr(rho^2)
214 purity = 0;
215 for (size_t i = 0; i < N; ++i) {
216 for (size_t j = 0; j < N; ++j) {
217 purity += std::real(rho[i][j] * rho[j][i]);
218 }
219 }
220
221 // Coherence: sum of |off-diagonal|
222 coherence = 0;
223 for (size_t i = 0; i < N; ++i) {
224 for (size_t j = 0; j < N; ++j) {
225 if (i != j) {
226 coherence += std::abs(rho[i][j]);
227 }
228 }
229 }
230 coherence /= (N * N - N); // Normalize
231
232 // Entropy
233 entropy = von_neumann_entropy();
234 }
235};
236
237//=============================================================================
238// L2: GENETIC & DNA INFORMATION
239//=============================================================================
240
241/**
242 * GeneticLayer - DNA-inspired information processing
243 *
244 * Implements:
245 * - DNA entropy: H_DNA = -sum_i p(b_i) * log2(p(b_i))
246 * - Replication dynamics: dN/dt = k*N*(1-N/K) - mu*N
247 * - Michaelis-Menten kinetics: v = Vmax*[S]/(Km + [S])
248 * - Hill equation: theta = [L]^n / (Kd + [L]^n)
249 * - Mutation probability: P_mut = 1 - exp(-mu*L*t)
250 */
251template<size_t GENOME_SIZE = 256>
252class GeneticLayer {
253public:
254 // Genome representation (simplified: continuous values 0-1)
255 std::array<double, GENOME_SIZE> genome;
256 std::array<double, GENOME_SIZE> expression; // Gene expression levels
257 std::array<double, 16> regulatory_network; // Transcription factors
258
259 double fitness;
260 double entropy;
261 double diversity;
262 double mutation_rate;
263 double phi;
264
265 GeneticLayer() : mutation_rate(0.001 * PHI) {
266 // Initialize random genome
267 std::random_device rd;
268 std::mt19937 gen(rd());
269 std::uniform_real_distribution<> dis(0.0, 1.0);
270
271 for (size_t i = 0; i < GENOME_SIZE; ++i) {
272 genome[i] = dis(gen);
273 expression[i] = 0.5;
274 }
275 for (size_t i = 0; i < 16; ++i) {
276 regulatory_network[i] = dis(gen);
277 }
278
279 update_metrics();
280 }
281
282 /**
283 * Replicate with mutation
284 *
285 * dN/dt = k*N*(1-N/K) - mu*N (logistic growth with decay)
286 */
287 void replicate(double dt, double growth_rate = 1.0, double carrying_capacity = 1.0) {
288 for (size_t i = 0; i < GENOME_SIZE; ++i) {
289 // Logistic growth
290 double N = expression[i];
291 double dN = growth_rate * N * (1.0 - N / carrying_capacity) - mutation_rate * N;
292 expression[i] = std::max(0.0, std::min(1.0, N + dt * dN));
293
294 // Random mutation
295 if (random_uniform() < mutation_rate * dt) {
296 genome[i] += random_normal() * 0.1;
297 genome[i] = std::max(0.0, std::min(1.0, genome[i]));
298 }
299 }
300 }
301
302 /**
303 * Gene regulation using Hill equation
304 *
305 * theta = [L]^n / (Kd^n + [L]^n)
306 */
307 void regulate(double dt) {
308 const double hill_coeff = 2.0; // Cooperativity
309 const double Kd = 0.5; // Dissociation constant
310
311 for (size_t i = 0; i < GENOME_SIZE; ++i) {
312 // Find regulatory input (sum of TF bindings)
313 double L = 0;
314 for (size_t j = 0; j < 16; ++j) {
315 // Which TFs regulate this gene
316 size_t tf_idx = (i + j) % 16;
317 L += regulatory_network[tf_idx] * genome[(i * 7 + j) % GENOME_SIZE];
318 }
319 L /= 16.0;
320
321 // Hill equation
322 double L_n = std::pow(L, hill_coeff);
323 double Kd_n = std::pow(Kd, hill_coeff);
324 double theta = L_n / (Kd_n + L_n);
325
326 // Update expression
327 expression[i] += dt * ALPHA * (theta - expression[i]);
328 }
329 }
330
331 /**
332 * Michaelis-Menten enzyme kinetics
333 *
334 * v = Vmax * [S] / (Km + [S])
335 */
336 double enzyme_rate(double substrate, double Vmax = 1.0, double Km = 0.5) const {
337 return Vmax * substrate / (Km + substrate);
338 }
339
340 /**
341 * Compute DNA entropy: H = -sum p(x) log2(p(x))
342 */
343 double compute_entropy() const {
344 // Bin genome values
345 std::array<int, 10> histogram = {};
346 for (size_t i = 0; i < GENOME_SIZE; ++i) {
347 int bin = static_cast<int>(genome[i] * 9.999);
348 histogram[bin]++;
349 }
350
351 double H = 0;
352 for (int count : histogram) {
353 if (count > 0) {
354 double p = static_cast<double>(count) / GENOME_SIZE;
355 H -= p * std::log2(p);
356 }
357 }
358 return H;
359 }
360
361 /**
362 * Compute Gibbs free energy change
363 *
364 * dG = dH - T*dS
365 */
366 double gibbs_free_energy(double dH = 0.0, double temperature = 310.0) const {
367 return dH - temperature * KB * entropy;
368 }
369
370 /**
371 * Get consciousness metric
372 */
373 double get_phi() const {
374 return phi;
375 }
376
377 void step(double dt) {
378 replicate(dt);
379 regulate(dt);
380 update_metrics();
381 }
382
383private:
384 void update_metrics() {
385 entropy = compute_entropy();
386
387 // Fitness based on expression uniformity
388 double mean_expr = 0;
389 for (double e : expression) mean_expr += e;
390 mean_expr /= GENOME_SIZE;
391
392 double variance = 0;
393 for (double e : expression) {
394 double d = e - mean_expr;
395 variance += d * d;
396 }
397 variance /= GENOME_SIZE;
398
399 fitness = 1.0 / (1.0 + variance);
400
401 // Diversity
402 diversity = entropy / std::log2(10.0); // Normalized
403
404 // Phi based on fitness and entropy balance
405 phi = compute_phi(fitness * (1.0 - std::abs(entropy / 3.32 - 0.5)));
406 }
407
408 double random_uniform() {
409 static std::mt19937 gen(std::random_device{}());
410 static std::uniform_real_distribution<> dis(0.0, 1.0);
411 return dis(gen);
412 }
413
414 double random_normal() {
415 static std::mt19937 gen(std::random_device{}());
416 static std::normal_distribution<> dis(0.0, 1.0);
417 return dis(gen);
418 }
419};
420
421//=============================================================================
422// L6: OSCILLATORY & FIELD DYNAMICS
423//=============================================================================
424
425/**
426 * KuramotoOscillators - Coupled oscillator network
427 *
428 * Implements:
429 * - Kuramoto order parameter: Z = (1/N)|sum_k exp(i*phi_k)|
430 * - Kuramoto phase dynamics: d(phi_i)/dt = omega_i + (K/N)*sum_j sin(phi_j - phi_i)
431 * - Wilson-Cowan: du/dt = -u + integral(W(x,y)*f(u)dy) + I
432 * - Phase-locking value: PLV = |<exp(i*(phi_1 - phi_2))>|
433 *
434 * Brain frequency bands:
435 * - Delta: 1-4 Hz
436 * - Theta: 4-8 Hz
437 * - Alpha: 8-13 Hz
438 * - Beta: 13-30 Hz
439 * - Gamma: 30-100 Hz
440 */
441template<size_t N = 64>
442class KuramotoOscillators {
443public:
444 std::array<double, N> phases; // Phase of each oscillator
445 std::array<double, N> natural_freqs; // Natural frequencies (Hz)
446 std::array<std::array<double, N>, N> coupling; // Coupling matrix
447
448 double coupling_strength; // Global coupling K
449 double order_parameter; // Synchronization order |Z|
450 double mean_phase; // Mean phase arg(Z)
451 double phi; // Consciousness metric
452
453 // Band power
454 struct BandPower {
455 double delta, theta, alpha, beta, gamma;
456 } band_power;
457
458 KuramotoOscillators(double K = 1.0) : coupling_strength(K) {
459 std::random_device rd;
460 std::mt19937 gen(rd());
461
462 // Initialize phases randomly
463 std::uniform_real_distribution<> phase_dis(0, 2 * M_PI);
464 for (size_t i = 0; i < N; ++i) {
465 phases[i] = phase_dis(gen);
466 }
467
468 // Natural frequencies: mix of brain bands
469 // 20% delta, 20% theta, 20% alpha, 20% beta, 20% gamma
470 for (size_t i = 0; i < N; ++i) {
471 double band_selector = static_cast<double>(i) / N;
472 if (band_selector < 0.2) {
473 natural_freqs[i] = 1.0 + 3.0 * (i % 5) / 4.0; // Delta: 1-4 Hz
474 } else if (band_selector < 0.4) {
475 natural_freqs[i] = 4.0 + 4.0 * (i % 5) / 4.0; // Theta: 4-8 Hz
476 } else if (band_selector < 0.6) {
477 natural_freqs[i] = 8.0 + 5.0 * (i % 5) / 4.0; // Alpha: 8-13 Hz
478 } else if (band_selector < 0.8) {
479 natural_freqs[i] = 13.0 + 17.0 * (i % 5) / 4.0; // Beta: 13-30 Hz
480 } else {
481 natural_freqs[i] = 30.0 + 70.0 * (i % 5) / 4.0; // Gamma: 30-100 Hz
482 }
483 }
484
485 // All-to-all coupling (can be modified for topology)
486 for (size_t i = 0; i < N; ++i) {
487 for (size_t j = 0; j < N; ++j) {
488 coupling[i][j] = 1.0 / N;
489 }
490 }
491
492 update_metrics();
493 }
494
495 /**
496 * Kuramoto phase dynamics step
497 *
498 * d(phi_i)/dt = omega_i + (K/N) * sum_j sin(phi_j - phi_i)
499 */
500 void step(double dt) {
501 std::array<double, N> dphases;
502
503 for (size_t i = 0; i < N; ++i) {
504 double sum_coupling = 0;
505 for (size_t j = 0; j < N; ++j) {
506 sum_coupling += coupling[i][j] * std::sin(phases[j] - phases[i]);
507 }
508 dphases[i] = 2 * M_PI * natural_freqs[i] + coupling_strength * sum_coupling;
509 }
510
511 // Euler integration
512 for (size_t i = 0; i < N; ++i) {
513 phases[i] += dt * dphases[i];
514 // Keep in [0, 2*pi]
515 phases[i] = std::fmod(phases[i], 2 * M_PI);
516 if (phases[i] < 0) phases[i] += 2 * M_PI;
517 }
518
519 update_metrics();
520 }
521
522 /**
523 * Compute Kuramoto order parameter
524 *
525 * Z = (1/N) * sum_k exp(i * phi_k)
526 * |Z| = 0: incoherent, |Z| = 1: fully synchronized
527 */
528 std::complex<double> compute_order_parameter() const {
529 std::complex<double> Z(0, 0);
530 for (size_t i = 0; i < N; ++i) {
531 Z += std::exp(std::complex<double>(0, phases[i]));
532 }
533 return Z / static_cast<double>(N);
534 }
535
536 /**
537 * Compute phase-locking value between two oscillators
538 */
539 double phase_locking_value(size_t i, size_t j) const {
540 return std::abs(std::exp(std::complex<double>(0, phases[i] - phases[j])));
541 }
542
543 /**
544 * Set coupling topology
545 */
546 void set_ring_topology(double local_strength = 1.0, size_t neighbors = 2) {
547 for (size_t i = 0; i < N; ++i) {
548 for (size_t j = 0; j < N; ++j) {
549 size_t dist = std::min((i + N - j) % N, (j + N - i) % N);
550 coupling[i][j] = (dist <= neighbors) ? local_strength / (2 * neighbors) : 0;
551 }
552 }
553 }
554
555 /**
556 * Set small-world topology (Watts-Strogatz)
557 */
558 void set_small_world_topology(double rewire_prob = 0.1) {
559 set_ring_topology(1.0, 4);
560
561 std::random_device rd;
562 std::mt19937 gen(rd());
563 std::uniform_real_distribution<> dis(0.0, 1.0);
564 std::uniform_int_distribution<> node_dis(0, N - 1);
565
566 for (size_t i = 0; i < N; ++i) {
567 for (size_t j = 0; j < N; ++j) {
568 if (coupling[i][j] > 0 && dis(gen) < rewire_prob) {
569 // Rewire to random node
570 size_t new_j = node_dis(gen);
571 coupling[i][j] = 0;
572 coupling[i][new_j] = 1.0 / (2 * 4);
573 }
574 }
575 }
576 }
577
578 /**
579 * Get consciousness metric
580 */
581 double get_phi() const {
582 return phi;
583 }
584
585private:
586 void update_metrics() {
587 auto Z = compute_order_parameter();
588 order_parameter = std::abs(Z);
589 mean_phase = std::arg(Z);
590
591 // Band power (simplified: count oscillators in each band)
592 int delta_count = 0, theta_count = 0, alpha_count = 0;
593 int beta_count = 0, gamma_count = 0;
594
595 for (size_t i = 0; i < N; ++i) {
596 double f = natural_freqs[i];
597 if (f <= 4) delta_count++;
598 else if (f <= 8) theta_count++;
599 else if (f <= 13) alpha_count++;
600 else if (f <= 30) beta_count++;
601 else gamma_count++;
602 }
603
604 band_power.delta = static_cast<double>(delta_count) / N;
605 band_power.theta = static_cast<double>(theta_count) / N;
606 band_power.alpha = static_cast<double>(alpha_count) / N;
607 band_power.beta = static_cast<double>(beta_count) / N;
608 band_power.gamma = static_cast<double>(gamma_count) / N;
609
610 // Phi based on synchronization and band balance
611 // High gamma + good sync = high consciousness
612 double band_balance = 1.0 - std::abs(band_power.gamma - 0.2);
613 phi = compute_phi(order_parameter * (0.5 + 0.5 * band_balance));
614 }
615};
616
617//=============================================================================
618// WILSON-COWAN POPULATION DYNAMICS
619//=============================================================================
620
621/**
622 * WilsonCowanPopulation - Neural population dynamics
623 *
624 * Implements:
625 * dE/dt = -E + S(w_EE*E - w_EI*I + I_ext)
626 * dI/dt = -I + S(w_IE*E - w_II*I)
627 *
628 * where S(x) = 1/(1 + exp(-a*(x - theta)))
629 */
630class WilsonCowanPopulation {
631public:
632 double E; // Excitatory population activity
633 double I; // Inhibitory population activity
634
635 // Connection weights
636 double w_EE; // E -> E
637 double w_EI; // I -> E (inhibitory)
638 double w_IE; // E -> I
639 double w_II; // I -> I (self-inhibition)
640
641 // Parameters
642 double tau_E; // Excitatory time constant
643 double tau_I; // Inhibitory time constant
644 double theta_E; // Excitatory threshold
645 double theta_I; // Inhibitory threshold
646 double a; // Sigmoid steepness
647
648 double phi;
649
650 WilsonCowanPopulation()
651 : E(0.5), I(0.5),
652 w_EE(10.0), w_EI(8.5), w_IE(8.0), w_II(3.0),
653 tau_E(10.0), tau_I(20.0),
654 theta_E(2.0), theta_I(4.0),
655 a(1.0), phi(0.5) {}
656
657 /**
658 * Sigmoid activation function
659 */
660 double sigmoid(double x, double theta) const {
661 return 1.0 / (1.0 + std::exp(-a * (x - theta)));
662 }
663
664 /**
665 * Step dynamics
666 */
667 void step(double dt, double I_ext = 0.0) {
668 // Compute inputs
669 double input_E = w_EE * E - w_EI * I + I_ext;
670 double input_I = w_IE * E - w_II * I;
671
672 // Wilson-Cowan equations
673 double dE = (-E + sigmoid(input_E, theta_E)) / tau_E;
674 double dI = (-I + sigmoid(input_I, theta_I)) / tau_I;
675
676 // Update
677 E += dt * dE;
678 I += dt * dI;
679
680 // Clamp to [0, 1]
681 E = std::max(0.0, std::min(1.0, E));
682 I = std::max(0.0, std::min(1.0, I));
683
684 // Update phi
685 // Balance between E and I indicates healthy dynamics
686 double balance = 1.0 - std::abs(E - I);
687 phi = compute_phi(0.5 * (E + I) * balance);
688 }
689
690 double get_phi() const { return phi; }
691};
692
693//=============================================================================
694// UNIFIED 7-LAYER SYSTEM
695//=============================================================================
696
697/**
698 * SevenLayerSystem - Complete consciousness architecture
699 */
700class SevenLayerSystem {
701public:
702 // Layer implementations
703 QuantumState<16> L1_quantum;
704 GeneticLayer<256> L2_genetic;
705 // L3, L4 simplified (use genetic layer activation)
706 // L5 uses existing neurological.hpp
707 KuramotoOscillators<64> L6_oscillatory;
708 WilsonCowanPopulation L6_population;
709
710 // Layer consciousness tracking
711 LayerConsciousness layer_consc;
712 LayerCoupling layer_coupling;
713
714 // Global metrics
715 double global_phi;
716 double global_omega;
717 int64_t tick;
718
719 SevenLayerSystem() : global_phi(0.5), global_omega(0.5), tick(0) {}
720
721 /**
722 * Step all layers
723 */
724 void step(double dt) {
725 // L1: Quantum evolution
726 L1_quantum.evolve(dt * 0.001); // Faster timescale
727 layer_consc.UpdateLayer(0, L1_quantum.get_phi());
728
729 // L2: Genetic dynamics
730 L2_genetic.step(dt);
731 layer_consc.UpdateLayer(1, L2_genetic.get_phi());
732
733 // L3, L4: Use genetic expression as proxy
734 layer_consc.UpdateLayer(2, L2_genetic.get_phi() * 0.9);
735 layer_consc.UpdateLayer(3, L2_genetic.get_phi() * 0.95);
736
737 // L5: Neural (placeholder - use neurological.hpp externally)
738 // layer_consc.UpdateLayer(4, neural_phi);
739
740 // L6: Oscillatory dynamics
741 L6_oscillatory.step(dt);
742 L6_population.step(dt);
743 double L6_phi = 0.5 * (L6_oscillatory.get_phi() + L6_population.get_phi());
744 layer_consc.UpdateLayer(5, L6_phi);
745
746 // L7: Consciousness integration
747 global_phi = layer_consc.GlobalPhi();
748 layer_consc.UpdateLayer(6, global_phi);
749
750 // Apply cross-layer coupling
751 std::array<double, 7> activations;
752 for (int i = 0; i < 7; ++i) {
753 activations[i] = layer_consc.LayerPhi[i];
754 }
755 layer_coupling.ApplyCoupling(activations, dt);
756
757 // Update with coupled values
758 for (int i = 0; i < 7; ++i) {
759 layer_consc.UpdateLayer(i, activations[i]);
760 }
761
762 // Compute global omega
763 global_omega = layer_consc.GlobalOmega();
764
765 tick++;
766 }
767
768 /**
769 * Inject external neural phi (from L5 neural layer)
770 */
771 void set_neural_phi(double phi) {
772 layer_consc.UpdateLayer(4, phi);
773 }
774
775 /**
776 * Get layer states
777 */
778 std::array<double, 7> get_layer_phis() const {
779 std::array<double, 7> phis;
780 for (int i = 0; i < 7; ++i) {
781 phis[i] = layer_consc.LayerPhi[i];
782 }
783 return phis;
784 }
785
786 double get_global_phi() const { return global_phi; }
787 double get_global_omega() const { return global_omega; }
788};
789
790} // namespace mind_farm
791
792#endif // LAYERS_HPP
793