-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanic_calc.py
More file actions
581 lines (496 loc) Β· 27.8 KB
/
panic_calc.py
File metadata and controls
581 lines (496 loc) Β· 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
from __future__ import annotations
"""Panic Disorder Treatment Calculator.
Mathematical framework for N1-based panic disorder treatment via cortical stimulation.
Core Equations:
Eq P1: LC-NE surge model β NE(t) = NE_base + A Γ exp(-t/Ο_surge) Γ (1 - suppression)
Eq P2: Amygdala-PFC inhibitory restoration β W_inh(n) = W_ceil - (W_ceil-W_0)Γ(1-a+)^(nΓΞ·)
Eq P3: Fear extinction rate β F(n) = F_0 Γ exp(-k_ext Γ n Γ W_inh)
Eq P4: Interoceptive gain model β G_int(t) = G_0 Γ (1 - Ξ² Γ I_insula) / (1 + Ξ³ Γ PFC_activity)
Eq P5: Panic attack probability β P_panic(NE, GABA, PFC) = Ο(w_NEΓNE - w_GABAΓGABA - w_PFCΓPFC - ΞΈ)
Eq P6: GABA deficit recovery β GABA(n) = GABA_floor + (GABA_target - GABA_floor)Γ(1-(1-r)^n)
Eq P7: Autonomic storm index β ASI = NEΒ²/GABA Γ (Sensory Γ Body) / (PFC Γ Coherence)
Eq P8: Acute suppression response time β T_suppress = T_detect + T_compute + T_stim
Eq P9: Fear circuit resonance β Ο_fear = 2Ο Γ f_amygdala, damping ratio ΞΆ = PFC/β(4ΓAmygΓLC)
Eq P10: Long-term panic freedom β P_free(n) = 1 - exp(-ΞΌ Γ n Γ W_inh Γ GABA_recovery)
Profiles (12-variable):
Pathology: DA= eCBβ 5HTβ GABAββ NEβββ Thetaβ Alphaββ Gammaββ PFCββ Sensoryββ Bodyβββ Coherenceββ
Treatment: Acute NE suppression + GABA restoration + PFC activation
Maintenance: PFCβAmygdala pathway strengthening + fear extinction
"""
import math
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Panic Disorder 12-Variable Profiles (3-phase)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PANIC_PATHOLOGY = {
'DA': 1.0, 'eCB': 0.6, '5HT': 0.7, 'GABA': 0.5, 'NE': 2.5,
'Theta': 0.8, 'Alpha': 0.4, 'Gamma': 1.8,
'PFC': 0.4, 'Sensory': 2.5, 'Body': 3.0, 'Coherence': 0.4,
}
PANIC_TREATMENT = {
'DA': 1.0, 'eCB': 1.1, '5HT': 1.1, 'GABA': 1.4, 'NE': 0.6,
'Theta': 1.1, 'Alpha': 1.3, 'Gamma': 0.9,
'PFC': 1.3, 'Sensory': 0.8, 'Body': 0.8, 'Coherence': 1.3,
}
PANIC_MAINTENANCE = {
'DA': 1.0, 'eCB': 1.0, '5HT': 1.0, 'GABA': 1.1, 'NE': 0.9,
'Theta': 1.0, 'Alpha': 1.1, 'Gamma': 0.95,
'PFC': 1.1, 'Sensory': 0.95, 'Body': 0.95, 'Coherence': 1.1,
}
PANIC_BASELINE = {k: 1.0 for k in PANIC_PATHOLOGY}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Circuit Definitions
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PANIC_CIRCUITS = {
'fear_circuit': {
'pathway': 'Amygdala β PAG β Autonomic cascade',
'pathology': 'Amygdala hyperactivation, false threat signaling',
'cortical_source': 'PFC',
'subcortical_target': 'Amygdala',
'f_project': 0.35, # Ghashghaei & Barbas 2002
'primary_variable': 'NE',
'refs': ['Gorman 2000', 'LeDoux 1996'],
},
'lc_ne_surge': {
'pathway': 'LC β Forebrain NE flooding',
'pathology': 'Sudden sympathetic storm: tachycardia, sweating, tremor',
'cortical_source': 'PFC',
'subcortical_target': 'LC',
'f_project': 0.28, # Jodo & Aston-Jones 1997
'primary_variable': 'NE',
'refs': ['Bremner 1996', 'Aston-Jones 2005'],
},
'interoceptive': {
'pathway': 'Insula β ACC β Amygdala',
'pathology': 'Normal body signals misinterpreted as threat',
'cortical_source': 'Insula',
'subcortical_target': 'Amygdala',
'f_project': 0.35, # Augustine 1996
'primary_variable': 'Sensory',
'refs': ['Paulus & Stein 2006', 'Craig 2002'],
},
'pfc_inhibition_failure': {
'pathway': 'vmPFC β Amygdala (inhibitory)',
'pathology': 'Top-down control failure, impaired fear extinction',
'cortical_source': 'PFC',
'subcortical_target': 'Amygdala',
'f_project': 0.35,
'primary_variable': 'PFC',
'refs': ['Milad 2005', 'Quirk 2006'],
},
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P1: LC-NE Surge Model
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def lc_ne_surge(NE_base: float = 1.0, A_surge: float = 1.5,
tau_surge_s: float = 30.0, t_s: float = 0.0,
suppression: float = 0.0) -> dict:
"""NE(t) = NE_base + A Γ exp(-t/Ο) Γ (1 - suppression).
Models the norepinephrine surge during a panic attack.
A_surge: peak amplitude above baseline (1.5 = NE reaches 2.5Γ).
tau_surge: time constant of surge decay (30s untreated).
suppression: N1 stimulation suppression factor (0=none, 1=complete).
"""
ne_t = NE_base + A_surge * math.exp(-t_s / tau_surge_s) * (1.0 - suppression)
# Time to return below 1.3Γ threshold
if A_surge * (1.0 - suppression) > 0.3:
t_threshold = -tau_surge_s * math.log(0.3 / (A_surge * (1.0 - suppression)))
t_threshold = max(0, t_threshold)
else:
t_threshold = 0.0 # already below threshold
return {
'NE_base': NE_base,
'A_surge': A_surge,
'tau_surge_s': tau_surge_s,
'suppression': suppression,
'NE_peak': NE_base + A_surge * (1.0 - suppression),
'NE_at_t': ne_t,
't_below_threshold_s': t_threshold,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P2: Amygdala-PFC Inhibitory Pathway Restoration (STDP)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def amygdala_pfc_restoration(n_sessions: int = 40, pulses_per_session: int = 800,
eta: float = 0.8, a_plus: float = 0.004,
w0: float = 0.4, w_ceil: float = 1.0) -> dict:
"""W_inh(n) = W_ceil - (W_ceil - W_0) Γ (1 - a+)^(n Γ Ξ·).
Restores vmPFCβAmygdala inhibitory pathway via STDP potentiation.
w0=0.4: severely weakened inhibition in panic disorder.
Lower a_plus than depression (0.004 vs 0.005): inhibitory synapses
potentiate slower than excitatory ones (Kullmann 2012).
"""
effective = n_sessions * pulses_per_session * eta
w_final = w_ceil - (w_ceil - w0) * (1.0 - a_plus) ** effective
recovery_pct = ((w_final - w0) / (w_ceil - w0)) * 100
trajectory = []
for s in range(0, n_sessions + 1, max(1, n_sessions // 10)):
eff = s * pulses_per_session * eta
w = w_ceil - (w_ceil - w0) * (1.0 - a_plus) ** eff
trajectory.append({'session': s, 'weight': w,
'recovery_pct': ((w - w0) / (w_ceil - w0)) * 100})
return {
'n_sessions': n_sessions,
'effective_pulses': effective,
'w_initial': w0,
'w_final': w_final,
'recovery_pct': recovery_pct,
'trajectory': trajectory,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P3: Fear Extinction Rate
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def fear_extinction(F_0: float = 1.0, k_ext: float = 0.05,
n_sessions: int = 40, w_inh: float = 0.4) -> dict:
"""F(n) = F_0 Γ exp(-k_ext Γ n Γ W_inh).
Fear response decays exponentially, rate proportional to inhibitory weight.
Stronger PFCβAmygdala inhibition (higher W_inh) = faster extinction.
"""
trajectory = []
for s in range(0, n_sessions + 1, max(1, n_sessions // 10)):
# W_inh also improves over sessions (coupled with Eq P2)
w_s = 0.4 + (1.0 - 0.4) * (1.0 - (1.0 - 0.004) ** (s * 800 * 0.8))
f = F_0 * math.exp(-k_ext * s * w_s)
trajectory.append({'session': s, 'fear': f, 'w_inh': w_s})
f_final = trajectory[-1]['fear']
# Sessions to 50% fear reduction
# Approximate: since w_inh changes, use numerical search
s_50 = None
for t in trajectory:
if t['fear'] <= F_0 * 0.5 and s_50 is None:
s_50 = t['session']
return {
'F_0': F_0,
'F_final': f_final,
'reduction_pct': (1.0 - f_final / F_0) * 100,
'sessions_to_50pct': s_50,
'trajectory': trajectory,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P4: Interoceptive Gain Model
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def interoceptive_gain(G_0: float = 2.5, beta_insula: float = 0.3,
I_insula: float = 0.0, gamma_pfc: float = 0.5,
PFC_activity: float = 0.4) -> dict:
"""G_int(t) = G_0 Γ (1 - Ξ² Γ I_insula) / (1 + Ξ³ Γ PFC_activity).
Models how interoceptive sensitivity is modulated by:
- Insula stimulation (reduces raw gain)
- PFC activity (provides top-down regulation)
G_0=2.5: pathological hypersensitivity.
"""
numerator = G_0 * (1.0 - beta_insula * min(I_insula, 1.0))
denominator = 1.0 + gamma_pfc * PFC_activity
g_int = numerator / denominator
return {
'G_0': G_0,
'I_insula': I_insula,
'PFC_activity': PFC_activity,
'G_int': g_int,
'normalized': g_int <= 1.2,
'reduction_pct': (1.0 - g_int / G_0) * 100,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P5: Panic Attack Probability (logistic model)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def panic_probability(NE: float = 2.5, GABA: float = 0.5, PFC: float = 0.4,
w_NE: float = 2.0, w_GABA: float = 3.0,
w_PFC: float = 2.5, theta: float = 1.0) -> dict:
"""P_panic = Ο(w_NE Γ NE - w_GABA Γ GABA - w_PFC Γ PFC - ΞΈ).
Logistic (sigmoid) model: panic probability as function of 3 key variables.
High NE drives panic; GABA and PFC suppress it.
Ο(x) = 1 / (1 + exp(-x)).
"""
z = w_NE * NE - w_GABA * GABA - w_PFC * PFC - theta
p = 1.0 / (1.0 + math.exp(-z))
return {
'NE': NE, 'GABA': GABA, 'PFC': PFC,
'logit': z,
'p_panic': p,
'risk_level': 'HIGH' if p > 0.7 else 'MODERATE' if p > 0.3 else 'LOW',
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P6: GABA Deficit Recovery
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def gaba_recovery(GABA_floor: float = 0.5, GABA_target: float = 1.0,
r: float = 0.04, n_sessions: int = 40) -> dict:
"""GABA(n) = GABA_floor + (GABA_target - GABA_floor) Γ (1 - (1-r)^n).
Saturating recovery model. r: recovery rate per session.
"""
trajectory = []
for s in range(0, n_sessions + 1, max(1, n_sessions // 10)):
g = GABA_floor + (GABA_target - GABA_floor) * (1.0 - (1.0 - r) ** s)
trajectory.append({'session': s, 'GABA': g})
g_final = GABA_floor + (GABA_target - GABA_floor) * (1.0 - (1.0 - r) ** n_sessions)
recovery_pct = (g_final - GABA_floor) / (GABA_target - GABA_floor) * 100
# Sessions to 80% recovery
if r > 0:
s_80 = math.log(0.2) / math.log(1.0 - r)
else:
s_80 = float('inf')
return {
'GABA_floor': GABA_floor,
'GABA_final': g_final,
'recovery_pct': recovery_pct,
'sessions_to_80pct': s_80,
'trajectory': trajectory,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P7: Autonomic Storm Index
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def autonomic_storm_index(NE: float = 2.5, GABA: float = 0.5,
Sensory: float = 2.5, Body: float = 3.0,
PFC: float = 0.4, Coherence: float = 0.4) -> dict:
"""ASI = NEΒ² / GABA Γ (Sensory Γ Body) / (PFC Γ Coherence).
Composite index of autonomic storm severity.
ASI > 100: severe panic attack. ASI < 10: normal. ASI < 1: suppressed.
"""
numerator = (NE ** 2) * Sensory * Body
denominator = GABA * PFC * Coherence
asi = numerator / max(denominator, 1e-9)
return {
'NE': NE, 'GABA': GABA, 'Sensory': Sensory,
'Body': Body, 'PFC': PFC, 'Coherence': Coherence,
'ASI': asi,
'severity': 'SEVERE' if asi > 100 else 'MODERATE' if asi > 10 else 'MILD' if asi > 1 else 'SUPPRESSED',
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P8: Acute Suppression Response Time
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def acute_response_time(n_channels: int = 1024, base_detect_ms: float = 200.0,
compute_ms: float = 2.0, stim_onset_ms: float = 1.0) -> dict:
"""T_suppress = T_detect + T_compute + T_stim.
T_detect = base / sqrt(N_channels) + latency.
For panic onset detection via sympathetic biomarkers (HR, GSR, pupil).
"""
t_detect = base_detect_ms / math.sqrt(n_channels) + 1.0 # +1ms system latency
t_total = t_detect + compute_ms + stim_onset_ms
# Panic attack ramp: NE surge reaches peak in ~5-10 seconds
# Intervention must start within ~2 seconds for pre-peak suppression
pre_peak = t_total < 2000.0 # < 2 seconds
return {
'n_channels': n_channels,
't_detect_ms': t_detect,
't_compute_ms': compute_ms,
't_stim_onset_ms': stim_onset_ms,
't_total_ms': t_total,
't_total_s': t_total / 1000.0,
'pre_peak_possible': pre_peak,
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P9: Fear Circuit Resonance (damped oscillator model)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def fear_circuit_resonance(f_amygdala_hz: float = 4.0, PFC_strength: float = 0.4,
amygdala_gain: float = 2.5, LC_gain: float = 2.5) -> dict:
"""Ο_fear = 2Ο Γ f_amygdala.
ΞΆ = PFC / β(4 Γ Amyg_gain Γ LC_gain).
Damped harmonic oscillator model of the fear circuit.
ΞΆ < 1: underdamped (oscillating panic-recovery cycles).
ΞΆ = 1: critically damped (fastest return to calm).
ΞΆ > 1: overdamped (slow but monotonic recovery).
Treatment goal: increase ΞΆ from <1 (oscillating panic) to β₯1 (stable).
"""
omega = 2 * math.pi * f_amygdala_hz
zeta = PFC_strength / math.sqrt(4 * amygdala_gain * LC_gain + 1e-9)
# Natural decay time
if zeta < 1:
damped_freq = omega * math.sqrt(1 - zeta ** 2)
decay_time_s = 1.0 / (zeta * omega) if zeta * omega > 0 else float('inf')
oscillating = True
else:
damped_freq = 0.0
decay_time_s = 1.0 / (zeta * omega) if zeta * omega > 0 else float('inf')
oscillating = False
return {
'f_amygdala_hz': f_amygdala_hz,
'omega': omega,
'zeta': zeta,
'PFC_strength': PFC_strength,
'amygdala_gain': amygdala_gain,
'LC_gain': LC_gain,
'oscillating': oscillating,
'damped_freq_hz': damped_freq / (2 * math.pi) if oscillating else 0.0,
'decay_time_s': decay_time_s,
'regime': 'underdamped' if zeta < 1 else 'critically_damped' if abs(zeta - 1) < 0.05 else 'overdamped',
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Eq P10: Long-term Panic Freedom
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def panic_freedom(n_sessions: int = 40, mu: float = 0.02,
w_inh_trajectory: list | None = None,
gaba_trajectory: list | None = None) -> dict:
"""P_free(n) = 1 - exp(-ΞΌ Γ Ξ£_{s=1}^{n} W_inh(s) Γ GABA(s)).
Cumulative probability of sustained panic freedom.
Integrates both pathway restoration and neurochemical recovery.
"""
# Generate default trajectories if not provided
if w_inh_trajectory is None:
w_inh_trajectory = []
for s in range(n_sessions + 1):
eff = s * 800 * 0.8
w = 1.0 - (1.0 - 0.4) * (1.0 - 0.004) ** eff
w_inh_trajectory.append(w)
if gaba_trajectory is None:
gaba_trajectory = []
for s in range(n_sessions + 1):
g = 0.5 + 0.5 * (1.0 - (1.0 - 0.04) ** s)
gaba_trajectory.append(g)
# Cumulative integral
cumulative = 0.0
trajectory = []
for s in range(1, min(n_sessions + 1, len(w_inh_trajectory), len(gaba_trajectory))):
cumulative += w_inh_trajectory[s] * gaba_trajectory[s]
p_free = 1.0 - math.exp(-mu * cumulative)
trajectory.append({'session': s, 'p_free': p_free,
'w_inh': w_inh_trajectory[s], 'gaba': gaba_trajectory[s]})
p_final = trajectory[-1]['p_free'] if trajectory else 0.0
return {
'n_sessions': n_sessions,
'mu': mu,
'p_freedom': p_final,
'trajectory': trajectory[::max(1, len(trajectory) // 10)],
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# N1 Coverage Proof: Panic Circuit Accessibility
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PANIC_COVERAGE = {
'Amygdala': {'sources': ['PFC', 'Insula', 'Temporal'], 'f_project_max': 0.35,
'refs': ['Ghashghaei & Barbas 2002', 'Augustine 1996']},
'PAG': {'sources': ['PFC', 'Insula', 'ACC'], 'f_project_max': 0.25,
'refs': ['Floyd 2000', 'An 1998']},
'LC': {'sources': ['PFC', 'ACC', 'Insula'], 'f_project_max': 0.28,
'refs': ['Jodo & Aston-Jones 1997', 'Aston-Jones & Cohen 2005']},
'Insula': {'sources': ['DIRECT'], 'f_project_max': 1.0,
'refs': ['N1 cortical electrode β direct access'],
'note': 'Insula is cortical; N1 can place electrodes directly'},
}
def panic_circuit_coverage() -> dict:
"""Theorem 11: All 4 panic-critical structures accessible via N1.
Proof by enumeration. Special case: Insula is cortical β direct access.
"""
two_hub = {'PFC', 'ACC'}
covered = {}
for structure, info in PANIC_COVERAGE.items():
if 'DIRECT' in info['sources']:
accessible_via = ['DIRECT (cortical)']
is_accessible = True
else:
accessible_via = [s for s in info['sources'] if s in two_hub]
is_accessible = len(accessible_via) > 0
covered[structure] = {
'accessible': is_accessible,
'via': accessible_via,
'f_project_max': info['f_project_max'],
}
all_covered = all(v['accessible'] for v in covered.values())
return {
'theorem': 'Theorem 11 (Panic Circuit Coverage)',
'hub_set': two_hub | {'Insula (direct)'},
'structures_covered': sum(1 for v in covered.values() if v['accessible']),
'structures_total': len(PANIC_COVERAGE),
'all_covered': all_covered,
'details': covered,
'proof_type': 'pure_math',
}
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Comprehensive Report
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def print_report():
"""Print full Panic Disorder treatment calculator report."""
print(f"\n{'=' * 70}")
print(f" Panic Disorder Treatment Calculator")
print(f" N1 Cortical Stimulation β Mathematical Framework")
print(f"{'=' * 70}")
# Profiles
print(f"\n === 12-Variable Profiles ===")
print(f" {'Var':<12} {'Pathology':>10} {'Treatment':>10} {'Maintenance':>12} {'Baseline':>10}")
print(f" {'-'*12} {'-'*10} {'-'*10} {'-'*12} {'-'*10}")
for var in PANIC_PATHOLOGY:
print(f" {var:<12} {PANIC_PATHOLOGY[var]:>10.2f} {PANIC_TREATMENT[var]:>10.2f} "
f"{PANIC_MAINTENANCE[var]:>12.2f} {PANIC_BASELINE[var]:>10.2f}")
# Eq P1: LC-NE surge
print(f"\n === Eq P1: LC-NE Surge Model ===")
print(f" NE(t) = NE_base + A Γ exp(-t/Ο) Γ (1 - suppression)")
for supp in [0.0, 0.3, 0.6, 0.9]:
r = lc_ne_surge(suppression=supp)
print(f" supp={supp:.1f}: NE_peak={r['NE_peak']:.2f}, "
f"t<1.3Γ: {r['t_below_threshold_s']:.1f}s")
# Eq P2: Amygdala-PFC restoration
print(f"\n === Eq P2: Amygdala-PFC Inhibitory Restoration ===")
print(f" W_inh(n) = W_ceil - (W_ceil-W_0) Γ (1-a+)^(nΓΞ·)")
for sessions in [10, 20, 30, 40]:
r = amygdala_pfc_restoration(n_sessions=sessions)
print(f" {sessions:>3} sessions: W={r['w_final']:.4f}, recovery={r['recovery_pct']:.1f}%")
# Eq P3: Fear extinction
print(f"\n === Eq P3: Fear Extinction Rate ===")
print(f" F(n) = F_0 Γ exp(-k Γ n Γ W_inh)")
r = fear_extinction()
print(f" F_0={r['F_0']:.1f} β F_final={r['F_final']:.4f}, "
f"reduction={r['reduction_pct']:.1f}%")
if r['sessions_to_50pct']:
print(f" 50% reduction at session {r['sessions_to_50pct']}")
# Eq P4: Interoceptive gain
print(f"\n === Eq P4: Interoceptive Gain Model ===")
print(f" G_int = G_0 Γ (1-Ξ²ΓI) / (1+Ξ³ΓPFC)")
for I_ins, pfc in [(0, 0.4), (0.5, 0.4), (0.5, 1.0), (1.0, 1.3)]:
r = interoceptive_gain(I_insula=I_ins, PFC_activity=pfc)
print(f" I_ins={I_ins:.1f} PFC={pfc:.1f}: G={r['G_int']:.2f} "
f"({'β' if r['normalized'] else 'β'}) {r['reduction_pct']:.0f}% reduced")
# Eq P5: Panic probability
print(f"\n === Eq P5: Panic Attack Probability ===")
print(f" P = Ο(w_NEΓNE - w_GABAΓGABA - w_PFCΓPFC - ΞΈ)")
scenarios = [
('Pathological', 2.5, 0.5, 0.4),
('Partial Tx', 1.5, 0.8, 0.8),
('Near normal', 1.1, 1.0, 1.0),
('Treated', 0.8, 1.2, 1.2),
]
for name, ne, gaba, pfc in scenarios:
r = panic_probability(ne, gaba, pfc)
print(f" {name:<14} NE={ne:.1f} GABA={gaba:.1f} PFC={pfc:.1f}: "
f"P={r['p_panic']:.4f} [{r['risk_level']}]")
# Eq P6: GABA recovery
print(f"\n === Eq P6: GABA Deficit Recovery ===")
print(f" GABA(n) = floor + (target-floor) Γ (1-(1-r)^n)")
r = gaba_recovery()
print(f" Floor={r['GABA_floor']:.1f} β Final={r['GABA_final']:.3f}, "
f"recovery={r['recovery_pct']:.1f}%, 80%@{r['sessions_to_80pct']:.0f}sess")
# Eq P7: ASI
print(f"\n === Eq P7: Autonomic Storm Index ===")
print(f" ASI = NEΒ²/GABA Γ (SensoryΓBody) / (PFCΓCoherence)")
scenarios_asi = [
('Panic attack', 2.5, 0.5, 2.5, 3.0, 0.4, 0.4),
('Partial Tx', 1.5, 0.8, 1.5, 1.5, 0.8, 0.8),
('Normal', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0),
('Suppressed', 0.6, 1.3, 0.8, 0.8, 1.3, 1.2),
]
for name, ne, gaba, sens, body, pfc, coh in scenarios_asi:
r = autonomic_storm_index(ne, gaba, sens, body, pfc, coh)
print(f" {name:<14}: ASI={r['ASI']:>8.1f} [{r['severity']}]")
# Eq P8: Response time
print(f"\n === Eq P8: Acute Suppression Response Time ===")
print(f" T = T_detect + T_compute + T_stim")
for nch in [4, 64, 256, 1024]:
r = acute_response_time(n_channels=nch)
print(f" {nch:>5}ch: T_detect={r['t_detect_ms']:.1f}ms, "
f"T_total={r['t_total_ms']:.1f}ms ({r['t_total_s']:.3f}s) "
f"{'PRE-PEAK' if r['pre_peak_possible'] else 'TOO SLOW'}")
# Eq P9: Fear circuit resonance
print(f"\n === Eq P9: Fear Circuit Resonance ===")
print(f" ΞΆ = PFC / β(4 Γ Amyg Γ LC)")
for pfc, amyg, lc in [(0.4, 2.5, 2.5), (0.8, 1.5, 1.5), (1.0, 1.0, 1.0), (1.3, 0.8, 0.8)]:
r = fear_circuit_resonance(PFC_strength=pfc, amygdala_gain=amyg, LC_gain=lc)
print(f" PFC={pfc:.1f} Amyg={amyg:.1f} LC={lc:.1f}: ΞΆ={r['zeta']:.3f} "
f"[{r['regime']}] decay={r['decay_time_s']:.2f}s")
# Eq P10: Panic freedom
print(f"\n === Eq P10: Long-term Panic Freedom ===")
print(f" P_free = 1 - exp(-ΞΌ Γ Ξ£ W_inh Γ GABA)")
r = panic_freedom()
print(f" 40 sessions: P_freedom={r['p_freedom']:.4f}")
# Theorem 11: Coverage
print(f"\n === Theorem 11: Panic Circuit Coverage ===")
c = panic_circuit_coverage()
print(f" Hub set: {c['hub_set']}")
print(f" Coverage: {c['structures_covered']}/{c['structures_total']}")
for struct, info in c['details'].items():
print(f" {struct:<15} via {info['via']}, f_max={info['f_project_max']:.2f} "
f"{'β' if info['accessible'] else 'β'}")
if __name__ == '__main__':
print_report()