tvboptim 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. tvboptim/__init__.py +9 -0
  2. tvboptim/data/__init__.py +12 -0
  3. tvboptim/data/loaders.py +99 -0
  4. tvboptim/execution.py +268 -0
  5. tvboptim/experimental/__init__.py +15 -0
  6. tvboptim/experimental/network_dynamics/__init__.py +28 -0
  7. tvboptim/experimental/network_dynamics/core/__init__.py +6 -0
  8. tvboptim/experimental/network_dynamics/core/bunch.py +67 -0
  9. tvboptim/experimental/network_dynamics/core/network.py +686 -0
  10. tvboptim/experimental/network_dynamics/coupling/__init__.py +22 -0
  11. tvboptim/experimental/network_dynamics/coupling/base.py +1005 -0
  12. tvboptim/experimental/network_dynamics/coupling/linear.py +466 -0
  13. tvboptim/experimental/network_dynamics/coupling/subspace.py +509 -0
  14. tvboptim/experimental/network_dynamics/coupling/tvb.py +202 -0
  15. tvboptim/experimental/network_dynamics/dynamics/__init__.py +7 -0
  16. tvboptim/experimental/network_dynamics/dynamics/base.py +541 -0
  17. tvboptim/experimental/network_dynamics/dynamics/lorenz.py +207 -0
  18. tvboptim/experimental/network_dynamics/dynamics/tvb/__init__.py +29 -0
  19. tvboptim/experimental/network_dynamics/dynamics/tvb/coombes_byrne.py +154 -0
  20. tvboptim/experimental/network_dynamics/dynamics/tvb/epileptor.py +200 -0
  21. tvboptim/experimental/network_dynamics/dynamics/tvb/generic_2d_oscillator.py +149 -0
  22. tvboptim/experimental/network_dynamics/dynamics/tvb/jansen_rit.py +158 -0
  23. tvboptim/experimental/network_dynamics/dynamics/tvb/kuramoto.py +120 -0
  24. tvboptim/experimental/network_dynamics/dynamics/tvb/larter_breakspear.py +221 -0
  25. tvboptim/experimental/network_dynamics/dynamics/tvb/linear.py +111 -0
  26. tvboptim/experimental/network_dynamics/dynamics/tvb/montbrio_pazo_roxin.py +137 -0
  27. tvboptim/experimental/network_dynamics/dynamics/tvb/sup_hopf.py +131 -0
  28. tvboptim/experimental/network_dynamics/dynamics/tvb/wilson_cowan.py +210 -0
  29. tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang.py +124 -0
  30. tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang_exc_inh.py +177 -0
  31. tvboptim/experimental/network_dynamics/external_input/__init__.py +20 -0
  32. tvboptim/experimental/network_dynamics/external_input/base.py +152 -0
  33. tvboptim/experimental/network_dynamics/external_input/data.py +203 -0
  34. tvboptim/experimental/network_dynamics/external_input/parametric.py +270 -0
  35. tvboptim/experimental/network_dynamics/graph/__init__.py +14 -0
  36. tvboptim/experimental/network_dynamics/graph/base.py +706 -0
  37. tvboptim/experimental/network_dynamics/graph/sparse.py +885 -0
  38. tvboptim/experimental/network_dynamics/graph/utils.py +0 -0
  39. tvboptim/experimental/network_dynamics/noise/__init__.py +6 -0
  40. tvboptim/experimental/network_dynamics/noise/base.py +162 -0
  41. tvboptim/experimental/network_dynamics/noise/gaussian.py +71 -0
  42. tvboptim/experimental/network_dynamics/result.py +78 -0
  43. tvboptim/experimental/network_dynamics/solve.py +721 -0
  44. tvboptim/experimental/network_dynamics/solvers/__init__.py +15 -0
  45. tvboptim/experimental/network_dynamics/solvers/base.py +46 -0
  46. tvboptim/experimental/network_dynamics/solvers/diffrax.py +63 -0
  47. tvboptim/experimental/network_dynamics/solvers/native.py +308 -0
  48. tvboptim/experimental/network_dynamics/utils/__init__.py +3 -0
  49. tvboptim/experimental/network_dynamics/utils/printer.py +555 -0
  50. tvboptim/model.py +111 -0
  51. tvboptim/observations/__init__.py +3 -0
  52. tvboptim/observations/observation.py +32 -0
  53. tvboptim/observations/tvb_monitors/__init__.py +11 -0
  54. tvboptim/observations/tvb_monitors/bold.py +290 -0
  55. tvboptim/observations/tvb_monitors/downsampling.py +185 -0
  56. tvboptim/optim/__init__.py +4 -0
  57. tvboptim/optim/callbacks.py +333 -0
  58. tvboptim/optim/optax.py +379 -0
  59. tvboptim/types/__init__.py +35 -0
  60. tvboptim/types/parameter.py +769 -0
  61. tvboptim/types/spaces.py +943 -0
  62. tvboptim/types/stateutils.py +109 -0
  63. tvboptim/utils/__init__.py +16 -0
  64. tvboptim/utils/caching.py +82 -0
  65. tvboptim/utils/utils.py +265 -0
  66. tvboptim-0.2.0.dist-info/METADATA +157 -0
  67. tvboptim-0.2.0.dist-info/RECORD +70 -0
  68. tvboptim-0.2.0.dist-info/WHEEL +5 -0
  69. tvboptim-0.2.0.dist-info/licenses/LICENSE +278 -0
  70. tvboptim-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,149 @@
1
+ """Generic 2D oscillator model.
2
+
3
+ A generic two-state-variable dynamic system with configurable nullclines,
4
+ capable of generating a wide range of dynamical behaviors including
5
+ excitability, bistability, and oscillations.
6
+
7
+ References:
8
+ - FitzHugh (1961). Impulses and physiological states in theoretical models
9
+ of nerve membrane. Biophysical Journal, 1, 445.
10
+ - Nagumo et al. (1962). An Active Pulse Transmission Line Simulating Nerve
11
+ Axon. Proceedings of the IRE, 50, 2061.
12
+ - Stefanescu & Jirsa (2008). A low dimensional description of globally
13
+ coupled heterogeneous neural networks of excitatory and inhibitory neurons.
14
+ PLoS Computational Biology, 4(11).
15
+ - Jirsa & Stefanescu (2010). Neural population modes capture biologically
16
+ realistic large-scale network dynamics. Bulletin of Mathematical Biology.
17
+ """
18
+
19
+ import jax.numpy as jnp
20
+
21
+ from ...core.bunch import Bunch
22
+ from ..base import AbstractDynamics
23
+
24
+
25
+ class Generic2dOscillator(AbstractDynamics):
26
+ """Generic 2D oscillator with configurable nullclines.
27
+
28
+ A flexible two-variable dynamical system where V typically represents a fast
29
+ variable (e.g., membrane potential) and W a slow recovery variable. The model
30
+ can exhibit FitzHugh-Nagumo dynamics, bistability, or other behaviors depending
31
+ on parameters.
32
+
33
+ Notes
34
+ -----
35
+ **State equations:**
36
+
37
+ $$
38
+ \\begin{aligned}
39
+ \\frac{dV}{dt} &= d \\tau (-f V^3 + e V^2 + g V + \\alpha W + \\gamma I + \\gamma c_{\\text{delayed}} + c_{\\text{instant}}) \\\\
40
+ \\frac{dW}{dt} &= \\frac{d}{\\tau} (a + b V + c V^2 - \\beta W)
41
+ \\end{aligned}
42
+ $$
43
+
44
+ **Parameter regimes:**
45
+
46
+ - **Excitable (FitzHugh-Nagumo-like)**: $a=-2.0, b=-10.0, c=0.0, d=0.02, I=0.0$
47
+ - **Bistable**: $a=1.0, b=0.0, c=-5.0, d=0.02, I=0.0$
48
+ - **Morris-Lecar-like**: $a=0.5, b=0.6, c=-4.0, d=0.02, I=0.0$
49
+
50
+ Attributes
51
+ ----------
52
+ STATE_NAMES : tuple of str
53
+ State variables: ``('V', 'W')`` (fast and slow variables)
54
+ INITIAL_STATE : tuple of float
55
+ Default initial conditions: ``(0.0, 0.0)``
56
+ COUPLING_INPUTS : dict
57
+ Coupling specification: ``{'instant': 1, 'delayed': 1}``
58
+ DEFAULT_PARAMS : Bunch
59
+ Configurable nullcline parameters
60
+
61
+ References
62
+ ----------
63
+ FitzHugh (1961). Impulses and physiological states in theoretical models
64
+ of nerve membrane. Biophysical Journal, 1, 445.
65
+ """
66
+
67
+ STATE_NAMES = ("V", "W")
68
+ INITIAL_STATE = (0.0, 0.0)
69
+
70
+ DEFAULT_PARAMS = Bunch(
71
+ # Nullcline parameters
72
+ a=-2.0, # Linear coefficient in W equation
73
+ b=-10.0, # Linear V coefficient in W equation
74
+ c=0.0, # Quadratic V coefficient in W equation
75
+ d=0.02, # Global time scaling
76
+ e=3.0, # Quadratic coefficient in V equation
77
+ f=1.0, # Cubic coefficient in V equation
78
+ g=0.0, # Linear coefficient in V equation
79
+ # Coupling parameters
80
+ alpha=1.0, # W to V coupling strength
81
+ beta=1.0, # W decay rate
82
+ gamma=1.0, # External input strength
83
+ # Other parameters
84
+ tau=1.0, # Time scale separation (tau > 1: V faster than W)
85
+ I=0.0, # External input current
86
+ )
87
+
88
+ COUPLING_INPUTS = {
89
+ "instant": 1, # Local/instantaneous coupling
90
+ "delayed": 1, # Long-range delayed coupling
91
+ }
92
+
93
+ EXTERNAL_INPUTS = {"stimulus": 1}
94
+
95
+ def dynamics(
96
+ self,
97
+ t: float,
98
+ state: jnp.ndarray,
99
+ params: Bunch,
100
+ coupling: Bunch,
101
+ external: Bunch,
102
+ ) -> jnp.ndarray:
103
+ """Compute Generic2dOscillator dynamics.
104
+
105
+ Args:
106
+ t: Current time
107
+ state: State [2, n_nodes] with (V, W)
108
+ params: Model parameters
109
+ coupling: Coupling inputs (.instant, .delayed)
110
+
111
+ Returns:
112
+ derivatives: [2, n_nodes] state derivatives
113
+ """
114
+ # Unpack state variables
115
+ V = state[0] # Fast variable (e.g., voltage)
116
+ W = state[1] # Slow variable (e.g., recovery)
117
+
118
+ # Unpack coupling
119
+ c_instant = coupling.instant[0] # Local coupling
120
+ c_delayed = coupling.delayed[0] # Long-range coupling
121
+
122
+ # Unpack external stimulus
123
+ stim = external.stimulus[0] # Extract [1, n_nodes] -> [n_nodes]
124
+
125
+ # V dynamics (cubic nullcline with external input)
126
+ dV_dt = (
127
+ params.d
128
+ * params.tau
129
+ * (
130
+ -params.f * V**3
131
+ + params.e * V**2
132
+ + params.g * V
133
+ + params.alpha * W
134
+ + params.gamma * params.I
135
+ + params.gamma * c_delayed
136
+ + c_instant
137
+ )
138
+ + stim
139
+ )
140
+
141
+ # W dynamics (polynomial nullcline)
142
+ dW_dt = (params.d / params.tau) * (
143
+ params.a + params.b * V + params.c * V**2 - params.beta * W
144
+ )
145
+
146
+ # Package results
147
+ derivatives = jnp.array([dV_dt, dW_dt])
148
+
149
+ return derivatives
@@ -0,0 +1,158 @@
1
+ """Jansen-Rit neural mass model with multi-coupling support."""
2
+
3
+ from typing import Tuple
4
+
5
+ import jax.numpy as jnp
6
+
7
+ from ...core.bunch import Bunch
8
+ from ..base import AbstractDynamics
9
+
10
+
11
+ class JansenRit(AbstractDynamics):
12
+ """Jansen-Rit neural mass model with multi-coupling support.
13
+
14
+ This implementation accepts two coupling inputs (instantaneous and delayed),
15
+ both of which add into the excitatory interneuron population equation.
16
+
17
+ Notes
18
+ -----
19
+ The model describes the dynamics of three neural populations: pyramidal cells,
20
+ excitatory interneurons, and inhibitory interneurons.
21
+
22
+ **State equations:**
23
+
24
+ $$
25
+ \\begin{aligned}
26
+ \\frac{dy_0}{dt} &= y_3 \\\\
27
+ \\frac{dy_3}{dt} &= A a S(y_1 - y_2) - 2a y_3 - a^2 y_0 \\\\
28
+ \\frac{dy_1}{dt} &= y_4 \\\\
29
+ \\frac{dy_4}{dt} &= A a (\\mu + a_2 J S(a_1 J y_0) + c_{\\text{instant}} + c_{\\text{delayed}}) - 2a y_4 - a^2 y_1 \\\\
30
+ \\frac{dy_2}{dt} &= y_5 \\\\
31
+ \\frac{dy_5}{dt} &= B b (a_4 J S(a_3 J y_0)) - 2b y_5 - b^2 y_2
32
+ \\end{aligned}
33
+ $$
34
+
35
+ **Sigmoid function:**
36
+
37
+ $$S(v) = \\frac{2 \\nu_{\\text{max}}}{1 + \\exp(r(v_0 - v))}$$
38
+
39
+ **State variables:**
40
+
41
+ - $y_0$: Average membrane potential of pyramidal cells
42
+ - $y_1$: Average membrane potential of excitatory interneurons
43
+ - $y_2$: Average membrane potential of inhibitory interneurons
44
+ - $y_3, y_4, y_5$: Time derivatives of $y_0, y_1, y_2$
45
+
46
+ Attributes
47
+ ----------
48
+ STATE_NAMES : tuple of str
49
+ State variable names: ``("y0", "y1", "y2", "y3", "y4", "y5")``
50
+ INITIAL_STATE : tuple of float
51
+ Default initial conditions: ``(0.0, 5.0, 5.0, 0.0, 0.0, 0.0)``
52
+ COUPLING_INPUTS : dict
53
+ Coupling input specification: ``{'instant': 1, 'delayed': 1}``
54
+ DEFAULT_PARAMS : Bunch
55
+ Standard Jansen-Rit parameters (A, B, a, b, v0, nu_max, r, J, a_1-a_4, mu)
56
+ """
57
+
58
+ STATE_NAMES = ("y0", "y1", "y2", "y3", "y4", "y5")
59
+ INITIAL_STATE = (0.0, 5.0, 5.0, 0.0, 0.0, 0.0)
60
+
61
+ AUXILIARY_NAMES = ("sigm_y1_y2", "sigm_y0_1", "sigm_y0_3")
62
+
63
+ DEFAULT_PARAMS = Bunch(
64
+ A=3.25, # Maximum amplitude of EPSP [mV]
65
+ B=22.0, # Maximum amplitude of IPSP [mV]
66
+ a=0.1, # Reciprocal of membrane time constant [ms^-1]
67
+ b=0.05, # Reciprocal of membrane time constant [ms^-1]
68
+ v0=5.52, # Firing threshold [mV]
69
+ nu_max=0.0025, # Maximum firing rate [ms^-1]
70
+ r=0.56, # Steepness of sigmoid [mV^-1]
71
+ J=135.0, # Average number of synapses
72
+ a_1=1.0, # Excitatory feedback probability
73
+ a_2=0.8, # Slow excitatory feedback probability
74
+ a_3=0.25, # Inhibitory feedback probability
75
+ a_4=0.25, # Slow inhibitory feedback probability
76
+ mu=0.22, # Mean input firing rate
77
+ )
78
+
79
+ # Multi-coupling: instantaneous and delayed
80
+ COUPLING_INPUTS = {
81
+ "instant": 1,
82
+ "delayed": 1,
83
+ }
84
+
85
+ def dynamics(
86
+ self,
87
+ t: float,
88
+ state: jnp.ndarray,
89
+ params: Bunch,
90
+ coupling: Bunch,
91
+ external: Bunch,
92
+ ) -> Tuple[jnp.ndarray, jnp.ndarray]:
93
+ """Compute Jansen-Rit dynamics with two coupling inputs.
94
+
95
+ Parameters
96
+ ----------
97
+ t : float
98
+ Current time (unused for autonomous system)
99
+ state : jnp.ndarray
100
+ Current state with shape ``[6, n_nodes]`` containing ``(y0, y1, y2, y3, y4, y5)``
101
+ params : Bunch
102
+ Model parameters including: A, B, a, b, v0, nu_max, r, J, a_1, a_2, a_3, a_4, mu
103
+ coupling : Bunch
104
+ Coupling inputs with attributes ``.instant[1, n_nodes]`` and ``.delayed[1, n_nodes]``
105
+ external : Bunch
106
+ External inputs (currently unused)
107
+
108
+ Returns
109
+ -------
110
+ derivatives : jnp.ndarray
111
+ State derivatives with shape ``[6, n_nodes]``
112
+ auxiliaries : jnp.ndarray
113
+ Auxiliary variables with shape ``[3, n_nodes]`` containing sigmoid function values
114
+ """
115
+ # Unpack parameters
116
+ A, B = params.A, params.B
117
+ a, b = params.a, params.b
118
+ v0, nu_max, r = params.v0, params.nu_max, params.r
119
+ J = params.J
120
+ a_1, a_2, a_3, a_4 = params.a_1, params.a_2, params.a_3, params.a_4
121
+ mu = params.mu
122
+
123
+ # Unpack state variables
124
+ y0, y1, y2, y3, y4, y5 = (
125
+ state[0],
126
+ state[1],
127
+ state[2],
128
+ state[3],
129
+ state[4],
130
+ state[5],
131
+ )
132
+
133
+ # Unpack coupling inputs
134
+ c_instant = coupling.instant[0]
135
+ c_delayed = coupling.delayed[0]
136
+
137
+ # Sigmoid functions
138
+ sigm_y1_y2 = 2.0 * nu_max / (1.0 + jnp.exp(r * (v0 - (y1 - y2))))
139
+ sigm_y0_1 = 2.0 * nu_max / (1.0 + jnp.exp(r * (v0 - (a_1 * J * y0))))
140
+ sigm_y0_3 = 2.0 * nu_max / (1.0 + jnp.exp(r * (v0 - (a_3 * J * y0))))
141
+
142
+ # State derivatives (both couplings add to excitatory interneuron)
143
+ dy0_dt = y3
144
+ dy1_dt = y4
145
+ dy2_dt = y5
146
+ dy3_dt = A * a * sigm_y1_y2 - 2.0 * a * y3 - a**2 * y0
147
+ dy4_dt = (
148
+ A * a * (mu + a_2 * J * sigm_y0_1 + c_instant + c_delayed)
149
+ - 2.0 * a * y4
150
+ - a**2 * y1
151
+ )
152
+ dy5_dt = B * b * (a_4 * J * sigm_y0_3) - 2.0 * b * y5 - b**2 * y2
153
+
154
+ # Package results
155
+ derivatives = jnp.array([dy0_dt, dy1_dt, dy2_dt, dy3_dt, dy4_dt, dy5_dt])
156
+ auxiliaries = jnp.array([sigm_y1_y2, sigm_y0_1, sigm_y0_3])
157
+
158
+ return derivatives, auxiliaries
@@ -0,0 +1,120 @@
1
+ """Kuramoto phase oscillator model.
2
+
3
+ Classic model of coupled phase oscillators, widely used to study
4
+ synchronization phenomena in networks of oscillatory units.
5
+
6
+ References:
7
+ - Kuramoto (1984). Chemical Oscillations, Waves, and Turbulence.
8
+ Springer-Verlag, Berlin.
9
+ """
10
+
11
+ import jax.numpy as jnp
12
+
13
+ from ...core.bunch import Bunch
14
+ from ..base import AbstractDynamics
15
+
16
+
17
+ class Kuramoto(AbstractDynamics):
18
+ """Kuramoto phase oscillator model.
19
+
20
+ Single-state model representing the phase angle of an oscillator, widely used to
21
+ study synchronization phenomena in networks of oscillatory units.
22
+
23
+ Notes
24
+ -----
25
+ The model describes synchronization dynamics in networks of coupled oscillators
26
+ through phase interactions.
27
+
28
+ **State equation:**
29
+
30
+ $$\\frac{d\\theta}{dt} = \\omega + c_{\\text{delayed}} + \\sin(c_{\\text{instant}} \\cdot \\theta)$$
31
+
32
+ where:
33
+
34
+ - $\\theta$: Phase angle $[0, 2\\pi]$
35
+ - $\\omega$: Natural frequency of oscillation
36
+ - $c_{\\text{instant}}$: Local coupling (phase-dependent via sinusoidal transformation)
37
+ - $c_{\\text{delayed}}$: Long-range delayed coupling (additive)
38
+
39
+ The local coupling uses a sinusoidal transformation capturing the phase-dependent
40
+ interaction characteristic of Kuramoto-type coupling.
41
+
42
+ Attributes
43
+ ----------
44
+ STATE_NAMES : tuple of str
45
+ State variable: ``('theta',)``
46
+ INITIAL_STATE : tuple of float
47
+ Default initial condition: ``(0.1,)``
48
+ AUXILIARY_NAMES : tuple of str
49
+ No auxiliary variables: ``()``
50
+ COUPLING_INPUTS : dict
51
+ Coupling specification: ``{'instant': 1, 'delayed': 1}``
52
+ DEFAULT_PARAMS : Bunch
53
+ Natural frequency ``omega=1.0`` (rad/s or Hz depending on units)
54
+
55
+ References
56
+ ----------
57
+ Kuramoto (1984). Chemical Oscillations, Waves, and Turbulence. Springer-Verlag, Berlin.
58
+ """
59
+
60
+ STATE_NAMES = ("theta",)
61
+ INITIAL_STATE = (0.1,)
62
+
63
+ DEFAULT_PARAMS = Bunch(
64
+ omega=1.0, # Natural frequency (rad/s or Hz depending on units)
65
+ )
66
+
67
+ COUPLING_INPUTS = {
68
+ "instant": 1, # Local coupling (phase-dependent)
69
+ "delayed": 1, # Long-range delayed coupling
70
+ }
71
+
72
+ def dynamics(
73
+ self,
74
+ t: float,
75
+ state: jnp.ndarray,
76
+ params: Bunch,
77
+ coupling: Bunch,
78
+ external: Bunch,
79
+ ) -> jnp.ndarray:
80
+ """Compute Kuramoto dynamics.
81
+
82
+ Parameters
83
+ ----------
84
+ t : float
85
+ Current time
86
+ state : jnp.ndarray
87
+ Current state with shape ``[1, n_nodes]`` containing theta (phase angle)
88
+ params : Bunch
89
+ Model parameters (omega: natural frequency)
90
+ coupling : Bunch
91
+ Coupling inputs with attributes:
92
+
93
+ - ``.instant[0]``: local coupling (used in sin transform)
94
+ - ``.delayed[0]``: long-range coupling (additive)
95
+ external : Bunch
96
+ External inputs (currently unused)
97
+
98
+ Returns
99
+ -------
100
+ derivatives : jnp.ndarray
101
+ Phase velocity with shape ``[1, n_nodes]``
102
+ """
103
+ # Unpack state
104
+ theta = state[0] # Phase angle
105
+
106
+ # Unpack coupling
107
+ c_instant = coupling.instant[0] # Local coupling
108
+ c_delayed = coupling.delayed[0] # Long-range coupling
109
+
110
+ # Phase dynamics with Kuramoto-style local coupling
111
+ # Local coupling is phase-dependent via sinusoidal transformation
112
+ local_range_coupling = jnp.sin(c_instant * theta)
113
+
114
+ # Phase update: natural frequency + long-range + local coupling
115
+ dtheta_dt = params.omega + c_delayed + local_range_coupling
116
+
117
+ # Package results
118
+ derivatives = jnp.array([dtheta_dt])
119
+
120
+ return derivatives
@@ -0,0 +1,221 @@
1
+ """Larter-Breakspear neural mass model.
2
+
3
+ A modified Morris-Lecar model that includes a third equation simulating
4
+ the effect of inhibitory interneurons synapsing on pyramidal cells.
5
+
6
+ References:
7
+ - Larter et al. (1999). A coupled ordinary differential equation lattice
8
+ model for the simulation of epileptic seizures. Chaos, 9(3), 795.
9
+ - Breakspear et al. (2003). Modulation of excitatory synaptic coupling
10
+ facilitates synchronization and complex dynamics in a biophysical model
11
+ of neuronal dynamics. Network: Computation in Neural Systems, 14, 703-732.
12
+ - Honey et al. (2007). Network structure of cerebral cortex shapes
13
+ functional connectivity on multiple time scales. PNAS, 104, 10240.
14
+ - Alstott et al. (2009). Modeling the impact of lesions in the human brain.
15
+ PLoS Comput Biol, 5, e1000408.
16
+ """
17
+
18
+ from typing import Tuple
19
+
20
+ import jax.numpy as jnp
21
+
22
+ from ...core.bunch import Bunch
23
+ from ..base import AbstractDynamics
24
+
25
+
26
+ class LarterBreakspear(AbstractDynamics):
27
+ """Larter-Breakspear neural mass model.
28
+
29
+ A modified Morris-Lecar model with three state variables representing pyramidal
30
+ cells, potassium dynamics, and inhibitory interneurons. The model exhibits rich
31
+ dynamical behaviors including fixed points, limit cycles, and chaos.
32
+
33
+ Notes
34
+ -----
35
+ **State variables:**
36
+
37
+ - $V$: Membrane potential of pyramidal cells
38
+ - $W$: Potassium channel gating variable
39
+ - $Z$: Inhibitory interneuron activity
40
+
41
+ **Dynamical regimes:**
42
+
43
+ - $d_V < 0.55$: Fixed point dynamics
44
+ - $0.55 < d_V < 0.59$: Limit cycle attractors
45
+ - $d_V > 0.59$: Chaotic attractors
46
+
47
+ **Auxiliary variables:**
48
+
49
+ $$
50
+ \\begin{aligned}
51
+ Q_V &= \\frac{1}{2} Q_{V,\\text{max}} \\left(1 + \\tanh\\left(\\frac{V - V_T}{d_V}\\right)\\right) \\quad \\text{(pyramidal firing rate)} \\\\
52
+ Q_Z &= \\frac{1}{2} Q_{Z,\\text{max}} \\left(1 + \\tanh\\left(\\frac{Z - Z_T}{d_Z}\\right)\\right) \\quad \\text{(inhibitory firing rate)} \\\\
53
+ m_{\\text{Ca}} &= \\frac{1}{2} \\left(1 + \\tanh\\left(\\frac{V - T_{\\text{Ca}}}{d_{\\text{Ca}}}\\right)\\right) \\quad \\text{(Ca channel gating)}
54
+ \\end{aligned}
55
+ $$
56
+
57
+ with similar expressions for $m_{\\text{Na}}$ and $m_K$.
58
+
59
+ Attributes
60
+ ----------
61
+ STATE_NAMES : tuple of str
62
+ State variables: ``('V', 'W', 'Z')``
63
+ INITIAL_STATE : tuple of float
64
+ Default initial conditions: ``(0.0, 0.0, 0.0)``
65
+ AUXILIARY_NAMES : tuple of str
66
+ Auxiliary variables: ``('QV', 'QZ', 'm_Ca', 'm_Na', 'm_K')``
67
+ COUPLING_INPUTS : dict
68
+ Coupling specification: ``{'instant': 1, 'delayed': 1}``
69
+ DEFAULT_PARAMS : Bunch
70
+ Conductances, thresholds, and synaptic weights
71
+
72
+ References
73
+ ----------
74
+ Breakspear et al. (2003). Modulation of excitatory synaptic coupling facilitates
75
+ synchronization and complex dynamics in a biophysical model of neuronal dynamics.
76
+ Network: Computation in Neural Systems, 14, 703-732.
77
+ """
78
+
79
+ STATE_NAMES = ("V", "W", "Z")
80
+ INITIAL_STATE = (0.0, 0.0, 0.0)
81
+
82
+ AUXILIARY_NAMES = ("QV", "QZ", "m_Ca", "m_Na", "m_K")
83
+
84
+ DEFAULT_PARAMS = Bunch(
85
+ # Ion channel conductances
86
+ gCa=1.1, # Ca++ channel conductance
87
+ gK=2.0, # K+ channel conductance
88
+ gL=0.5, # Leak channel conductance
89
+ gNa=6.7, # Na+ channel conductance
90
+ # Channel activation thresholds
91
+ TCa=-0.01, # Ca channel threshold
92
+ TK=0.0, # K channel threshold
93
+ TNa=0.3, # Na channel threshold
94
+ # Channel activation slope parameters
95
+ d_Ca=0.15, # Ca channel threshold variance
96
+ d_K=0.3, # K channel threshold variance
97
+ d_Na=0.15, # Na channel threshold variance
98
+ # Nernst potentials
99
+ VCa=1.0, # Ca Nernst potential
100
+ VK=-0.7, # K Nernst potential
101
+ VL=-0.5, # Leak Nernst potential
102
+ VNa=0.53, # Na Nernst potential
103
+ # Kinetic parameters
104
+ phi=0.7, # Temperature scaling factor
105
+ tau_K=1.0, # K relaxation time constant (ms)
106
+ # Synaptic coupling strengths
107
+ aee=0.4, # Excitatory-to-excitatory
108
+ aei=2.0, # Excitatory-to-inhibitory
109
+ aie=2.0, # Inhibitory-to-excitatory
110
+ ane=1.0, # External-to-excitatory
111
+ ani=0.4, # External-to-inhibitory
112
+ # Other parameters
113
+ b=0.1, # Inhibitory feedback strength
114
+ C=0.1, # Long-range coupling weight (vs local)
115
+ Iext=0.3, # External input current
116
+ rNMDA=0.25, # NMDA receptor strength
117
+ # Firing rate function parameters
118
+ VT=0.0, # Pyramidal cell firing threshold
119
+ d_V=0.65, # Pyramidal cell threshold variance
120
+ ZT=0.0, # Inhibitory cell firing threshold
121
+ d_Z=0.7, # Inhibitory cell threshold variance
122
+ QV_max=1.0, # Maximum pyramidal firing rate
123
+ QZ_max=1.0, # Maximum inhibitory firing rate
124
+ # Time scaling
125
+ t_scale=1.0, # Global time scale factor
126
+ )
127
+
128
+ COUPLING_INPUTS = {
129
+ "instant": 1, # Local/instantaneous coupling
130
+ "delayed": 1, # Long-range delayed coupling
131
+ }
132
+
133
+ def dynamics(
134
+ self,
135
+ t: float,
136
+ state: jnp.ndarray,
137
+ params: Bunch,
138
+ coupling: Bunch,
139
+ external: Bunch,
140
+ ) -> Tuple[jnp.ndarray, jnp.ndarray]:
141
+ """Compute Larter-Breakspear dynamics.
142
+
143
+ Parameters
144
+ ----------
145
+ t : float
146
+ Current time (ms)
147
+ state : jnp.ndarray
148
+ Current state with shape ``[3, n_nodes]`` containing ``(V, W, Z)``
149
+ params : Bunch
150
+ Model parameters
151
+ coupling : Bunch
152
+ Coupling inputs with attributes ``.instant`` and ``.delayed``
153
+ external : Bunch
154
+ External inputs (currently unused)
155
+
156
+ Returns
157
+ -------
158
+ derivatives : jnp.ndarray
159
+ State derivatives with shape ``[3, n_nodes]``
160
+ auxiliaries : jnp.ndarray
161
+ Auxiliary variables with shape ``[5, n_nodes]`` containing ``(QV, QZ, m_Ca, m_Na, m_K)``
162
+ """
163
+ # Unpack state variables
164
+ V = state[0] # Membrane potential
165
+ W = state[1] # K channel gating
166
+ Z = state[2] # Inhibitory activity
167
+
168
+ # Unpack coupling
169
+ c_instant = coupling.instant[0] # Local coupling
170
+ c_delayed = coupling.delayed[0] # Long-range coupling
171
+
172
+ # Channel activation functions (sigmoid gating)
173
+ m_Ca = 0.5 * (1.0 + jnp.tanh((V - params.TCa) / params.d_Ca))
174
+ m_Na = 0.5 * (1.0 + jnp.tanh((V - params.TNa) / params.d_Na))
175
+ m_K = 0.5 * (1.0 + jnp.tanh((V - params.TK) / params.d_K))
176
+
177
+ # Firing rate functions
178
+ QV = 0.5 * params.QV_max * (1.0 + jnp.tanh((V - params.VT) / params.d_V))
179
+ QZ = 0.5 * params.QZ_max * (1.0 + jnp.tanh((Z - params.ZT) / params.d_Z))
180
+
181
+ # Voltage dynamics
182
+ # Ion channel currents
183
+ I_Ca = (
184
+ (
185
+ params.gCa
186
+ + (1.0 - params.C) * params.rNMDA * params.aee * (QV + c_instant)
187
+ + params.C * params.rNMDA * params.aee * c_delayed
188
+ )
189
+ * m_Ca
190
+ * (V - params.VCa)
191
+ )
192
+
193
+ I_K = params.gK * W * (V - params.VK)
194
+
195
+ I_L = params.gL * (V - params.VL)
196
+
197
+ I_Na = (
198
+ params.gNa * m_Na
199
+ + (1.0 - params.C) * params.aee * (QV + c_instant)
200
+ + params.C * params.aee * c_delayed
201
+ ) * (V - params.VNa)
202
+
203
+ I_inh = params.aie * Z * QZ
204
+
205
+ I_ext = params.ane * params.Iext
206
+
207
+ dV_dt = params.t_scale * (-I_Ca - I_K - I_L - I_Na - I_inh + I_ext)
208
+
209
+ # Potassium channel dynamics
210
+ dW_dt = params.t_scale * params.phi * (m_K - W) / params.tau_K
211
+
212
+ # Inhibitory population dynamics
213
+ dZ_dt = (
214
+ params.t_scale * params.b * (params.ani * params.Iext + params.aei * V * QV)
215
+ )
216
+
217
+ # Package results
218
+ derivatives = jnp.array([dV_dt, dW_dt, dZ_dt])
219
+ auxiliaries = jnp.array([QV, QZ, m_Ca, m_Na, m_K])
220
+
221
+ return derivatives, auxiliaries