tvboptim 0.2.0__tar.gz → 0.2.2__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 (78) hide show
  1. {tvboptim-0.2.0 → tvboptim-0.2.2}/PKG-INFO +17 -11
  2. {tvboptim-0.2.0 → tvboptim-0.2.2}/README.md +13 -10
  3. {tvboptim-0.2.0 → tvboptim-0.2.2}/pyproject.toml +8 -2
  4. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/__init__.py +2 -2
  5. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/core/network.py +4 -8
  6. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/coupling/base.py +35 -4
  7. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/coombes_byrne.py +2 -2
  8. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/epileptor.py +9 -7
  9. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/generic_2d_oscillator.py +1 -1
  10. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/kuramoto.py +3 -2
  11. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wilson_cowan.py +18 -19
  12. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/solve.py +410 -40
  13. tvboptim-0.2.2/src/tvboptim/tvbo/__init__.py +3 -0
  14. tvboptim-0.2.2/src/tvboptim/tvbo/prepare_experiment.py +148 -0
  15. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim.egg-info/PKG-INFO +17 -11
  16. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim.egg-info/SOURCES.txt +2 -1
  17. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim.egg-info/requires.txt +3 -0
  18. tvboptim-0.2.0/src/tvboptim/model.py +0 -111
  19. {tvboptim-0.2.0 → tvboptim-0.2.2}/LICENSE +0 -0
  20. {tvboptim-0.2.0 → tvboptim-0.2.2}/setup.cfg +0 -0
  21. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/data/__init__.py +0 -0
  22. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/data/loaders.py +0 -0
  23. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/execution.py +0 -0
  24. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/__init__.py +0 -0
  25. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/__init__.py +0 -0
  26. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/core/__init__.py +0 -0
  27. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/core/bunch.py +0 -0
  28. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/coupling/__init__.py +0 -0
  29. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/coupling/linear.py +0 -0
  30. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/coupling/subspace.py +0 -0
  31. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/coupling/tvb.py +0 -0
  32. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/__init__.py +0 -0
  33. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/base.py +0 -0
  34. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/lorenz.py +0 -0
  35. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/__init__.py +0 -0
  36. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/jansen_rit.py +0 -0
  37. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/larter_breakspear.py +0 -0
  38. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/linear.py +0 -0
  39. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/montbrio_pazo_roxin.py +0 -0
  40. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/sup_hopf.py +0 -0
  41. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang.py +0 -0
  42. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang_exc_inh.py +0 -0
  43. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/external_input/__init__.py +0 -0
  44. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/external_input/base.py +0 -0
  45. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/external_input/data.py +0 -0
  46. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/external_input/parametric.py +0 -0
  47. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/graph/__init__.py +0 -0
  48. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/graph/base.py +0 -0
  49. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/graph/sparse.py +0 -0
  50. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/graph/utils.py +0 -0
  51. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/noise/__init__.py +0 -0
  52. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/noise/base.py +0 -0
  53. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/noise/gaussian.py +0 -0
  54. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/result.py +0 -0
  55. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/solvers/__init__.py +0 -0
  56. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/solvers/base.py +0 -0
  57. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/solvers/diffrax.py +0 -0
  58. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/solvers/native.py +0 -0
  59. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/utils/__init__.py +0 -0
  60. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/experimental/network_dynamics/utils/printer.py +0 -0
  61. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/observations/__init__.py +0 -0
  62. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/observations/observation.py +0 -0
  63. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/observations/tvb_monitors/__init__.py +0 -0
  64. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/observations/tvb_monitors/bold.py +0 -0
  65. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/observations/tvb_monitors/downsampling.py +0 -0
  66. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/optim/__init__.py +0 -0
  67. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/optim/callbacks.py +0 -0
  68. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/optim/optax.py +0 -0
  69. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/types/__init__.py +0 -0
  70. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/types/parameter.py +0 -0
  71. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/types/spaces.py +0 -0
  72. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/types/stateutils.py +0 -0
  73. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/utils/__init__.py +0 -0
  74. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/utils/caching.py +0 -0
  75. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim/utils/utils.py +0 -0
  76. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim.egg-info/dependency_links.txt +0 -0
  77. {tvboptim-0.2.0 → tvboptim-0.2.2}/src/tvboptim.egg-info/top_level.txt +0 -0
  78. {tvboptim-0.2.0 → tvboptim-0.2.2}/tests/test_execution.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tvboptim
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
@@ -38,29 +38,35 @@ Requires-Dist: quartodoc>=0.6.0; extra == "dev"
38
38
  Requires-Dist: jupyter>=1.0.0; extra == "dev"
39
39
  Requires-Dist: ipykernel; extra == "dev"
40
40
  Provides-Extra: docs
41
+ Requires-Dist: tvb-library; extra == "docs"
41
42
  Requires-Dist: jupyter-cache>=1.0.1; extra == "docs"
43
+ Requires-Dist: nibabel; extra == "docs"
44
+ Requires-Dist: nilearn; extra == "docs"
42
45
  Dynamic: license-file
43
46
 
44
47
  <p align="center">
45
- <img src="./docs/images/tvboptim.png" width="60%">
48
+ <img src="https://raw.githubusercontent.com/virtual-twin/tvboptim/main/docs/images/tvboptim.png" width="60%">
46
49
  </p>
47
50
 
48
51
  # TVB-Optim
49
52
 
50
53
  [![Tests](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml/badge.svg)](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml)
51
- [![codecov](https://codecov.io/gh/virtual-twin/tvboptim/branch/main/graph/badge.svg)](https://codecov.io/gh/virtual-twin/tvboptim)
54
+ [![Ruff](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml/badge.svg)](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml)
52
55
  [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
56
+ [![PyPI version](https://img.shields.io/pypi/v/tvboptim.svg)](https://pypi.org/project/tvboptim/)
57
+ <!-- [![Downloads](https://img.shields.io/pypi/dm/tvboptim.svg)](https://pypi.org/project/tvboptim/) -->
58
+ <!-- [![codecov](https://codecov.io/gh/virtual-twin/tvboptim/branch/main/graph/badge.svg)](https://codecov.io/gh/virtual-twin/tvboptim) -->
53
59
 
54
60
  [JAX](https://jax.readthedocs.io/en/latest/)-based framework for brain network simulation and gradient-based optimization.
55
61
 
56
- **[Documentation](https://virtual-twin.github.io/tvboptim)** | **[Get Started](https://virtual-twin.github.io/tvboptim/get_started.html)** | **[Examples](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html)**
62
+ **[Documentation](https://virtual-twin.github.io/tvboptim)** | **[Get Started](https://virtual-twin.github.io/tvboptim/get_started.html)** | **[Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html)**
57
63
 
58
64
  ## Key Features
59
65
 
60
- - **Gradient-based optimization** - Fit thousands of parameters using automatic differentiation through the entire simulation pipeline
61
- - **Performance** - JAX-powered with seamless GPU/TPU scaling
62
- - **Flexible & extensible** - Build models with [Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html), a composable framework for whole-brain modeling. Existing TVB workflows supported via [TVB-O](https://github.com/virtual-twin/tvbo).
63
- - **Intuitive parameter control** - Mark values for optimization with [Parameter()](https://virtual-twin.github.io/tvboptim/parameters_and_optimization.html). Define exploration spaces with [Axes](https://virtual-twin.github.io/tvboptim/axes_and_spaces.html) for automatic parallel evaluation via JAX vmap/pmap.
66
+ - **Gradient-based optimization:** Fit thousands of parameters using automatic differentiation through the entire simulation pipeline
67
+ - **Performance:** JAX-powered with seamless GPU/TPU scaling
68
+ - **Flexible & extensible:** Build models with [Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html), a composable framework for whole-brain modeling. Existing TVB workflows supported via [TVB-O](https://github.com/virtual-twin/tvbo).
69
+ - **Intuitive parameter control:** Mark values for optimization with [Parameter()](https://virtual-twin.github.io/tvboptim/parameters_and_optimization.html). Define exploration spaces with [Axes](https://virtual-twin.github.io/tvboptim/axes_and_spaces.html) for automatic parallel evaluation via JAX vmap/pmap.
64
70
 
65
71
  ## Installation
66
72
 
@@ -120,11 +126,11 @@ See the [full example with visualization](https://virtual-twin.github.io/tvbopti
120
126
 
121
127
  ## How It Works
122
128
 
123
- **Functional Composition** - Models are composable functions that can be inspected, modified, and extended. Build complexity incrementally by wrapping functions.
129
+ **Functional Composition:** Models are composable functions that can be inspected, modified, and extended. Build complexity incrementally by wrapping functions.
124
130
 
125
- **End-to-End Differentiability** - Compute gradients through the full pipeline: neural dynamics → hemodynamic models → empirical observables.
131
+ **End-to-End Differentiability:** Compute gradients through the full pipeline: neural dynamics → hemodynamic models → empirical observables.
126
132
 
127
- **Interoperability** - Convert existing TVB simulations to JAX-compatible functions via the TVB-O framework.
133
+ **Interoperability:** Convert existing TVB simulations to JAX-compatible functions via the TVB-O framework.
128
134
 
129
135
  ## Contributing
130
136
 
@@ -1,23 +1,26 @@
1
1
  <p align="center">
2
- <img src="./docs/images/tvboptim.png" width="60%">
2
+ <img src="https://raw.githubusercontent.com/virtual-twin/tvboptim/main/docs/images/tvboptim.png" width="60%">
3
3
  </p>
4
4
 
5
5
  # TVB-Optim
6
6
 
7
7
  [![Tests](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml/badge.svg)](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml)
8
- [![codecov](https://codecov.io/gh/virtual-twin/tvboptim/branch/main/graph/badge.svg)](https://codecov.io/gh/virtual-twin/tvboptim)
8
+ [![Ruff](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml/badge.svg)](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml)
9
9
  [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
10
+ [![PyPI version](https://img.shields.io/pypi/v/tvboptim.svg)](https://pypi.org/project/tvboptim/)
11
+ <!-- [![Downloads](https://img.shields.io/pypi/dm/tvboptim.svg)](https://pypi.org/project/tvboptim/) -->
12
+ <!-- [![codecov](https://codecov.io/gh/virtual-twin/tvboptim/branch/main/graph/badge.svg)](https://codecov.io/gh/virtual-twin/tvboptim) -->
10
13
 
11
14
  [JAX](https://jax.readthedocs.io/en/latest/)-based framework for brain network simulation and gradient-based optimization.
12
15
 
13
- **[Documentation](https://virtual-twin.github.io/tvboptim)** | **[Get Started](https://virtual-twin.github.io/tvboptim/get_started.html)** | **[Examples](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html)**
16
+ **[Documentation](https://virtual-twin.github.io/tvboptim)** | **[Get Started](https://virtual-twin.github.io/tvboptim/get_started.html)** | **[Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html)**
14
17
 
15
18
  ## Key Features
16
19
 
17
- - **Gradient-based optimization** - Fit thousands of parameters using automatic differentiation through the entire simulation pipeline
18
- - **Performance** - JAX-powered with seamless GPU/TPU scaling
19
- - **Flexible & extensible** - Build models with [Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html), a composable framework for whole-brain modeling. Existing TVB workflows supported via [TVB-O](https://github.com/virtual-twin/tvbo).
20
- - **Intuitive parameter control** - Mark values for optimization with [Parameter()](https://virtual-twin.github.io/tvboptim/parameters_and_optimization.html). Define exploration spaces with [Axes](https://virtual-twin.github.io/tvboptim/axes_and_spaces.html) for automatic parallel evaluation via JAX vmap/pmap.
20
+ - **Gradient-based optimization:** Fit thousands of parameters using automatic differentiation through the entire simulation pipeline
21
+ - **Performance:** JAX-powered with seamless GPU/TPU scaling
22
+ - **Flexible & extensible:** Build models with [Network Dynamics](https://virtual-twin.github.io/tvboptim/network_dynamics/network_dynamics.html), a composable framework for whole-brain modeling. Existing TVB workflows supported via [TVB-O](https://github.com/virtual-twin/tvbo).
23
+ - **Intuitive parameter control:** Mark values for optimization with [Parameter()](https://virtual-twin.github.io/tvboptim/parameters_and_optimization.html). Define exploration spaces with [Axes](https://virtual-twin.github.io/tvboptim/axes_and_spaces.html) for automatic parallel evaluation via JAX vmap/pmap.
21
24
 
22
25
  ## Installation
23
26
 
@@ -77,11 +80,11 @@ See the [full example with visualization](https://virtual-twin.github.io/tvbopti
77
80
 
78
81
  ## How It Works
79
82
 
80
- **Functional Composition** - Models are composable functions that can be inspected, modified, and extended. Build complexity incrementally by wrapping functions.
83
+ **Functional Composition:** Models are composable functions that can be inspected, modified, and extended. Build complexity incrementally by wrapping functions.
81
84
 
82
- **End-to-End Differentiability** - Compute gradients through the full pipeline: neural dynamics → hemodynamic models → empirical observables.
85
+ **End-to-End Differentiability:** Compute gradients through the full pipeline: neural dynamics → hemodynamic models → empirical observables.
83
86
 
84
- **Interoperability** - Convert existing TVB simulations to JAX-compatible functions via the TVB-O framework.
87
+ **Interoperability:** Convert existing TVB simulations to JAX-compatible functions via the TVB-O framework.
85
88
 
86
89
  ## Contributing
87
90
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tvboptim"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Optimization tools for The Virtual Brain"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -63,7 +63,10 @@ dev = [
63
63
  ]
64
64
  docs = [
65
65
  # "tvbo",
66
+ "tvb-library",
66
67
  "jupyter-cache>=1.0.1",
68
+ "nibabel",
69
+ "nilearn",
67
70
  ]
68
71
 
69
72
  # Standard PEP 621 optional dependencies (used by PyPI)
@@ -77,8 +80,11 @@ dev = [
77
80
  "ipykernel",
78
81
  ]
79
82
  docs = [
80
- # "tvbo", # Uncomment when published to PyPI
83
+ # "tvbo",
84
+ "tvb-library",
81
85
  "jupyter-cache>=1.0.1",
86
+ "nibabel",
87
+ "nilearn",
82
88
  ]
83
89
 
84
90
  [tool.ruff]
@@ -3,7 +3,7 @@
3
3
  __version__ = "0.1.0"
4
4
 
5
5
  from . import data
6
- from .model import jaxify
6
+ from .tvbo.prepare_experiment import HAS_TVBO, prepare
7
7
  from .types import parameter, spaces
8
8
 
9
- __all__ = ["spaces", "jaxify", "parameter", "data"]
9
+ __all__ = ["spaces", "prepare", "HAS_TVBO", "parameter", "data"]
@@ -528,10 +528,9 @@ class Network:
528
528
  Otherwise history buffer [n_steps, n_states, n_nodes]
529
529
  where n_steps = ceil(max_delay / dt)
530
530
  """
531
- if self.max_delay == 0.0:
532
- return None
533
-
534
- n_steps = int(jnp.ceil(self.max_delay / dt))
531
+ n_steps = max(
532
+ 1, int(jnp.ceil(self.max_delay / dt))
533
+ ) # at least 1 step (case: speed = inf)
535
534
  return jnp.broadcast_to(
536
535
  self.initial_state[None, :, :],
537
536
  (n_steps, self.initial_state.shape[0], self.initial_state.shape[1]),
@@ -552,7 +551,7 @@ class Network:
552
551
  where n_steps = ceil(max_delay / dt)
553
552
  """
554
553
  # Calculate required number of steps
555
- n_steps_needed = int(jnp.ceil(self.max_delay / dt))
554
+ n_steps_needed = int(jnp.rint(self.max_delay / dt)) + 1
556
555
 
557
556
  # Get history data
558
557
  hist_ts = self._history.ts
@@ -657,9 +656,6 @@ class Network:
657
656
  Otherwise history buffer [n_steps, n_states, n_nodes]
658
657
  where n_steps = ceil(max_delay / dt)
659
658
  """
660
- if self.max_delay == 0.0:
661
- return None
662
-
663
659
  if self._history is None:
664
660
  return self._get_initial_history(dt)
665
661
  else:
@@ -684,8 +684,26 @@ class DelayedCoupling(AbstractCoupling):
684
684
  local_idx = dynamics.name_to_index(self.LOCAL_STATE_NAMES)
685
685
 
686
686
  # Setup delay indexing (static)
687
+ # Convert delay times to discrete timesteps
687
688
  delays_dense = _ensure_dense(graph.delays)
688
- delay_indices = jnp.round(delays_dense / dt).astype(jnp.int32)
689
+
690
+ # Compute delay indices for history buffer lookup
691
+ # History buffer structure: [max_delay_steps+1, n_states, n_nodes]
692
+ # - history[0] contains the oldest state (max_delay in the past)
693
+ # - history[max_delay_steps] contains the newest state (current step)
694
+ #
695
+ # For edge (j,k) with delay τ_jk, we need: state from (max_delay - τ_jk) ago
696
+ # This inverted indexing ensures:
697
+ # - Large delays (close to max_delay) → small index (older states)
698
+ # - Small delays (close to 0) → large index (newer states)
699
+ #
700
+ # Example: max_delay=10ms, dt=1ms, τ_jk=3ms
701
+ # → delay_index[j,k] = 10 - 3 = 7
702
+ # → history[7] gives state from 3ms ago (10ms - 3ms from oldest)
703
+ max_delay_steps = jnp.rint(graph.max_delay / dt).astype(jnp.int32)
704
+ delay_steps = jnp.rint(delays_dense / dt).astype(jnp.int32)
705
+ delay_indices = max_delay_steps - delay_steps
706
+
689
707
  state_indices = jnp.arange(graph.n_nodes)
690
708
 
691
709
  # Precompute BCOO indices for sparse incoming states optimization
@@ -744,8 +762,12 @@ class DelayedCoupling(AbstractCoupling):
744
762
  from ..graph.sparse import SparseDelayGraph
745
763
 
746
764
  # Extract delayed states from history using indices from coupling_data
747
- # delayed_states[i, j, k] = history[delay[j,k], i, k]
748
- # i.e., state i from node k delayed by delay[j,k] going to node j
765
+ # History indexing: history[delay_indices[j,k], :, k] retrieves state from node k
766
+ # at the appropriate time delay for edge j←k
767
+ #
768
+ # Result shape after indexing: [n_nodes_target, n_nodes_source, n_incoming, n_nodes]
769
+ # After transpose: delayed_states[i, j, k] = history[delay_indices[j,k], i, k]
770
+ # i.e., incoming state i from source node k, delayed by τ_jk, going to target node j
749
771
  delayed_states = jnp.transpose(
750
772
  coupling_state.history[
751
773
  coupling_data.delay_indices, :, coupling_data.state_indices
@@ -824,9 +846,18 @@ class DelayedCoupling(AbstractCoupling):
824
846
  New Bunch with updated history buffer
825
847
  """
826
848
  # Update history buffer (circular) - only mutable operation
849
+ # History structure after roll: [max_delay_steps+1, n_incoming, n_nodes]
850
+ # - history[0] = oldest state (at time t - max_delay)
851
+ # - history[-1] = newest state (at time t, before update)
852
+ #
853
+ # Roll by -1 shifts all states towards index 0 (older end):
854
+ # [oldest, ..., newest] → [2nd_oldest, ..., newest, oldest]
855
+ # Then overwrite index -1 with new current state:
856
+ # [2nd_oldest, ..., old_newest, **new_state**]
857
+ # This maintains history[0]=oldest, history[-1]=newest
827
858
  new_history = jnp.roll(coupling_state.history, -1, axis=0)
828
859
  new_incoming_states = new_state[coupling_data.incoming_indices]
829
- new_history = new_history.at[0].set(new_incoming_states)
860
+ new_history = new_history.at[-1].set(new_incoming_states)
830
861
 
831
862
  return Bunch(history=new_history)
832
863
 
@@ -79,7 +79,7 @@ class CoombesByrne2D(AbstractDynamics):
79
79
  Delta=1.0, # Width of heterogeneous noise distribution
80
80
  eta=2.0, # Constant external input
81
81
  k=1.0, # Synaptic conductance scaling (kappa)
82
- v_syn=0.0, # Synaptic reversal potential
82
+ v_syn=-4.0, # Synaptic reversal potential
83
83
  )
84
84
 
85
85
  COUPLING_INPUTS = {
@@ -136,7 +136,7 @@ class CoombesByrne2D(AbstractDynamics):
136
136
 
137
137
  # Mean field dynamics
138
138
  # Firing rate dynamics (with quadratic damping from conductance)
139
- dr_dt = params.Delta / jnp.pi + 2.0 * V * r - g * r**2
139
+ dr_dt = params.Delta / jnp.pi + 2.0 * V * r - g * r
140
140
 
141
141
  # Membrane potential dynamics (with conductance-based interaction)
142
142
  dV_dt = (
@@ -97,7 +97,7 @@ class Epileptor(AbstractDynamics):
97
97
  Ks=0.0, # Slow time scale coupling (to z, permittivity)
98
98
  # Global parameters
99
99
  tt=1.0, # Global time scaling
100
- modification=False, # Use nonlinear permittivity influence on z
100
+ modification=0.0, # Use nonlinear permittivity influence on z (1.0=yes, 0.0=no)
101
101
  )
102
102
 
103
103
  COUPLING_INPUTS = {
@@ -164,12 +164,14 @@ class Epileptor(AbstractDynamics):
164
164
  z_nonlin_if_pos = 0.0
165
165
  z_nonlin = jnp.where(z < 0.0, z_nonlin_if_neg, z_nonlin_if_pos)
166
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
167
+ # Compute both permittivity influence variants
168
+ # Nonlinear (sigmoidal) permittivity influence
169
+ h_nonlinear = params.x0 + 3.0 / (1.0 + jnp.exp(-(x1 + 0.5) / 0.1))
170
+ # Linear permittivity influence
171
+ h_linear = 4.0 * (x1 - params.x0) + z_nonlin
172
+
173
+ # Select based on modification parameter (1.0=nonlinear, 0.0=linear)
174
+ h = params.modification * h_nonlinear + (1.0 - params.modification) * h_linear
173
175
 
174
176
  dz_dt = params.tt * params.r * (h - z + params.Ks * c_pop1)
175
177
 
@@ -133,7 +133,7 @@ class Generic2dOscillator(AbstractDynamics):
133
133
  + params.alpha * W
134
134
  + params.gamma * params.I
135
135
  + params.gamma * c_delayed
136
- + c_instant
136
+ + params.gamma * c_instant
137
137
  )
138
138
  + stim
139
139
  )
@@ -109,10 +109,11 @@ class Kuramoto(AbstractDynamics):
109
109
 
110
110
  # Phase dynamics with Kuramoto-style local coupling
111
111
  # Local coupling is phase-dependent via sinusoidal transformation
112
- local_range_coupling = jnp.sin(c_instant * theta)
112
+ local_coupling = 0
113
+ local_range_coupling = jnp.sin(local_coupling * theta)
113
114
 
114
115
  # Phase update: natural frequency + long-range + local coupling
115
- dtheta_dt = params.omega + c_delayed + local_range_coupling
116
+ dtheta_dt = params.omega + c_delayed + c_instant + local_range_coupling
116
117
 
117
118
  # Package results
118
119
  derivatives = jnp.array([dtheta_dt])
@@ -111,8 +111,8 @@ class WilsonCowan(AbstractDynamics):
111
111
  # Input gain parameters
112
112
  alpha_e=1.0, # Excitatory input scaling
113
113
  alpha_i=1.0, # Inhibitory input scaling
114
- # Sigmoid shift option
115
- shift_sigmoid=False, # Whether to use baseline-corrected sigmoid
114
+ # Sigmoid shift option (use 1.0 for shifted, 0.0 for standard)
115
+ shift_sigmoid=1.0, # Whether to use baseline-corrected sigmoid (1.0=yes, 0.0=no)
116
116
  )
117
117
 
118
118
  COUPLING_INPUTS = {
@@ -181,23 +181,22 @@ class WilsonCowan(AbstractDynamics):
181
181
  )
182
182
 
183
183
  # Compute sigmoid activation functions
184
- if params.shift_sigmoid:
185
- # Baseline-corrected sigmoid (passes through zero)
186
- sigmoid_offset_e = 1.0 / (1.0 + jnp.exp(params.a_e * params.b_e))
187
- S_e = params.c_e * (
188
- 1.0 / (1.0 + jnp.exp(-params.a_e * (x_e - params.b_e)))
189
- - sigmoid_offset_e
190
- )
191
-
192
- sigmoid_offset_i = 1.0 / (1.0 + jnp.exp(params.a_i * params.b_i))
193
- S_i = params.c_i * (
194
- 1.0 / (1.0 + jnp.exp(-params.a_i * (x_i - params.b_i)))
195
- - sigmoid_offset_i
196
- )
197
- else:
198
- # Standard sigmoid
199
- S_e = params.c_e / (1.0 + jnp.exp(-params.a_e * (x_e - params.b_e)))
200
- S_i = params.c_i / (1.0 + jnp.exp(-params.a_i * (x_i - params.b_i)))
184
+ # Standard sigmoid
185
+ sigmoid_e = params.c_e / (1.0 + jnp.exp(-params.a_e * (x_e - params.b_e)))
186
+ sigmoid_i = params.c_i / (1.0 + jnp.exp(-params.a_i * (x_i - params.b_i)))
187
+
188
+ # Baseline correction offset (only applied if shift_sigmoid=1.0)
189
+ # When shift_sigmoid=0.0, offset is zero (standard sigmoid)
190
+ # When shift_sigmoid=1.0, offset shifts sigmoid to pass through zero
191
+ sigmoid_offset_e = (
192
+ params.shift_sigmoid * params.c_e / (1.0 + jnp.exp(params.a_e * params.b_e))
193
+ )
194
+ sigmoid_offset_i = (
195
+ params.shift_sigmoid * params.c_i / (1.0 + jnp.exp(params.a_i * params.b_i))
196
+ )
197
+
198
+ S_e = sigmoid_e - sigmoid_offset_e
199
+ S_i = sigmoid_i - sigmoid_offset_i
201
200
 
202
201
  # Population dynamics
203
202
  dE_dt = (-E + (params.k_e - params.r_e * E) * S_e) / params.tau_e