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,202 @@
1
+ """TVB coupling implementations."""
2
+
3
+ import jax.numpy as jnp
4
+
5
+ from ..core.bunch import Bunch
6
+ from .base import DelayedCoupling, InstantaneousCoupling
7
+
8
+
9
+ class SigmoidalJansenRit(InstantaneousCoupling):
10
+ """Sigmoidal Jansen-Rit coupling function.
11
+
12
+ Implements the coupling function used in Jansen and Rit neural mass models.
13
+ Applies a sigmoidal transformation to the difference between two state variables
14
+ (typically y1 and y2) before network summation, then scales the result.
15
+
16
+ Notes
17
+ -----
18
+ The coupling implements:
19
+
20
+ $$c_i = G \\cdot \\sum_{j} w_{ij} \\sigma(y1_j - y2_j)$$
21
+
22
+ where the sigmoid function is defined as:
23
+
24
+ $$\\sigma(x) = c_{\\text{min}} + \\frac{c_{\\text{max}} - c_{\\text{min}}}{1 + e^{r(m - x)}}$$
25
+
26
+ with $m$ being the midpoint and $r$ the steepness.
27
+
28
+ Parameters
29
+ ----------
30
+ incoming_states : tuple of str
31
+ Tuple of two state names, e.g., ``('y1', 'y2')`` (required)
32
+ local_states : str or list of str, optional
33
+ State name(s) from current node (default: ``[]``)
34
+
35
+ Attributes
36
+ ----------
37
+ N_OUTPUT_STATES : int
38
+ Number of output coupling states: ``1``
39
+ DEFAULT_PARAMS : Bunch
40
+ Default parameters: ``G=1.0`` (global coupling strength), ``cmin=0.0`` (sigmoid minimum),
41
+ ``cmax=0.005`` (sigmoid maximum), ``midpoint=6.0`` (sigmoid center), ``r=0.56`` (sigmoid steepness)
42
+
43
+ Examples
44
+ --------
45
+ >>> # Typical Jansen-Rit coupling
46
+ >>> coupling = SigmoidalJansenRit(
47
+ ... incoming_states=('y1', 'y2'),
48
+ ... G=1.0,
49
+ ... cmax=0.005
50
+ ... )
51
+ """
52
+
53
+ N_OUTPUT_STATES = 1
54
+ DEFAULT_PARAMS = Bunch(
55
+ G=1.0,
56
+ cmin=0.0,
57
+ cmax=0.005, # 2 * 0.0025 from TVB default
58
+ midpoint=6.0,
59
+ r=0.56,
60
+ )
61
+
62
+ def pre(
63
+ self, incoming_states: jnp.ndarray, local_states: jnp.ndarray, params: Bunch
64
+ ) -> jnp.ndarray:
65
+ """Apply sigmoidal transformation to state difference.
66
+
67
+ Args:
68
+ incoming_states: States from connected nodes in per-edge format
69
+ [n_incoming, n_nodes_target, n_nodes_source]
70
+ Expected: n_incoming=2 (y1 and y2)
71
+ local_states: Local node states (unused in this implementation)
72
+ params: Coupling parameters (cmin, cmax, midpoint, r)
73
+
74
+ Returns:
75
+ Transformed states after sigmoidal coupling
76
+ [1, n_nodes_target, n_nodes_source]
77
+ """
78
+ # Extract first two state variables: y1 and y2
79
+ # incoming_states[0] = y1, incoming_states[1] = y2
80
+ # Each has shape [n_nodes_target, n_nodes_source]
81
+ state_diff = incoming_states[0] - incoming_states[1]
82
+
83
+ # Apply sigmoidal transformation
84
+ exp_term = jnp.exp(params.r * (params.midpoint - state_diff))
85
+ coupling_term = params.cmin + (params.cmax - params.cmin) / (1.0 + exp_term)
86
+
87
+ # Return as [1, n_nodes_target, n_nodes_source] for matrix multiplication
88
+ return coupling_term[jnp.newaxis, :, :]
89
+
90
+ def post(
91
+ self, summed_inputs: jnp.ndarray, local_states: jnp.ndarray, params: Bunch
92
+ ) -> jnp.ndarray:
93
+ """Scale summed coupling inputs.
94
+
95
+ Args:
96
+ summed_inputs: Sum of coupling inputs after network summation
97
+ [1, n_nodes]
98
+ local_states: Local node states (unused)
99
+ params: Coupling parameters (G)
100
+
101
+ Returns:
102
+ Scaled coupling output [1, n_nodes]
103
+ """
104
+ return params.G * summed_inputs
105
+
106
+
107
+ class DelayedSigmoidalJansenRit(DelayedCoupling):
108
+ """Sigmoidal Jansen-Rit coupling with transmission delays.
109
+
110
+ Implements the delayed coupling function used in Jansen and Rit neural mass models.
111
+ Applies a sigmoidal transformation to the difference between two delayed state variables
112
+ (typically y1 and y2) before network summation, then scales the result.
113
+
114
+ Notes
115
+ -----
116
+ The coupling implements:
117
+
118
+ $$c_i(t) = G \\cdot \\sum_{j} w_{ij} \\sigma(y1_j(t - \\tau_{ij}) - y2_j(t - \\tau_{ij}))$$
119
+
120
+ where $\\tau_{ij}$ are the transmission delays and the sigmoid function is defined as:
121
+
122
+ $$\\sigma(x) = c_{\\text{min}} + \\frac{c_{\\text{max}} - c_{\\text{min}}}{1 + e^{r(m - x)}}$$
123
+
124
+ with $m$ being the midpoint and $r$ the steepness.
125
+
126
+ Parameters
127
+ ----------
128
+ incoming_states : tuple of str
129
+ Tuple of two state names, e.g., ``('y1', 'y2')`` (required)
130
+ local_states : str or list of str, optional
131
+ State name(s) from current node (default: ``[]``)
132
+
133
+ Attributes
134
+ ----------
135
+ N_OUTPUT_STATES : int
136
+ Number of output coupling states: ``1``
137
+ DEFAULT_PARAMS : Bunch
138
+ Default parameters: ``G=1.0`` (global coupling strength), ``cmin=0.0`` (sigmoid minimum),
139
+ ``cmax=0.005`` (sigmoid maximum), ``midpoint=6.0`` (sigmoid center), ``r=0.56`` (sigmoid steepness)
140
+
141
+ Examples
142
+ --------
143
+ >>> # Typical delayed Jansen-Rit coupling
144
+ >>> coupling = DelayedSigmoidalJansenRit(
145
+ ... incoming_states=('y1', 'y2'),
146
+ ... G=1.0,
147
+ ... cmax=0.005
148
+ ... )
149
+ """
150
+
151
+ N_OUTPUT_STATES = 1
152
+ DEFAULT_PARAMS = Bunch(
153
+ G=1.0,
154
+ cmin=0.0,
155
+ cmax=0.005, # 2 * 0.0025 from TVB default
156
+ midpoint=6.0,
157
+ r=0.56,
158
+ )
159
+
160
+ def pre(
161
+ self, incoming_states: jnp.ndarray, local_states: jnp.ndarray, params: Bunch
162
+ ) -> jnp.ndarray:
163
+ """Apply sigmoidal transformation to state difference.
164
+
165
+ Args:
166
+ incoming_states: States from connected nodes in per-edge format
167
+ [n_incoming, n_nodes_target, n_nodes_source]
168
+ Expected: n_incoming=2 (y1 and y2)
169
+ local_states: Local node states (unused in this implementation)
170
+ params: Coupling parameters (cmin, cmax, midpoint, r)
171
+
172
+ Returns:
173
+ Transformed states after sigmoidal coupling
174
+ [1, n_nodes_target, n_nodes_source]
175
+ """
176
+ # Extract first two state variables: y1 and y2
177
+ # incoming_states[0] = y1, incoming_states[1] = y2
178
+ # Each has shape [n_nodes_target, n_nodes_source]
179
+ state_diff = incoming_states[0] - incoming_states[1]
180
+
181
+ # Apply sigmoidal transformation
182
+ exp_term = jnp.exp(params.r * (params.midpoint - state_diff))
183
+ coupling_term = params.cmin + (params.cmax - params.cmin) / (1.0 + exp_term)
184
+
185
+ # Return as [1, n_nodes_target, n_nodes_source] for matrix multiplication
186
+ return coupling_term[jnp.newaxis, :, :]
187
+
188
+ def post(
189
+ self, summed_inputs: jnp.ndarray, local_states: jnp.ndarray, params: Bunch
190
+ ) -> jnp.ndarray:
191
+ """Scale summed coupling inputs.
192
+
193
+ Args:
194
+ summed_inputs: Sum of coupling inputs after network summation
195
+ [1, n_nodes]
196
+ local_states: Local node states (unused)
197
+ params: Coupling parameters (G)
198
+
199
+ Returns:
200
+ Scaled coupling output [1, n_nodes]
201
+ """
202
+ return params.G * summed_inputs
@@ -0,0 +1,7 @@
1
+ """Neural dynamics models."""
2
+
3
+ from .base import AbstractDynamics
4
+ from .lorenz import Lorenz
5
+ from .tvb import JansenRit, ReducedWongWang
6
+
7
+ __all__ = ["AbstractDynamics", "Lorenz", "ReducedWongWang", "JansenRit"]