tvboptim 0.2.9__tar.gz → 0.2.10__tar.gz

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 (87) hide show
  1. {tvboptim-0.2.9/src/tvboptim.egg-info → tvboptim-0.2.10}/PKG-INFO +2 -1
  2. {tvboptim-0.2.9 → tvboptim-0.2.10}/pyproject.toml +3 -1
  3. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/external_input/base.py +69 -0
  4. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/external_input/data.py +19 -0
  5. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/observations/tvb_monitors/__init__.py +3 -1
  6. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/observations/tvb_monitors/bold.py +195 -23
  7. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/types/parameter.py +5 -1
  8. {tvboptim-0.2.9 → tvboptim-0.2.10/src/tvboptim.egg-info}/PKG-INFO +2 -1
  9. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim.egg-info/requires.txt +1 -0
  10. {tvboptim-0.2.9 → tvboptim-0.2.10}/LICENSE +0 -0
  11. {tvboptim-0.2.9 → tvboptim-0.2.10}/README.md +0 -0
  12. {tvboptim-0.2.9 → tvboptim-0.2.10}/setup.cfg +0 -0
  13. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/__init__.py +0 -0
  14. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/__init__.py +0 -0
  15. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/connectivity/dTOR/data.npz +0 -0
  16. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/connectivity/dk_average/data.npz +0 -0
  17. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/functional/dk_average/data.npz +0 -0
  18. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/loaders.py +0 -0
  19. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/plotting/dk_average/aparc+aseg-mni_09c.nii.gz +0 -0
  20. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/plotting/dk_average/fs_default.txt +0 -0
  21. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/data/plotting/dk_average/fs_default_freesurfer_idx.csv +0 -0
  22. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/execution.py +0 -0
  23. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/__init__.py +0 -0
  24. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/__init__.py +0 -0
  25. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/analysis/__init__.py +0 -0
  26. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/analysis/lyapunov.py +0 -0
  27. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/core/__init__.py +0 -0
  28. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/core/bunch.py +0 -0
  29. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/core/network.py +0 -0
  30. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/coupling/__init__.py +0 -0
  31. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/coupling/base.py +0 -0
  32. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/coupling/linear.py +0 -0
  33. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/coupling/subspace.py +0 -0
  34. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/coupling/tvb.py +0 -0
  35. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/__init__.py +0 -0
  36. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/base.py +0 -0
  37. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/lorenz.py +0 -0
  38. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/__init__.py +0 -0
  39. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/coombes_byrne.py +0 -0
  40. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/epileptor.py +0 -0
  41. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/generic_2d_oscillator.py +0 -0
  42. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/jansen_rit.py +0 -0
  43. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/kuramoto.py +0 -0
  44. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/larter_breakspear.py +0 -0
  45. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/linear.py +0 -0
  46. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/montbrio_pazo_roxin.py +0 -0
  47. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/sup_hopf.py +0 -0
  48. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wilson_cowan.py +0 -0
  49. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang.py +0 -0
  50. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang_exc_inh.py +0 -0
  51. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/external_input/__init__.py +0 -0
  52. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/external_input/parametric.py +0 -0
  53. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/graph/__init__.py +0 -0
  54. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/graph/base.py +0 -0
  55. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/graph/sparse.py +0 -0
  56. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/graph/utils.py +0 -0
  57. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/noise/__init__.py +0 -0
  58. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/noise/base.py +0 -0
  59. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/noise/gaussian.py +0 -0
  60. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/result.py +0 -0
  61. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/solve.py +0 -0
  62. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/solvers/__init__.py +0 -0
  63. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/solvers/base.py +0 -0
  64. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/solvers/diffrax.py +0 -0
  65. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/solvers/native.py +0 -0
  66. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/utils/__init__.py +0 -0
  67. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/utils/history.py +0 -0
  68. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/experimental/network_dynamics/utils/printer.py +0 -0
  69. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/observations/__init__.py +0 -0
  70. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/observations/observation.py +0 -0
  71. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/observations/tvb_monitors/downsampling.py +0 -0
  72. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/optim/__init__.py +0 -0
  73. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/optim/callbacks.py +0 -0
  74. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/optim/optax.py +0 -0
  75. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/tvbo/__init__.py +0 -0
  76. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/tvbo/prepare_experiment.py +0 -0
  77. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/types/__init__.py +0 -0
  78. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/types/spaces.py +0 -0
  79. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/types/stateutils.py +0 -0
  80. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/utils/__init__.py +0 -0
  81. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/utils/caching.py +0 -0
  82. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim/utils/utils.py +0 -0
  83. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim.egg-info/SOURCES.txt +0 -0
  84. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim.egg-info/dependency_links.txt +0 -0
  85. {tvboptim-0.2.9 → tvboptim-0.2.10}/src/tvboptim.egg-info/top_level.txt +0 -0
  86. {tvboptim-0.2.9 → tvboptim-0.2.10}/tests/test_execution.py +0 -0
  87. {tvboptim-0.2.9 → tvboptim-0.2.10}/tests/test_optax_optimizer_toy.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tvboptim
3
- Version: 0.2.9
3
+ Version: 0.2.10
4
4
  Summary: Optimization tools for The Virtual Brain
5
5
  Author-email: Marius Pille <marius.pille@bih-charite.de>
6
6
  License-Expression: EUPL-1.2
@@ -43,6 +43,7 @@ Requires-Dist: tvb-library; extra == "docs"
43
43
  Requires-Dist: jupyter-cache>=1.0.1; extra == "docs"
44
44
  Requires-Dist: nibabel; extra == "docs"
45
45
  Requires-Dist: nilearn; extra == "docs"
46
+ Requires-Dist: pymoo; extra == "docs"
46
47
  Requires-Dist: griffe<2.0.0; extra == "docs"
47
48
  Dynamic: license-file
48
49
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tvboptim"
7
- version = "0.2.9"
7
+ version = "0.2.10"
8
8
  description = "Optimization tools for The Virtual Brain"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -76,6 +76,7 @@ docs = [
76
76
  "jupyter-cache>=1.0.1",
77
77
  "nibabel",
78
78
  "nilearn",
79
+ "pymoo",
79
80
  "griffe<2.0.0"
80
81
  ]
81
82
 
@@ -95,6 +96,7 @@ docs = [
95
96
  "jupyter-cache>=1.0.1",
96
97
  "nibabel",
97
98
  "nilearn",
99
+ "pymoo",
98
100
  "griffe<2.0.0"
99
101
  ]
100
102
 
@@ -150,3 +150,72 @@ class AbstractExternalInput(ABC):
150
150
  """String representation of external input."""
151
151
  param_str = ", ".join(f"{k}={v}" for k, v in self.params.items())
152
152
  return f"{self.__class__.__name__}({param_str})"
153
+
154
+ def _plot_prepare(self, n_nodes: int, dt: float) -> Tuple[Bunch, Bunch]:
155
+ """Lightweight prepare for the plot path (no network required).
156
+
157
+ Subclasses that need precomputed data (e.g. interpolators) override this.
158
+ Default returns empty Bunches, which works for all stateless parametric
159
+ inputs.
160
+ """
161
+ return Bunch(), Bunch()
162
+
163
+ def plot(
164
+ self,
165
+ t0: float = 0.0,
166
+ t1: float = 1.0,
167
+ *,
168
+ dt: float = None,
169
+ n_nodes: int = 1,
170
+ ax=None,
171
+ ):
172
+ """Plot the input signal over [t0, t1] for quick inspection.
173
+
174
+ Calls ``compute`` directly with a zero state and empty input_data /
175
+ input_state (or whatever ``_plot_prepare`` returns). State-dependent or
176
+ stateful inputs will therefore show open-loop behavior only.
177
+
178
+ Args:
179
+ t0, t1: Time interval to plot.
180
+ dt: Sampling step. Defaults to (t1 - t0) / 500.
181
+ n_nodes: Number of nodes to render (lets spatial patterns show up).
182
+ ax: Matplotlib axis (or array of axes for multi-dim outputs). Created
183
+ if None.
184
+
185
+ Returns:
186
+ The matplotlib axis (or array of axes) used for plotting.
187
+ """
188
+ import matplotlib.pyplot as plt
189
+
190
+ if dt is None:
191
+ dt = (t1 - t0) / 500.0
192
+
193
+ input_data, input_state = self._plot_prepare(n_nodes, dt)
194
+ state = jnp.zeros((1, n_nodes))
195
+
196
+ ts = jnp.arange(t0, t1, dt)
197
+ signals = jnp.stack(
198
+ [
199
+ self.compute(float(t), state, input_data, input_state, self.params)
200
+ for t in ts
201
+ ]
202
+ ) # [T, N_OUTPUT_DIMS, n_nodes]
203
+
204
+ n_dims = signals.shape[1]
205
+ if ax is None:
206
+ fig, ax = plt.subplots(n_dims, 1, sharex=True, squeeze=False)
207
+ ax = ax[:, 0]
208
+ else:
209
+ ax = ax if hasattr(ax, "__len__") else [ax]
210
+
211
+ show_legend = n_nodes <= 8
212
+ for d in range(n_dims):
213
+ for i in range(n_nodes):
214
+ ax[d].plot(ts, signals[:, d, i], label=f"node {i}" if show_legend else None)
215
+ ax[d].set_ylabel(f"input[{d}]" if n_dims > 1 else "input")
216
+ if show_legend and n_nodes > 1:
217
+ ax[d].legend(loc="best", fontsize="small")
218
+ ax[-1].set_xlabel("time")
219
+ ax[0].set_title(repr(self))
220
+
221
+ return ax if n_dims > 1 else ax[0]
@@ -187,6 +187,25 @@ class DataInput(AbstractExternalInput):
187
187
  # [n_times, n_dims, n_nodes] → [n_dims, n_nodes]
188
188
  return interpolated
189
189
 
190
+ def _plot_prepare(self, n_nodes, dt):
191
+ """Build interpolator for the plot path without a network."""
192
+ times = self.params.times
193
+ data = self.params.data
194
+ interp_type = self.params.interpolation_type
195
+
196
+ if interp_type == "linear":
197
+ interpolator = diffrax.LinearInterpolation(ts=times, ys=data)
198
+ else:
199
+ coeffs = diffrax.backward_hermite_coefficients(ts=times, ys=data)
200
+ interpolator = diffrax.CubicInterpolation(ts=times, coeffs=coeffs)
201
+
202
+ input_data = Bunch(
203
+ interpolator=interpolator,
204
+ n_nodes=n_nodes,
205
+ data_shape=tuple(data.shape),
206
+ )
207
+ return input_data, Bunch()
208
+
190
209
  def update_state(
191
210
  self, input_data: Bunch, input_state: Bunch, new_state: jnp.ndarray
192
211
  ) -> Bunch:
@@ -1,6 +1,7 @@
1
1
  from .bold import (
2
2
  BalloonWindkesselBold,
3
3
  Bold,
4
+ FirstOrderVolterraHRFKernel,
4
5
  HRFBold,
5
6
  HRFKernel,
6
7
  LotkaVolterraHRFKernel,
@@ -13,8 +14,9 @@ __all__ = [
13
14
  "TemporalAverage",
14
15
  "HRFBold",
15
16
  "BalloonWindkesselBold",
16
- "LotkaVolterraHRFKernel",
17
+ "FirstOrderVolterraHRFKernel",
17
18
  "HRFKernel",
18
19
  # Deprecated aliases
19
20
  "Bold",
21
+ "LotkaVolterraHRFKernel",
20
22
  ]
@@ -37,14 +37,20 @@ class HRFKernel(eqx.Module):
37
37
  duration: Duration of kernel support in milliseconds
38
38
  """
39
39
 
40
- duration: float
40
+ duration: eqx.AbstractVar[float]
41
41
 
42
42
  def __call__(self, t: jax.Array, downsample_dt: float) -> jax.Array:
43
43
  """Compute kernel values at time points.
44
44
 
45
45
  Args:
46
46
  t: Time points at which to evaluate the kernel
47
- downsample_dt: Time step of downsampled signal (for internal use)
47
+ downsample_dt: Step size of the convolution grid `t` is sampled on.
48
+ Closed-form kernels (e.g. FirstOrderVolterraHRFKernel) are exact
49
+ functions of `t` and ignore this. It is part of the interface
50
+ for grid-dependent kernels not yet implemented — e.g. an
51
+ empirical/tabulated HRF that must resample itself onto the
52
+ convolution grid, or a kernel that scales by the sample spacing
53
+ to approximate the convolution integral.
48
54
 
49
55
  Returns:
50
56
  Kernel values at the specified time points
@@ -81,10 +87,16 @@ class HRFKernel(eqx.Module):
81
87
  return ax
82
88
 
83
89
 
84
- class LotkaVolterraHRFKernel(HRFKernel):
85
- """Canonical hemodynamic response function based on Lotka-Volterra dynamics.
90
+ class FirstOrderVolterraHRFKernel(HRFKernel):
91
+ """First-order Volterra kernel of the hemodynamic system.
86
92
 
87
- This implements the oscillatory HRF kernel used in standard BOLD signal modeling.
93
+ This is the canonical damped-oscillator HRF used in standard BOLD signal
94
+ modeling — the first-order Volterra kernel of the Balloon/Windkessel
95
+ hemodynamics (Friston et al. 2000). Ported from TVB's ``FirstOrderVolterra``
96
+ equation.
97
+
98
+ Despite the shared name of the mathematician Vito Volterra, this is
99
+ unrelated to Lotka-Volterra (predator-prey) dynamics.
88
100
 
89
101
  Attributes:
90
102
  tau_s: Signal decay time constant in seconds (default: 0.8 s)
@@ -93,8 +105,15 @@ class LotkaVolterraHRFKernel(HRFKernel):
93
105
  duration: Kernel support duration in ms (default: 20,000 ms = 20 s)
94
106
 
95
107
  Note:
96
- The tau parameters are in seconds (not ms) to match the standard HRF formulation.
97
- Time input to __call__ is expected in milliseconds and converted internally.
108
+ The tau parameters are in seconds (not ms) to match the standard HRF
109
+ formulation. Time input to __call__ is expected in milliseconds and
110
+ converted internally.
111
+
112
+ This is the *underdamped* solution: the oscillation frequency
113
+ ``omega = sqrt(1/tau_f - 1/(4*tau_s**2))`` is real only when
114
+ ``4*tau_s**2 > tau_f``. The defaults satisfy this. Parameter values that
115
+ violate it make ``omega`` NaN and the whole kernel NaN — the overdamped
116
+ regime (which would need ``sinh`` instead of ``sin``) is not supported.
98
117
  """
99
118
 
100
119
  tau_s: float = 0.8 # seconds
@@ -102,22 +121,8 @@ class LotkaVolterraHRFKernel(HRFKernel):
102
121
  scaling: float = 1.0 / 3.0
103
122
  duration: float = 20_000.0 # ms (20 seconds)
104
123
 
105
- def __init__(self, tau_s=0.8, tau_f=0.4, scaling=1.0 / 3.0, duration=20_000.0):
106
- """Initialize Lotka-Volterra HRF kernel.
107
-
108
- Args:
109
- tau_s: Signal decay time constant in seconds (default: 0.8 s)
110
- tau_f: Feedback time constant in seconds (default: 0.4 s)
111
- scaling: Kernel amplitude scaling factor (default: 1/3)
112
- duration: Kernel support duration in ms (default: 20,000 ms)
113
- """
114
- self.tau_s = tau_s
115
- self.tau_f = tau_f
116
- self.scaling = scaling
117
- self.duration = duration
118
-
119
124
  def __call__(self, t: jax.Array, downsample_dt: float) -> jax.Array:
120
- """Compute Lotka-Volterra HRF kernel.
125
+ """Compute the first-order Volterra HRF kernel.
121
126
 
122
127
  Args:
123
128
  t: Time points in milliseconds at which to evaluate the kernel
@@ -137,6 +142,173 @@ class LotkaVolterraHRFKernel(HRFKernel):
137
142
  / omega
138
143
  )
139
144
 
145
+ class GammaHRFKernel(HRFKernel):
146
+ """
147
+ Gamma HRF kernel, ported from TVBSim's Gamma class.
148
+
149
+ h(t) = ((t/tau)^(n-1) * exp(-(t/tau))) / (tau * (n-1)!)
150
+ normalized and scaled by amplitude factor `a`.
151
+
152
+ Parameters
153
+ ----------
154
+ tau : float
155
+ Exponential time constant in seconds (default: 1.08 s)
156
+ n : float
157
+ Phase delay / shape parameter (default: 3.0)
158
+ a : float
159
+ Amplitude scaling factor after normalization (default: 0.1)
160
+ duration : float
161
+ Kernel support duration in ms (default: 20_000 ms)
162
+
163
+ Reference
164
+ ---------
165
+ Boynton et al. (1996). Linear Systems Analysis of fMRI in Human V1.
166
+ J Neurosci 16: 4207-4221.
167
+ """
168
+
169
+ tau: float = 1.08 # seconds
170
+ n: float = 3.0
171
+ a: float = 0.1
172
+ duration: float = 20_000.0 # ms
173
+
174
+ def __call__(self, t: jax.Array, downsample_dt: float) -> jax.Array:
175
+ # Convert time from ms to seconds for the HRF formula
176
+ t_s = t / 1000.0
177
+
178
+ factorial = math.factorial(int(self.n) - 1)
179
+
180
+ kernel = (
181
+ (t_s / self.tau) ** (self.n - 1)
182
+ * jnp.exp(-(t_s / self.tau))
183
+ ) / (self.tau * factorial)
184
+
185
+ # Replicate TVBSim's normalization and amplitude scaling from evaluate()
186
+ peak = jnp.max(kernel)
187
+ peak = jnp.where(peak > 0, peak, 1.0) # Avoid division by zero
188
+ kernel = kernel / peak
189
+ kernel = kernel * self.a
190
+
191
+ return kernel
192
+
193
+ class DoubleExponentialHRFKernel(HRFKernel):
194
+ """
195
+ A difference of two exponential functions to define a kernel for the bold monitor, ported from TVBSim's DoubleExponential class.
196
+
197
+ h(t) = amp_1*exp(-t/tau_1)*sin(2*pi*f_1*t) - amp_2*exp(-t/tau_2)*sin(2*pi*f_2*t)
198
+ normalized and scaled by amplitude factor `a`.
199
+
200
+ Parameters
201
+ ----------
202
+ tau_1 : float
203
+ Time constant of the first exponential function [s] (default: 7.22)
204
+ tau_2 : float
205
+ Time constant of the second exponential function [s] (default: 7.4)
206
+ f_1 : float
207
+ Frequency of the first sine function [Hz] (default: 0.03)
208
+ f_2 : float
209
+ Frequency of the second sine function [Hz] (default: 0.12)
210
+ amp_1 : float
211
+ Amplitude of the first exponential function (default: 0.1)
212
+ amp_2 : float
213
+ Amplitude of the second exponential function. (default: 0.1)
214
+ a : float
215
+ Amplitude factor after normalization (default: 0.1)
216
+
217
+ Reference
218
+ ---------
219
+ Alex Polonsky, Randolph Blake, Jochen Braun and David J. Heeger
220
+ (2000). Neuronal activity in human primary visual cortex correlates with
221
+ perception during binocular rivalry. Nature Neuroscience 3: 1153-1159
222
+
223
+ """
224
+
225
+ tau_1: float = 7.22
226
+ tau_2: float = 7.4
227
+ f_1: float = 0.03
228
+ f_2: float = 0.12
229
+ amp_1: float = 0.1
230
+ amp_2: float = 0.1
231
+ a: float = 0.1
232
+ duration: float = 40_000.0 # ms
233
+
234
+ def __call__(self, t: jax.Array, downsample_dt: float) -> jax.Array:
235
+ # Convert ms to seconds
236
+ t_s = t / 1000.0
237
+
238
+ kernel = ((self.amp_1 * jnp.exp(-t_s/self.tau_1) * jnp.sin(2 * math.pi * self.f_1 * t_s))
239
+ - (self.amp_2 * jnp.exp(-t_s/self.tau_2) * jnp.sin(2 * math.pi * self.f_2 * t_s))
240
+ )
241
+
242
+ # Replicate TVBSim's normalization + amplitude scaling from evaluate()
243
+ peak = jnp.max(kernel)
244
+ peak = jnp.where(peak > 0, peak, 1.0) # Avoid division by zero
245
+ kernel = kernel / peak
246
+ kernel = kernel * self.a
247
+
248
+ return kernel
249
+
250
+ class MixtureOfGammasHRFKernel(HRFKernel):
251
+ """
252
+ Mixture of two gamma distributions HRF kernel, ported from TVBSim's MixtureOfGammas.
253
+
254
+ hrf(t) = (l*t)^(a_1-1) * exp(-l*t) / Γ(a_1)
255
+ - c * (l*t)^(a_2-1) * exp(-l*t) / Γ(a_2)
256
+
257
+ Parameters
258
+ ----------
259
+ a_1 : float
260
+ Shape parameter of the first gamma pdf (default: 6.0)
261
+ a_2 : float
262
+ Shape parameter of the second gamma pdf (default: 13.0)
263
+ l : float
264
+ Scale parameter / lambda (default: 1.0)
265
+ c : float
266
+ Scaling factor of the second gamma pdf (default: 0.4)
267
+ duration : float
268
+ Kernel support duration [ms] (default: 20_000)
269
+
270
+ Reference
271
+ ---------
272
+ Glover (1999). Deconvolution of Impulse Response in Event-Related BOLD fMRI.
273
+ NeuroImage 9, 416-429.
274
+ """
275
+
276
+ a_1: float = 6.0
277
+ a_2: float = 13.0
278
+ l: float = 1.0
279
+ c: float = 0.4
280
+ duration: float = 20_000.0
281
+
282
+ def __call__(self, t: jax.Array, downsample_dt: float) -> jax.Array:
283
+ t_s = t / 1000.0
284
+
285
+ gamma_a_1 = jsp.special.gamma(self.a_1)
286
+ gamma_a_2 = jsp.special.gamma(self.a_2)
287
+
288
+ return (
289
+ (self.l * t_s) ** (self.a_1 - 1) * jnp.exp(-self.l * t_s) / gamma_a_1
290
+ - self.c
291
+ * (self.l * t_s) ** (self.a_2 - 1)
292
+ * jnp.exp(-self.l * t_s)
293
+ / gamma_a_2
294
+ )
295
+
296
+ def LotkaVolterraHRFKernel(*args, **kwargs):
297
+ """Deprecated: use FirstOrderVolterraHRFKernel.
298
+
299
+ The kernel was misnamed — it is the first-order Volterra kernel of the
300
+ hemodynamic system (Friston 2000), unrelated to Lotka-Volterra dynamics.
301
+ """
302
+ warnings.warn(
303
+ "LotkaVolterraHRFKernel is deprecated and will be removed in a future "
304
+ "version. Use FirstOrderVolterraHRFKernel instead — the kernel is the "
305
+ "first-order Volterra kernel of the hemodynamic system (Friston 2000), "
306
+ "unrelated to Lotka-Volterra dynamics.",
307
+ DeprecationWarning,
308
+ stacklevel=2,
309
+ )
310
+ return FirstOrderVolterraHRFKernel(*args, **kwargs)
311
+
140
312
 
141
313
  class HRFBold(AbstractMonitor):
142
314
  """BOLD signal monitor using hemodynamic response function convolution.
@@ -199,7 +371,7 @@ class HRFBold(AbstractMonitor):
199
371
 
200
372
  # Set up kernel
201
373
  if kernel is None:
202
- self.kernel = LotkaVolterraHRFKernel()
374
+ self.kernel = FirstOrderVolterraHRFKernel()
203
375
  else:
204
376
  self.kernel = kernel
205
377
 
@@ -737,7 +737,11 @@ class BoundedParameter(Parameter):
737
737
  ) -> "BoundedParameter":
738
738
  """Unflatten for JAX pytree registration."""
739
739
  low, high = aux_data
740
- return cls(children[0], low, high)
740
+ instance = cls.__new__(cls)
741
+ instance.value = children[0]
742
+ instance.low = low
743
+ instance.high = high
744
+ return instance
741
745
 
742
746
 
743
747
  # Utility functions for working with parameters
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tvboptim
3
- Version: 0.2.9
3
+ Version: 0.2.10
4
4
  Summary: Optimization tools for The Virtual Brain
5
5
  Author-email: Marius Pille <marius.pille@bih-charite.de>
6
6
  License-Expression: EUPL-1.2
@@ -43,6 +43,7 @@ Requires-Dist: tvb-library; extra == "docs"
43
43
  Requires-Dist: jupyter-cache>=1.0.1; extra == "docs"
44
44
  Requires-Dist: nibabel; extra == "docs"
45
45
  Requires-Dist: nilearn; extra == "docs"
46
+ Requires-Dist: pymoo; extra == "docs"
46
47
  Requires-Dist: griffe<2.0.0; extra == "docs"
47
48
  Dynamic: license-file
48
49
 
@@ -25,4 +25,5 @@ tvb-library
25
25
  jupyter-cache>=1.0.1
26
26
  nibabel
27
27
  nilearn
28
+ pymoo
28
29
  griffe<2.0.0
File without changes
File without changes
File without changes