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.
- tvboptim/__init__.py +9 -0
- tvboptim/data/__init__.py +12 -0
- tvboptim/data/loaders.py +99 -0
- tvboptim/execution.py +268 -0
- tvboptim/experimental/__init__.py +15 -0
- tvboptim/experimental/network_dynamics/__init__.py +28 -0
- tvboptim/experimental/network_dynamics/core/__init__.py +6 -0
- tvboptim/experimental/network_dynamics/core/bunch.py +67 -0
- tvboptim/experimental/network_dynamics/core/network.py +686 -0
- tvboptim/experimental/network_dynamics/coupling/__init__.py +22 -0
- tvboptim/experimental/network_dynamics/coupling/base.py +1005 -0
- tvboptim/experimental/network_dynamics/coupling/linear.py +466 -0
- tvboptim/experimental/network_dynamics/coupling/subspace.py +509 -0
- tvboptim/experimental/network_dynamics/coupling/tvb.py +202 -0
- tvboptim/experimental/network_dynamics/dynamics/__init__.py +7 -0
- tvboptim/experimental/network_dynamics/dynamics/base.py +541 -0
- tvboptim/experimental/network_dynamics/dynamics/lorenz.py +207 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/__init__.py +29 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/coombes_byrne.py +154 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/epileptor.py +200 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/generic_2d_oscillator.py +149 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/jansen_rit.py +158 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/kuramoto.py +120 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/larter_breakspear.py +221 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/linear.py +111 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/montbrio_pazo_roxin.py +137 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/sup_hopf.py +131 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/wilson_cowan.py +210 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang.py +124 -0
- tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang_exc_inh.py +177 -0
- tvboptim/experimental/network_dynamics/external_input/__init__.py +20 -0
- tvboptim/experimental/network_dynamics/external_input/base.py +152 -0
- tvboptim/experimental/network_dynamics/external_input/data.py +203 -0
- tvboptim/experimental/network_dynamics/external_input/parametric.py +270 -0
- tvboptim/experimental/network_dynamics/graph/__init__.py +14 -0
- tvboptim/experimental/network_dynamics/graph/base.py +706 -0
- tvboptim/experimental/network_dynamics/graph/sparse.py +885 -0
- tvboptim/experimental/network_dynamics/graph/utils.py +0 -0
- tvboptim/experimental/network_dynamics/noise/__init__.py +6 -0
- tvboptim/experimental/network_dynamics/noise/base.py +162 -0
- tvboptim/experimental/network_dynamics/noise/gaussian.py +71 -0
- tvboptim/experimental/network_dynamics/result.py +78 -0
- tvboptim/experimental/network_dynamics/solve.py +721 -0
- tvboptim/experimental/network_dynamics/solvers/__init__.py +15 -0
- tvboptim/experimental/network_dynamics/solvers/base.py +46 -0
- tvboptim/experimental/network_dynamics/solvers/diffrax.py +63 -0
- tvboptim/experimental/network_dynamics/solvers/native.py +308 -0
- tvboptim/experimental/network_dynamics/utils/__init__.py +3 -0
- tvboptim/experimental/network_dynamics/utils/printer.py +555 -0
- tvboptim/model.py +111 -0
- tvboptim/observations/__init__.py +3 -0
- tvboptim/observations/observation.py +32 -0
- tvboptim/observations/tvb_monitors/__init__.py +11 -0
- tvboptim/observations/tvb_monitors/bold.py +290 -0
- tvboptim/observations/tvb_monitors/downsampling.py +185 -0
- tvboptim/optim/__init__.py +4 -0
- tvboptim/optim/callbacks.py +333 -0
- tvboptim/optim/optax.py +379 -0
- tvboptim/types/__init__.py +35 -0
- tvboptim/types/parameter.py +769 -0
- tvboptim/types/spaces.py +943 -0
- tvboptim/types/stateutils.py +109 -0
- tvboptim/utils/__init__.py +16 -0
- tvboptim/utils/caching.py +82 -0
- tvboptim/utils/utils.py +265 -0
- tvboptim-0.2.0.dist-info/METADATA +157 -0
- tvboptim-0.2.0.dist-info/RECORD +70 -0
- tvboptim-0.2.0.dist-info/WHEEL +5 -0
- tvboptim-0.2.0.dist-info/licenses/LICENSE +278 -0
- tvboptim-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""Lorenz chaotic dynamical system with multi-coupling support."""
|
|
2
|
+
|
|
3
|
+
import jax.numpy as jnp
|
|
4
|
+
|
|
5
|
+
from ..core.bunch import Bunch
|
|
6
|
+
from .base import AbstractDynamics
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Lorenz(AbstractDynamics):
|
|
10
|
+
"""Lorenz chaotic dynamical system with multi-coupling support.
|
|
11
|
+
|
|
12
|
+
The classic three-dimensional chaotic system with support for structural coupling.
|
|
13
|
+
|
|
14
|
+
Notes
|
|
15
|
+
-----
|
|
16
|
+
**State equations:**
|
|
17
|
+
|
|
18
|
+
$$
|
|
19
|
+
\\begin{aligned}
|
|
20
|
+
\\frac{dx}{dt} &= \\sigma(y - x) + c_{\\text{structural}} \\\\
|
|
21
|
+
\\frac{dy}{dt} &= x(\\rho - z) - y \\\\
|
|
22
|
+
\\frac{dz}{dt} &= xy - \\beta z
|
|
23
|
+
\\end{aligned}
|
|
24
|
+
$$
|
|
25
|
+
|
|
26
|
+
where $c_{\\text{structural}}$ is the structural coupling input.
|
|
27
|
+
|
|
28
|
+
Attributes
|
|
29
|
+
----------
|
|
30
|
+
STATE_NAMES : tuple of str
|
|
31
|
+
State variable names: ``("x", "y", "z")``
|
|
32
|
+
INITIAL_STATE : tuple of float
|
|
33
|
+
Default initial conditions: ``(1.0, 1.0, 1.0)``
|
|
34
|
+
COUPLING_INPUTS : dict
|
|
35
|
+
Coupling specification: ``{'structural': 1}`` (single structural coupling to x)
|
|
36
|
+
DEFAULT_PARAMS : Bunch
|
|
37
|
+
Model parameters: ``sigma=10.0`` (Prandtl number), ``rho=28.0`` (Rayleigh number),
|
|
38
|
+
``beta=8/3`` (geometric parameter)
|
|
39
|
+
|
|
40
|
+
Examples
|
|
41
|
+
--------
|
|
42
|
+
>>> dynamics = Lorenz()
|
|
43
|
+
>>> dynamics = Lorenz(sigma=15.0, rho=30.0)
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
STATE_NAMES = ("x", "y", "z")
|
|
47
|
+
INITIAL_STATE = (1.0, 1.0, 1.0)
|
|
48
|
+
|
|
49
|
+
AUXILIARY_NAMES = ()
|
|
50
|
+
|
|
51
|
+
DEFAULT_PARAMS = Bunch(
|
|
52
|
+
sigma=10.0, # Prandtl number
|
|
53
|
+
rho=28.0, # Rayleigh number
|
|
54
|
+
beta=8.0 / 3.0, # Geometric parameter
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# NEW: Declare expected coupling inputs
|
|
58
|
+
COUPLING_INPUTS = {
|
|
59
|
+
"structural": 1, # Structural connectivity coupling
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def dynamics(
|
|
63
|
+
self,
|
|
64
|
+
t: float,
|
|
65
|
+
state: jnp.ndarray,
|
|
66
|
+
params: Bunch,
|
|
67
|
+
coupling: Bunch,
|
|
68
|
+
external: Bunch,
|
|
69
|
+
) -> jnp.ndarray:
|
|
70
|
+
"""Compute Lorenz system derivatives with coupling.
|
|
71
|
+
|
|
72
|
+
Parameters
|
|
73
|
+
----------
|
|
74
|
+
t : float
|
|
75
|
+
Current time (unused for autonomous system)
|
|
76
|
+
state : jnp.ndarray
|
|
77
|
+
Current state with shape ``[3, n_nodes]`` containing ``(x, y, z)``
|
|
78
|
+
params : Bunch
|
|
79
|
+
Model parameters: sigma, rho, beta
|
|
80
|
+
coupling : Bunch
|
|
81
|
+
Coupling inputs with attribute ``.structural[1, n_nodes]``
|
|
82
|
+
external : Bunch
|
|
83
|
+
External inputs (currently unused)
|
|
84
|
+
|
|
85
|
+
Returns
|
|
86
|
+
-------
|
|
87
|
+
derivatives : jnp.ndarray
|
|
88
|
+
State derivatives with shape ``[3, n_nodes]`` containing ``(dx/dt, dy/dt, dz/dt)``
|
|
89
|
+
"""
|
|
90
|
+
x, y, z = state[0], state[1], state[2]
|
|
91
|
+
|
|
92
|
+
# Access structural coupling via Bunch attribute
|
|
93
|
+
structural = coupling.structural[0]
|
|
94
|
+
|
|
95
|
+
# Lorenz equations with coupling
|
|
96
|
+
dxdt = params.sigma * (y - x) + structural
|
|
97
|
+
dydt = x * (params.rho - z) - y
|
|
98
|
+
dzdt = x * y - params.beta * z
|
|
99
|
+
|
|
100
|
+
return jnp.array([dxdt, dydt, dzdt])
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class FlexibleLorenz(AbstractDynamics):
|
|
104
|
+
"""Lorenz system with multiple coupling types for demonstration.
|
|
105
|
+
|
|
106
|
+
Extends the Lorenz system to support multiple coupling mechanisms:
|
|
107
|
+
structural (diffusive) and modulatory (gain modulation).
|
|
108
|
+
|
|
109
|
+
Notes
|
|
110
|
+
-----
|
|
111
|
+
**State equations:**
|
|
112
|
+
|
|
113
|
+
$$
|
|
114
|
+
\\begin{aligned}
|
|
115
|
+
\\frac{dx}{dt} &= \\sigma_{\\text{eff}}(y - x) + c_{\\text{structural}} \\\\
|
|
116
|
+
\\frac{dy}{dt} &= x(\\rho - z) - y \\\\
|
|
117
|
+
\\frac{dz}{dt} &= xy - \\beta z
|
|
118
|
+
\\end{aligned}
|
|
119
|
+
$$
|
|
120
|
+
|
|
121
|
+
where the effective sigma parameter is modulated by coupling:
|
|
122
|
+
|
|
123
|
+
$$\\sigma_{\\text{eff}} = \\sigma (1 + \\alpha \\cdot c_{\\text{modulatory}})$$
|
|
124
|
+
|
|
125
|
+
with $\\alpha$ being the modulation strength parameter.
|
|
126
|
+
|
|
127
|
+
Attributes
|
|
128
|
+
----------
|
|
129
|
+
STATE_NAMES : tuple of str
|
|
130
|
+
State variable names: ``("x", "y", "z")``
|
|
131
|
+
INITIAL_STATE : tuple of float
|
|
132
|
+
Default initial conditions: ``(1.0, 1.0, 1.0)``
|
|
133
|
+
COUPLING_INPUTS : dict
|
|
134
|
+
Coupling specification: ``{'structural': 1, 'modulatory': 1}``
|
|
135
|
+
DEFAULT_PARAMS : Bunch
|
|
136
|
+
Model parameters including ``modulation_strength=0.3`` to control
|
|
137
|
+
how much modulatory coupling affects sigma
|
|
138
|
+
|
|
139
|
+
Examples
|
|
140
|
+
--------
|
|
141
|
+
>>> # Use both couplings
|
|
142
|
+
>>> dynamics = FlexibleLorenz()
|
|
143
|
+
>>> # If only structural is provided, modulatory gets zeros automatically
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
STATE_NAMES = ("x", "y", "z")
|
|
147
|
+
INITIAL_STATE = (1.0, 1.0, 1.0)
|
|
148
|
+
|
|
149
|
+
AUXILIARY_NAMES = ()
|
|
150
|
+
|
|
151
|
+
DEFAULT_PARAMS = Bunch(
|
|
152
|
+
sigma=10.0,
|
|
153
|
+
rho=28.0,
|
|
154
|
+
beta=8.0 / 3.0,
|
|
155
|
+
modulation_strength=0.3, # How much modulatory coupling affects sigma
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Declare multiple coupling inputs
|
|
159
|
+
COUPLING_INPUTS = {
|
|
160
|
+
"structural": 1, # Structural connectivity
|
|
161
|
+
"modulatory": 1, # Gain modulation
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
def dynamics(
|
|
165
|
+
self,
|
|
166
|
+
t: float,
|
|
167
|
+
state: jnp.ndarray,
|
|
168
|
+
params: Bunch,
|
|
169
|
+
coupling: Bunch,
|
|
170
|
+
external: Bunch,
|
|
171
|
+
) -> jnp.ndarray:
|
|
172
|
+
"""Compute Lorenz derivatives with multi-coupling.
|
|
173
|
+
|
|
174
|
+
Parameters
|
|
175
|
+
----------
|
|
176
|
+
t : float
|
|
177
|
+
Current time (unused for autonomous system)
|
|
178
|
+
state : jnp.ndarray
|
|
179
|
+
Current state with shape ``[3, n_nodes]`` containing ``(x, y, z)``
|
|
180
|
+
params : Bunch
|
|
181
|
+
Model parameters: sigma, rho, beta, modulation_strength
|
|
182
|
+
coupling : Bunch
|
|
183
|
+
Coupling inputs with attributes ``.structural`` and ``.modulatory``
|
|
184
|
+
external : Bunch
|
|
185
|
+
External inputs (currently unused)
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
derivatives : jnp.ndarray
|
|
190
|
+
State derivatives with shape ``[3, n_nodes]`` containing ``(dx/dt, dy/dt, dz/dt)``
|
|
191
|
+
"""
|
|
192
|
+
x, y, z = state[0], state[1], state[2]
|
|
193
|
+
|
|
194
|
+
# Access both couplings via Bunch attributes
|
|
195
|
+
structural = coupling.structural[0]
|
|
196
|
+
modulatory = coupling.modulatory[0]
|
|
197
|
+
|
|
198
|
+
# Model-specific combination logic:
|
|
199
|
+
# Modulatory coupling affects the effective sigma parameter
|
|
200
|
+
effective_sigma = params.sigma * (1.0 + params.modulation_strength * modulatory)
|
|
201
|
+
|
|
202
|
+
# Lorenz equations with modulated sigma and structural coupling
|
|
203
|
+
dxdt = effective_sigma * (y - x) + structural
|
|
204
|
+
dydt = x * (params.rho - z) - y
|
|
205
|
+
dzdt = x * y - params.beta * z
|
|
206
|
+
|
|
207
|
+
return jnp.array([dxdt, dydt, dzdt])
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Neural mass models."""
|
|
2
|
+
|
|
3
|
+
from .coombes_byrne import CoombesByrne2D
|
|
4
|
+
from .epileptor import Epileptor
|
|
5
|
+
from .generic_2d_oscillator import Generic2dOscillator
|
|
6
|
+
from .jansen_rit import JansenRit
|
|
7
|
+
from .kuramoto import Kuramoto
|
|
8
|
+
from .larter_breakspear import LarterBreakspear
|
|
9
|
+
from .linear import Linear
|
|
10
|
+
from .montbrio_pazo_roxin import MontbrioPazoRoxin
|
|
11
|
+
from .sup_hopf import SupHopf
|
|
12
|
+
from .wilson_cowan import WilsonCowan
|
|
13
|
+
from .wong_wang import ReducedWongWang
|
|
14
|
+
from .wong_wang_exc_inh import WongWangExcInh
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CoombesByrne2D",
|
|
18
|
+
"Epileptor",
|
|
19
|
+
"Generic2dOscillator",
|
|
20
|
+
"JansenRit",
|
|
21
|
+
"Kuramoto",
|
|
22
|
+
"LarterBreakspear",
|
|
23
|
+
"Linear",
|
|
24
|
+
"MontbrioPazoRoxin",
|
|
25
|
+
"SupHopf",
|
|
26
|
+
"WilsonCowan",
|
|
27
|
+
"ReducedWongWang",
|
|
28
|
+
"WongWangExcInh",
|
|
29
|
+
]
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Coombes-Byrne 2D infinite theta neuron model.
|
|
2
|
+
|
|
3
|
+
Mean field model of infinite populations of all-to-all coupled QIF neurons
|
|
4
|
+
with synaptic conductance dynamics, derived via the Ott-Antonsen reduction.
|
|
5
|
+
|
|
6
|
+
References:
|
|
7
|
+
- Coombes & Byrne (2019). Next generation neural mass models. In Nonlinear
|
|
8
|
+
Dynamics in Computational Neuroscience (pp. 1-16). Springer.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import Tuple
|
|
12
|
+
|
|
13
|
+
import jax.numpy as jnp
|
|
14
|
+
|
|
15
|
+
from ...core.bunch import Bunch
|
|
16
|
+
from ..base import AbstractDynamics
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CoombesByrne2D(AbstractDynamics):
|
|
20
|
+
"""Coombes-Byrne 2D infinite theta neuron population model.
|
|
21
|
+
|
|
22
|
+
Two-dimensional mean field model with conductance-based synaptic interactions,
|
|
23
|
+
derived via the Ott-Antonsen reduction. Unlike the Montbrio-Pazo-Roxin model,
|
|
24
|
+
this includes implicit synaptic conductance proportional to firing rate.
|
|
25
|
+
|
|
26
|
+
Notes
|
|
27
|
+
-----
|
|
28
|
+
**State variables:**
|
|
29
|
+
|
|
30
|
+
- $r$: Average firing rate of the population
|
|
31
|
+
- $V$: Average membrane potential of the population
|
|
32
|
+
|
|
33
|
+
**Synaptic conductance:**
|
|
34
|
+
|
|
35
|
+
$$g = \\kappa \\pi r$$
|
|
36
|
+
|
|
37
|
+
where $\\kappa$ is the synaptic conductance scaling factor.
|
|
38
|
+
|
|
39
|
+
**State equations:**
|
|
40
|
+
|
|
41
|
+
$$
|
|
42
|
+
\\begin{aligned}
|
|
43
|
+
\\frac{dr}{dt} &= \\frac{\\Delta}{\\pi} + 2Vr - gr^2 \\\\
|
|
44
|
+
\\frac{dV}{dt} &= V^2 - (\\pi r)^2 + \\eta + (v_{\\text{syn}} - V)g + c_{\\text{coup}}
|
|
45
|
+
\\end{aligned}
|
|
46
|
+
$$
|
|
47
|
+
|
|
48
|
+
where $c_{\\text{coup}}$ is the combined instant and delayed coupling.
|
|
49
|
+
|
|
50
|
+
The conductance $g = \\kappa \\pi r$ creates a quadratic nonlinearity in the
|
|
51
|
+
firing rate equation, leading to different dynamical regimes compared to the
|
|
52
|
+
standard Montbrio-Pazo-Roxin model.
|
|
53
|
+
|
|
54
|
+
Attributes
|
|
55
|
+
----------
|
|
56
|
+
STATE_NAMES : tuple of str
|
|
57
|
+
State variables: ``('r', 'V')``
|
|
58
|
+
INITIAL_STATE : tuple of float
|
|
59
|
+
Default initial conditions: ``(0.1, 0.0)``
|
|
60
|
+
AUXILIARY_NAMES : tuple of str
|
|
61
|
+
Auxiliary variable: ``('g',)`` (synaptic conductance)
|
|
62
|
+
COUPLING_INPUTS : dict
|
|
63
|
+
Coupling specification: ``{'instant': 1, 'delayed': 1}``
|
|
64
|
+
DEFAULT_PARAMS : Bunch
|
|
65
|
+
Standard Coombes-Byrne parameters
|
|
66
|
+
|
|
67
|
+
References
|
|
68
|
+
----------
|
|
69
|
+
Coombes & Byrne (2019). Next generation neural mass models. In Nonlinear
|
|
70
|
+
Dynamics in Computational Neuroscience (pp. 1-16). Springer.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
STATE_NAMES = ("r", "V")
|
|
74
|
+
INITIAL_STATE = (0.1, 0.0)
|
|
75
|
+
|
|
76
|
+
AUXILIARY_NAMES = ("g",)
|
|
77
|
+
|
|
78
|
+
DEFAULT_PARAMS = Bunch(
|
|
79
|
+
Delta=1.0, # Width of heterogeneous noise distribution
|
|
80
|
+
eta=2.0, # Constant external input
|
|
81
|
+
k=1.0, # Synaptic conductance scaling (kappa)
|
|
82
|
+
v_syn=0.0, # Synaptic reversal potential
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
COUPLING_INPUTS = {
|
|
86
|
+
"instant": 1, # Local coupling through r
|
|
87
|
+
"delayed": 1, # Long-range coupling through r
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
def dynamics(
|
|
91
|
+
self,
|
|
92
|
+
t: float,
|
|
93
|
+
state: jnp.ndarray,
|
|
94
|
+
params: Bunch,
|
|
95
|
+
coupling: Bunch,
|
|
96
|
+
external: Bunch,
|
|
97
|
+
) -> Tuple[jnp.ndarray, jnp.ndarray]:
|
|
98
|
+
"""Compute Coombes-Byrne 2D dynamics.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
t : float
|
|
103
|
+
Current time
|
|
104
|
+
state : jnp.ndarray
|
|
105
|
+
Current state with shape ``[2, n_nodes]`` containing ``(r, V)``
|
|
106
|
+
params : Bunch
|
|
107
|
+
Model parameters
|
|
108
|
+
coupling : Bunch
|
|
109
|
+
Coupling inputs with attributes:
|
|
110
|
+
|
|
111
|
+
- ``.instant[0]``: local r-coupling
|
|
112
|
+
- ``.delayed[0]``: long-range r-coupling
|
|
113
|
+
external : Bunch
|
|
114
|
+
External inputs (currently unused)
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
derivatives : jnp.ndarray
|
|
119
|
+
State derivatives with shape ``[2, n_nodes]``
|
|
120
|
+
auxiliaries : jnp.ndarray
|
|
121
|
+
Auxiliary variables with shape ``[1, n_nodes]`` containing synaptic conductance g
|
|
122
|
+
"""
|
|
123
|
+
# Unpack state variables
|
|
124
|
+
r = state[0] # Average firing rate
|
|
125
|
+
V = state[1] # Average membrane potential
|
|
126
|
+
|
|
127
|
+
# Unpack coupling
|
|
128
|
+
c_instant = coupling.instant[0] # Local coupling
|
|
129
|
+
c_delayed = coupling.delayed[0] # Long-range coupling
|
|
130
|
+
|
|
131
|
+
# Total coupling (enters V equation)
|
|
132
|
+
coupling_total = c_instant + c_delayed
|
|
133
|
+
|
|
134
|
+
# Synaptic conductance (proportional to firing rate)
|
|
135
|
+
g = params.k * jnp.pi * r
|
|
136
|
+
|
|
137
|
+
# Mean field dynamics
|
|
138
|
+
# Firing rate dynamics (with quadratic damping from conductance)
|
|
139
|
+
dr_dt = params.Delta / jnp.pi + 2.0 * V * r - g * r**2
|
|
140
|
+
|
|
141
|
+
# Membrane potential dynamics (with conductance-based interaction)
|
|
142
|
+
dV_dt = (
|
|
143
|
+
V**2
|
|
144
|
+
- (jnp.pi * r) ** 2
|
|
145
|
+
+ params.eta
|
|
146
|
+
+ (params.v_syn - V) * g
|
|
147
|
+
+ coupling_total
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Package results
|
|
151
|
+
derivatives = jnp.array([dr_dt, dV_dt])
|
|
152
|
+
auxiliaries = jnp.array([g])
|
|
153
|
+
|
|
154
|
+
return derivatives, auxiliaries
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Epileptor model for seizure dynamics.
|
|
2
|
+
|
|
3
|
+
The Hindmarsh-Rose-Jirsa Epileptor is a composite neural mass model with six
|
|
4
|
+
state variables, crafted to capture the phenomenology of epileptic seizures
|
|
5
|
+
including transitions between interictal and ictal states.
|
|
6
|
+
|
|
7
|
+
References:
|
|
8
|
+
- Jirsa et al. (2014). On the nature of seizure dynamics. Brain, 137(8),
|
|
9
|
+
2210-2230.
|
|
10
|
+
- Proix et al. (2014). Permittivity coupling across brain regions determines
|
|
11
|
+
seizure recruitment in partial epilepsy. Journal of Neuroscience, 34(45),
|
|
12
|
+
15009-15021.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import jax.numpy as jnp
|
|
16
|
+
|
|
17
|
+
from ...core.bunch import Bunch
|
|
18
|
+
from ..base import AbstractDynamics
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Epileptor(AbstractDynamics):
|
|
22
|
+
"""Epileptor model for epileptic seizure dynamics.
|
|
23
|
+
|
|
24
|
+
Six-dimensional model with two coupled populations operating on different time
|
|
25
|
+
scales, designed to reproduce transitions between interictal (between seizures)
|
|
26
|
+
and ictal (during seizure) states.
|
|
27
|
+
|
|
28
|
+
Notes
|
|
29
|
+
-----
|
|
30
|
+
The model consists of:
|
|
31
|
+
|
|
32
|
+
- **Population 1** (x1, y1, z): Fast time scale, represents rapid ictal activity
|
|
33
|
+
- **Population 2** (x2, y2): Ultra-slow time scale, controls interictal background
|
|
34
|
+
- **Filter variable** g: Low-pass filtered version of x1
|
|
35
|
+
|
|
36
|
+
**State equations:**
|
|
37
|
+
|
|
38
|
+
$$
|
|
39
|
+
\\begin{aligned}
|
|
40
|
+
\\frac{dx_1}{dt} &= t_t (y_1 - z + I_{\\text{ext}} + K_{vf} c_{\\text{pop1}} + f_1(x_1,x_2) x_1) \\\\
|
|
41
|
+
\\frac{dy_1}{dt} &= t_t (c - d x_1^2 - y_1) \\\\
|
|
42
|
+
\\frac{dz}{dt} &= t_t r (h(x_1,z) - z + K_s c_{\\text{pop1}}) \\\\
|
|
43
|
+
\\frac{dx_2}{dt} &= t_t (-y_2 + x_2 - x_2^3 + I_{\\text{ext2}} + bb \\cdot g - 0.3(z-3.5) + K_f c_{\\text{pop2}}) \\\\
|
|
44
|
+
\\frac{dy_2}{dt} &= t_t \\frac{-y_2 + f_2(x_2)}{\\tau} \\\\
|
|
45
|
+
\\frac{dg}{dt} &= t_t (-0.01(g - 0.1 x_1))
|
|
46
|
+
\\end{aligned}
|
|
47
|
+
$$
|
|
48
|
+
|
|
49
|
+
where $f_1$, $f_2$, and $h$ are piecewise nonlinear functions modeling different
|
|
50
|
+
dynamical regimes.
|
|
51
|
+
|
|
52
|
+
**Key parameters:**
|
|
53
|
+
|
|
54
|
+
- $x_0$: Epileptogenicity parameter (controls seizure threshold)
|
|
55
|
+
- $K_{vf}, K_f, K_s$: Coupling strengths at different time scales
|
|
56
|
+
- ``modification``: If True, uses nonlinear (sigmoidal) permittivity
|
|
57
|
+
|
|
58
|
+
Attributes
|
|
59
|
+
----------
|
|
60
|
+
STATE_NAMES : tuple of str
|
|
61
|
+
State variables: ``('x1', 'y1', 'z', 'x2', 'y2', 'g')``
|
|
62
|
+
INITIAL_STATE : tuple of float
|
|
63
|
+
Default initial conditions: ``(-1.5, -10.0, 3.5, -1.0, 0.0, 0.0)``
|
|
64
|
+
COUPLING_INPUTS : dict
|
|
65
|
+
Coupling specification: ``{'instant': 2, 'delayed': 2}``
|
|
66
|
+
Components [0] couple to population 1 (fast), [1] to population 2 (slow)
|
|
67
|
+
DEFAULT_PARAMS : Bunch
|
|
68
|
+
Standard Epileptor parameters from Jirsa et al. 2014
|
|
69
|
+
|
|
70
|
+
References
|
|
71
|
+
----------
|
|
72
|
+
Jirsa et al. (2014). On the nature of seizure dynamics. Brain, 137(8), 2210-2230.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
STATE_NAMES = ("x1", "y1", "z", "x2", "y2", "g")
|
|
76
|
+
INITIAL_STATE = (-1.5, -10.0, 3.5, -1.0, 0.0, 0.0)
|
|
77
|
+
|
|
78
|
+
DEFAULT_PARAMS = Bunch(
|
|
79
|
+
# Population 1 parameters
|
|
80
|
+
a=1.0, # Cubic term coefficient in x1
|
|
81
|
+
b=3.0, # Squared term coefficient in x1
|
|
82
|
+
c=1.0, # Additive coefficient in y1
|
|
83
|
+
d=5.0, # Squared term coefficient in y1
|
|
84
|
+
r=0.00035, # Temporal scaling in z (1/tau_0)
|
|
85
|
+
s=4.0, # Linear coefficient in z
|
|
86
|
+
x0=-1.6, # Epileptogenicity parameter
|
|
87
|
+
Iext=3.1, # External input to population 1
|
|
88
|
+
slope=0.0, # Linear coefficient in x1
|
|
89
|
+
# Population 2 parameters
|
|
90
|
+
Iext2=0.45, # External input to population 2
|
|
91
|
+
tau=10.0, # Temporal scaling in y2
|
|
92
|
+
aa=6.0, # Linear coefficient in y2
|
|
93
|
+
bb=2.0, # Coupling coefficient from g to x2
|
|
94
|
+
# Coupling parameters
|
|
95
|
+
Kvf=0.0, # Very fast time scale coupling (to x1)
|
|
96
|
+
Kf=0.0, # Fast time scale coupling (to x2)
|
|
97
|
+
Ks=0.0, # Slow time scale coupling (to z, permittivity)
|
|
98
|
+
# Global parameters
|
|
99
|
+
tt=1.0, # Global time scaling
|
|
100
|
+
modification=False, # Use nonlinear permittivity influence on z
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
COUPLING_INPUTS = {
|
|
104
|
+
"instant": 2, # Local coupling [pop1, pop2]
|
|
105
|
+
"delayed": 2, # Long-range coupling [pop1, pop2]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
def dynamics(
|
|
109
|
+
self,
|
|
110
|
+
t: float,
|
|
111
|
+
state: jnp.ndarray,
|
|
112
|
+
params: Bunch,
|
|
113
|
+
coupling: Bunch,
|
|
114
|
+
external: Bunch,
|
|
115
|
+
) -> jnp.ndarray:
|
|
116
|
+
"""Compute Epileptor dynamics.
|
|
117
|
+
|
|
118
|
+
Parameters
|
|
119
|
+
----------
|
|
120
|
+
t : float
|
|
121
|
+
Current time
|
|
122
|
+
state : jnp.ndarray
|
|
123
|
+
Current state with shape ``[6, n_nodes]`` containing ``(x1, y1, z, x2, y2, g)``
|
|
124
|
+
params : Bunch
|
|
125
|
+
Model parameters
|
|
126
|
+
coupling : Bunch
|
|
127
|
+
Coupling inputs with attributes:
|
|
128
|
+
|
|
129
|
+
- ``.instant[0], .delayed[0]``: population 1 coupling
|
|
130
|
+
- ``.instant[1], .delayed[1]``: population 2 coupling
|
|
131
|
+
external : Bunch
|
|
132
|
+
External inputs (currently unused)
|
|
133
|
+
|
|
134
|
+
Returns
|
|
135
|
+
-------
|
|
136
|
+
derivatives : jnp.ndarray
|
|
137
|
+
State derivatives with shape ``[6, n_nodes]``
|
|
138
|
+
"""
|
|
139
|
+
# Unpack state variables
|
|
140
|
+
x1 = state[0] # Fast population membrane potential
|
|
141
|
+
y1 = state[1] # Fast population recovery
|
|
142
|
+
z = state[2] # Slow permittivity variable
|
|
143
|
+
x2 = state[3] # Slow population membrane potential
|
|
144
|
+
y2 = state[4] # Slow population recovery
|
|
145
|
+
g = state[5] # Low-pass filter of x1
|
|
146
|
+
|
|
147
|
+
# Unpack coupling
|
|
148
|
+
c_pop1 = coupling.instant[0] + coupling.delayed[0] # Population 1 coupling
|
|
149
|
+
c_pop2 = coupling.instant[1] + coupling.delayed[1] # Population 2 coupling
|
|
150
|
+
|
|
151
|
+
# Population 1 dynamics (fast time scale)
|
|
152
|
+
# Piecewise function f1(x1, x2)
|
|
153
|
+
f1_if_neg = -params.a * x1**2 + params.b * x1
|
|
154
|
+
f1_if_pos = params.slope - x2 + 0.6 * (z - 4.0) ** 2
|
|
155
|
+
f1 = jnp.where(x1 < 0.0, f1_if_neg, f1_if_pos)
|
|
156
|
+
|
|
157
|
+
dx1_dt = params.tt * (y1 - z + params.Iext + params.Kvf * c_pop1 + f1 * x1)
|
|
158
|
+
|
|
159
|
+
dy1_dt = params.tt * (params.c - params.d * x1**2 - y1)
|
|
160
|
+
|
|
161
|
+
# Energy/permittivity variable (slow time scale)
|
|
162
|
+
# Piecewise nonlinearity in z dynamics
|
|
163
|
+
z_nonlin_if_neg = -0.1 * z**7
|
|
164
|
+
z_nonlin_if_pos = 0.0
|
|
165
|
+
z_nonlin = jnp.where(z < 0.0, z_nonlin_if_neg, z_nonlin_if_pos)
|
|
166
|
+
|
|
167
|
+
if params.modification:
|
|
168
|
+
# Nonlinear (sigmoidal) permittivity influence
|
|
169
|
+
h = params.x0 + 3.0 / (1.0 + jnp.exp(-(x1 + 0.5) / 0.1))
|
|
170
|
+
else:
|
|
171
|
+
# Linear permittivity influence
|
|
172
|
+
h = 4.0 * (x1 - params.x0) + z_nonlin
|
|
173
|
+
|
|
174
|
+
dz_dt = params.tt * params.r * (h - z + params.Ks * c_pop1)
|
|
175
|
+
|
|
176
|
+
# Population 2 dynamics (ultra-slow time scale)
|
|
177
|
+
dx2_dt = params.tt * (
|
|
178
|
+
-y2
|
|
179
|
+
+ x2
|
|
180
|
+
- x2**3
|
|
181
|
+
+ params.Iext2
|
|
182
|
+
+ params.bb * g
|
|
183
|
+
- 0.3 * (z - 3.5)
|
|
184
|
+
+ params.Kf * c_pop2
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Piecewise function f2(x2)
|
|
188
|
+
f2_if_neg = 0.0
|
|
189
|
+
f2_if_pos = params.aa * (x2 + 0.25)
|
|
190
|
+
f2 = jnp.where(x2 < -0.25, f2_if_neg, f2_if_pos)
|
|
191
|
+
|
|
192
|
+
dy2_dt = params.tt * ((-y2 + f2) / params.tau)
|
|
193
|
+
|
|
194
|
+
# Low-pass filter
|
|
195
|
+
dg_dt = params.tt * (-0.01 * (g - 0.1 * x1))
|
|
196
|
+
|
|
197
|
+
# Package results
|
|
198
|
+
derivatives = jnp.array([dx1_dt, dy1_dt, dz_dt, dx2_dt, dy2_dt, dg_dt])
|
|
199
|
+
|
|
200
|
+
return derivatives
|