tvboptim 0.3.0__tar.gz → 0.3.1__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.
- {tvboptim-0.3.0/src/tvboptim.egg-info → tvboptim-0.3.1}/PKG-INFO +4 -3
- {tvboptim-0.3.0 → tvboptim-0.3.1}/README.md +3 -2
- {tvboptim-0.3.0 → tvboptim-0.3.1}/pyproject.toml +9 -1
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/analysis/identifiability.py +2 -5
- tvboptim-0.3.1/src/tvboptim/experimental/network_dynamics/analysis/__init__.py +9 -0
- tvboptim-0.3.1/src/tvboptim/experimental/network_dynamics/analysis/adiabatic_scan.py +183 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/analysis/lyapunov.py +18 -4
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/external_input/base.py +3 -1
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/solve.py +518 -147
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/solvers/native.py +75 -25
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/observations/__init__.py +2 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/observations/observation.py +51 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/observations/tvb_monitors/__init__.py +5 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/observations/tvb_monitors/bold.py +128 -24
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/optim/callbacks.py +6 -14
- {tvboptim-0.3.0 → tvboptim-0.3.1/src/tvboptim.egg-info}/PKG-INFO +4 -3
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim.egg-info/SOURCES.txt +1 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/tests/test_identifiability.py +6 -11
- tvboptim-0.3.0/src/tvboptim/experimental/network_dynamics/analysis/__init__.py +0 -3
- {tvboptim-0.3.0 → tvboptim-0.3.1}/LICENSE +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/setup.cfg +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/analysis/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/connectivity/dTOR/data.npz +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/connectivity/dk_average/data.npz +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/functional/dk_average/data.npz +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/loaders.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/plotting/dk_average/aparc+aseg-mni_09c.nii.gz +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/plotting/dk_average/fs_default.txt +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/data/plotting/dk_average/fs_default_freesurfer_idx.csv +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/execution.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/core/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/core/bunch.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/core/network.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/coupling/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/coupling/base.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/coupling/linear.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/coupling/subspace.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/coupling/tvb.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/base.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/lorenz.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/coombes_byrne.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/epileptor.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/generic_2d_oscillator.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/jansen_rit.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/kuramoto.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/larter_breakspear.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/linear.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/montbrio_pazo_roxin.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/sup_hopf.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wilson_cowan.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/dynamics/tvb/wong_wang_exc_inh.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/external_input/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/external_input/data.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/external_input/parametric.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/graph/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/graph/base.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/graph/sparse.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/graph/utils.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/noise/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/noise/base.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/noise/gaussian.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/result.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/solvers/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/solvers/base.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/solvers/diffrax.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/utils/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/utils/history.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/utils/printer.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/observations/tvb_monitors/downsampling.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/optim/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/optim/optax.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/tvbo/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/tvbo/prepare_experiment.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/types/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/types/parameter.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/types/spaces.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/types/stateutils.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/utils/__init__.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/utils/caching.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/utils/utils.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim.egg-info/dependency_links.txt +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim.egg-info/requires.txt +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim.egg-info/top_level.txt +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/tests/test_execution.py +0 -0
- {tvboptim-0.3.0 → tvboptim-0.3.1}/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.3.
|
|
3
|
+
Version: 0.3.1
|
|
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
|
|
@@ -53,8 +53,8 @@ Dynamic: license-file
|
|
|
53
53
|
|
|
54
54
|
# TVB-Optim
|
|
55
55
|
|
|
56
|
+
<!-- [](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml) -->
|
|
56
57
|
[](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml)
|
|
57
|
-
[](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml)
|
|
58
58
|
[](https://www.python.org/downloads/)
|
|
59
59
|
[](https://pypi.org/project/tvboptim/)
|
|
60
60
|
[](https://virtual-twin.github.io/tvboptim)
|
|
@@ -93,12 +93,13 @@ from tvboptim.experimental.network_dynamics.graph import DenseDelayGraph
|
|
|
93
93
|
from tvboptim.observations.tvb_monitors import Bold
|
|
94
94
|
from tvboptim.observations import compute_fc, rmse
|
|
95
95
|
from tvboptim.optim import OptaxOptimizer
|
|
96
|
+
from tvboptim.types import Parameter
|
|
96
97
|
import optax
|
|
97
98
|
|
|
98
99
|
# Build brain network model
|
|
99
100
|
network = Network(
|
|
100
101
|
dynamics=ReducedWongWang(),
|
|
101
|
-
coupling={'delayed': LinearCoupling(incoming_states="S", G=0.5)},
|
|
102
|
+
coupling={'delayed': LinearCoupling(incoming_states="S", G=Parameter(0.5))},
|
|
102
103
|
graph=DenseDelayGraph(weights, delays)
|
|
103
104
|
)
|
|
104
105
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
# TVB-Optim
|
|
6
6
|
|
|
7
|
+
<!-- [](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml) -->
|
|
7
8
|
[](https://github.com/virtual-twin/tvboptim/actions/workflows/python-package.yml)
|
|
8
|
-
[](https://github.com/virtual-twin/tvboptim/actions/workflows/ruff.yml)
|
|
9
9
|
[](https://www.python.org/downloads/)
|
|
10
10
|
[](https://pypi.org/project/tvboptim/)
|
|
11
11
|
[](https://virtual-twin.github.io/tvboptim)
|
|
@@ -44,12 +44,13 @@ from tvboptim.experimental.network_dynamics.graph import DenseDelayGraph
|
|
|
44
44
|
from tvboptim.observations.tvb_monitors import Bold
|
|
45
45
|
from tvboptim.observations import compute_fc, rmse
|
|
46
46
|
from tvboptim.optim import OptaxOptimizer
|
|
47
|
+
from tvboptim.types import Parameter
|
|
47
48
|
import optax
|
|
48
49
|
|
|
49
50
|
# Build brain network model
|
|
50
51
|
network = Network(
|
|
51
52
|
dynamics=ReducedWongWang(),
|
|
52
|
-
coupling={'delayed': LinearCoupling(incoming_states="S", G=0.5)},
|
|
53
|
+
coupling={'delayed': LinearCoupling(incoming_states="S", G=Parameter(0.5))},
|
|
53
54
|
graph=DenseDelayGraph(weights, delays)
|
|
54
55
|
)
|
|
55
56
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tvboptim"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.1"
|
|
8
8
|
description = "Optimization tools for The Virtual Brain"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -100,6 +100,14 @@ docs = [
|
|
|
100
100
|
"griffe<2.0.0"
|
|
101
101
|
]
|
|
102
102
|
|
|
103
|
+
[tool.uv]
|
|
104
|
+
# tvb-library depends on numba without an upper or lower bound, so a fresh
|
|
105
|
+
# resolution can backtrack numba down to 0.53.1 (-> llvmlite 0.36.0), which
|
|
106
|
+
# only builds on Python <3.10 and breaks CI on the >=3.11 matrix. Floor numba
|
|
107
|
+
# at a version that ships wheels for our supported Pythons. Constraints only
|
|
108
|
+
# bound transitively-pulled packages; they do not add a direct dependency.
|
|
109
|
+
constraint-dependencies = ["numba>=0.61", "llvmlite>=0.44"]
|
|
110
|
+
|
|
103
111
|
[tool.ruff]
|
|
104
112
|
line-length = 88
|
|
105
113
|
target-version = "py311"
|
|
@@ -235,8 +235,7 @@ class IdentifiabilityResult:
|
|
|
235
235
|
"""Human-readable one-screen report."""
|
|
236
236
|
label = _KIND_LABELS.get(self.kind, self.kind)
|
|
237
237
|
lines = [
|
|
238
|
-
f"Identifiability analysis -- {label} "
|
|
239
|
-
f"({self.n_params} parameters)",
|
|
238
|
+
f"Identifiability analysis -- {label} ({self.n_params} parameters)",
|
|
240
239
|
"-" * 60,
|
|
241
240
|
]
|
|
242
241
|
if self.gradient_norm is not None:
|
|
@@ -423,9 +422,7 @@ def eigendecompose_curvature(
|
|
|
423
422
|
downstream in ``summary()`` / ``__repr__``.
|
|
424
423
|
"""
|
|
425
424
|
if kind not in ("hessian", "fisher"):
|
|
426
|
-
raise ValueError(
|
|
427
|
-
f"`kind` must be 'hessian' or 'fisher', got {kind!r}."
|
|
428
|
-
)
|
|
425
|
+
raise ValueError(f"`kind` must be 'hessian' or 'fisher', got {kind!r}.")
|
|
429
426
|
matrix = jnp.asarray(matrix)
|
|
430
427
|
matrix = 0.5 * (matrix + matrix.T) # symmetrize against floating-point asymmetry
|
|
431
428
|
eigenvalues, eigenvectors = jnp.linalg.eigh(matrix)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Adiabatic parameter scan: a network bifurcation diagram.
|
|
2
|
+
|
|
3
|
+
Slowly ramp one parameter from ``low`` to ``high`` (and optionally back down to
|
|
4
|
+
catch hysteresis), carrying the settled state forward between steps, and record
|
|
5
|
+
summary statistics of an observed network signal at each value. This traces a
|
|
6
|
+
bifurcation-diagram-like picture of how the network's activity changes with the
|
|
7
|
+
swept parameter.
|
|
8
|
+
|
|
9
|
+
The swept parameter is addressed with a lens ``accessor`` applied through
|
|
10
|
+
``eqx.tree_at`` (e.g. ``lambda c: c.coupling.instant.G``), so any nested config
|
|
11
|
+
field can be scanned without the function knowing its name.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Callable, Dict
|
|
16
|
+
|
|
17
|
+
import equinox as eqx
|
|
18
|
+
import jax
|
|
19
|
+
import jax.numpy as jnp
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from .. import prepare
|
|
23
|
+
from ..core.bunch import Bunch
|
|
24
|
+
from ..solvers import Heun
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class AdiabaticScanResult:
|
|
29
|
+
"""Result of an :func:`adiabatic_scan`.
|
|
30
|
+
|
|
31
|
+
Attributes
|
|
32
|
+
----------
|
|
33
|
+
p : jax.Array
|
|
34
|
+
The swept parameter values, in scan order. Length ``2*n`` when
|
|
35
|
+
``bothways`` (up then down), else ``n``.
|
|
36
|
+
n_up : int
|
|
37
|
+
Number of values in the ascending branch. ``p[:n_up]`` is the up-branch
|
|
38
|
+
and ``p[n_up:]`` the down-branch.
|
|
39
|
+
stats : Bunch of str -> jax.Array
|
|
40
|
+
One array per recorded statistic, stacked along the scan axis and
|
|
41
|
+
reachable by attribute (``stats.mean``) or key (``stats["mean"]``).
|
|
42
|
+
Shape is ``[len(p)]`` for scalar reducers and ``[len(p), ...]`` for
|
|
43
|
+
vector-valued reducers (e.g. ``[len(p), n_nodes]`` for a per-node
|
|
44
|
+
statistic).
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
p: jax.Array
|
|
48
|
+
n_up: int
|
|
49
|
+
stats: Bunch
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _default_observe(result):
|
|
53
|
+
"""Observe the first variable across all nodes -> [n_time, n_nodes]."""
|
|
54
|
+
return result.ys[:, 0, :]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _network_mean(arr):
|
|
58
|
+
"""Mean over time per node, then averaged across nodes."""
|
|
59
|
+
return jnp.mean(arr, axis=0).mean()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _network_min(arr):
|
|
63
|
+
"""Mean over time per node, then the minimum across nodes."""
|
|
64
|
+
return jnp.mean(arr, axis=0).min()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _network_max(arr):
|
|
68
|
+
"""Mean over time per node, then the maximum across nodes."""
|
|
69
|
+
return jnp.mean(arr, axis=0).max()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
_DEFAULT_STATISTICS = {
|
|
73
|
+
"mean": _network_mean,
|
|
74
|
+
"min": _network_min,
|
|
75
|
+
"max": _network_max,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def adiabatic_scan(
|
|
80
|
+
network,
|
|
81
|
+
solver=None,
|
|
82
|
+
*,
|
|
83
|
+
accessor: Callable,
|
|
84
|
+
low: float,
|
|
85
|
+
high: float,
|
|
86
|
+
n: int,
|
|
87
|
+
t: float = 2000.0,
|
|
88
|
+
skip: float = 1000.0,
|
|
89
|
+
dt: float = 1.0,
|
|
90
|
+
t0: float = 0.0,
|
|
91
|
+
bothways: bool = True,
|
|
92
|
+
observe: Callable = None,
|
|
93
|
+
statistics: Dict[str, Callable] = None,
|
|
94
|
+
) -> AdiabaticScanResult:
|
|
95
|
+
"""Ramp one parameter and record network statistics (bifurcation diagram).
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
network : Network
|
|
100
|
+
solver : solver instance, optional (default: Heun())
|
|
101
|
+
accessor : callable
|
|
102
|
+
Lens onto the swept leaf, used as ``eqx.tree_at(accessor, config, value)``.
|
|
103
|
+
Example: ``lambda c: c.coupling.instant.G``.
|
|
104
|
+
low, high : float
|
|
105
|
+
Bounds of the swept parameter.
|
|
106
|
+
n : int
|
|
107
|
+
Number of values per branch.
|
|
108
|
+
t : float
|
|
109
|
+
Simulation duration per step in ms.
|
|
110
|
+
skip : float
|
|
111
|
+
Transient duration in ms discarded before computing statistics.
|
|
112
|
+
dt : float
|
|
113
|
+
Integration timestep in ms.
|
|
114
|
+
t0 : float
|
|
115
|
+
Simulation start time.
|
|
116
|
+
bothways : bool
|
|
117
|
+
If True, scan up then back down to expose hysteresis.
|
|
118
|
+
observe : callable, optional
|
|
119
|
+
``result -> [n_time, n_nodes]`` signal to summarise. Defaults to the
|
|
120
|
+
first variable across all nodes.
|
|
121
|
+
statistics : dict of str -> callable, optional
|
|
122
|
+
Maps a name to a reducer ``[n_time, n_nodes] -> scalar or array``.
|
|
123
|
+
Vector-valued reducers (e.g. a per-node ``[n_nodes]`` statistic) are
|
|
124
|
+
supported as long as the output shape is the same at every scan point.
|
|
125
|
+
Defaults to mean/min/max of the per-node temporal mean across the
|
|
126
|
+
network.
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
AdiabaticScanResult
|
|
131
|
+
|
|
132
|
+
Notes
|
|
133
|
+
-----
|
|
134
|
+
The settled state is carried forward between steps (the slow, adiabatic
|
|
135
|
+
ramp). For networks with delayed coupling the delay history buffer is not
|
|
136
|
+
carried, so this is only exact for instantaneous (non-delayed) coupling.
|
|
137
|
+
"""
|
|
138
|
+
if solver is None:
|
|
139
|
+
solver = Heun()
|
|
140
|
+
if observe is None:
|
|
141
|
+
observe = _default_observe
|
|
142
|
+
if statistics is None:
|
|
143
|
+
statistics = _DEFAULT_STATISTICS
|
|
144
|
+
|
|
145
|
+
solve_fn, config = prepare(network, solver, t0=t0, t1=t0 + t, dt=dt)
|
|
146
|
+
|
|
147
|
+
p_up = jnp.linspace(low, high, n)
|
|
148
|
+
if bothways:
|
|
149
|
+
p = jnp.concatenate([p_up, p_up[::-1]])
|
|
150
|
+
else:
|
|
151
|
+
p = p_up
|
|
152
|
+
|
|
153
|
+
n_states = config.initial_state.dynamics.shape[0]
|
|
154
|
+
init_state = config.initial_state.dynamics
|
|
155
|
+
|
|
156
|
+
# The save grid is deterministic in (t0, t1, dt), so the post-transient
|
|
157
|
+
# window is the same at every step. Resolve it once to static integer
|
|
158
|
+
# indices (a host-side computation) so the scan body has no data-dependent
|
|
159
|
+
# shapes and stays jittable.
|
|
160
|
+
probe_ts = np.asarray(solve_fn(config).ts)
|
|
161
|
+
keep = jnp.asarray(np.flatnonzero(probe_ts > (t0 + skip)))
|
|
162
|
+
|
|
163
|
+
def step(state, value):
|
|
164
|
+
cfg = eqx.tree_at(accessor, config, value)
|
|
165
|
+
cfg = eqx.tree_at(lambda c: c.initial_state.dynamics, cfg, state)
|
|
166
|
+
result = solve_fn(cfg)
|
|
167
|
+
|
|
168
|
+
# statistics over the post-transient window. Reducer outputs stay on the
|
|
169
|
+
# JAX side; lax.scan stacks them along the scan axis, so array-valued
|
|
170
|
+
# reducers like a per-node median ([n_nodes]) are supported.
|
|
171
|
+
arr = observe(result)[keep]
|
|
172
|
+
outs = {name: fn(arr) for name, fn in statistics.items()}
|
|
173
|
+
|
|
174
|
+
# carry the settled state forward (the slow, adiabatic ramp)
|
|
175
|
+
new_state = result.ys[-1][:n_states]
|
|
176
|
+
return new_state, outs
|
|
177
|
+
|
|
178
|
+
# The whole sweep is one jitted scan: a single XLA compilation, the carry
|
|
179
|
+
# expressed natively, and the function is vmap-able over a batch of `p`
|
|
180
|
+
# arrays to explore several ranges in parallel.
|
|
181
|
+
_, stacked = jax.jit(lambda s, ps: jax.lax.scan(step, s, ps))(init_state, p)
|
|
182
|
+
|
|
183
|
+
return AdiabaticScanResult(p=p, n_up=n, stats=Bunch(stacked))
|
{tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/analysis/lyapunov.py
RENAMED
|
@@ -30,10 +30,15 @@ def lyapunov(network, solver=None, t=1000.0, n=10, d0=1e-9, dt=0.1, t0=0.0):
|
|
|
30
30
|
|
|
31
31
|
Notes
|
|
32
32
|
-----
|
|
33
|
-
For
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
For delayed coupling the history buffer is held fixed across segments
|
|
34
|
+
(each rescaling step re-seeds only the point state), so the result is a
|
|
35
|
+
good approximation only when t >> max_delay, not exact. The two-trajectory
|
|
36
|
+
method is the natural route to a delay-correct MLE -- each trajectory
|
|
37
|
+
evolves its own history, so no explicit history-space tangents are needed --
|
|
38
|
+
but that needs carrying the full final state (point + history) across
|
|
39
|
+
segments, or running unsegmented. Run a warmup via
|
|
40
|
+
network.update_history(result) first to initialise the delay buffer from a
|
|
41
|
+
settled trajectory.
|
|
37
42
|
"""
|
|
38
43
|
if solver is None:
|
|
39
44
|
solver = Heun()
|
|
@@ -95,6 +100,15 @@ def lyapunov_spectrum(
|
|
|
95
100
|
Returns
|
|
96
101
|
-------
|
|
97
102
|
jnp.ndarray — top k Lyapunov exponents sorted descending (1/ms)
|
|
103
|
+
|
|
104
|
+
Notes
|
|
105
|
+
-----
|
|
106
|
+
Exact for instantaneous (non-delayed) coupling only. Both modes propagate a
|
|
107
|
+
*point* state (perturb/linearize only ``initial_state.dynamics``) and reset
|
|
108
|
+
the delay history buffer each rescaling step, so for delayed coupling the
|
|
109
|
+
history is held fixed across segments: a good approximation only when
|
|
110
|
+
``t >> max_delay``, not the true DDE spectrum (which would need tangents
|
|
111
|
+
spanning the augmented history-buffer state).
|
|
98
112
|
"""
|
|
99
113
|
if solver is None:
|
|
100
114
|
solver = Heun()
|
{tvboptim-0.3.0 → tvboptim-0.3.1}/src/tvboptim/experimental/network_dynamics/external_input/base.py
RENAMED
|
@@ -211,7 +211,9 @@ class AbstractExternalInput(ABC):
|
|
|
211
211
|
show_legend = n_nodes <= 8
|
|
212
212
|
for d in range(n_dims):
|
|
213
213
|
for i in range(n_nodes):
|
|
214
|
-
ax[d].plot(
|
|
214
|
+
ax[d].plot(
|
|
215
|
+
ts, signals[:, d, i], label=f"node {i}" if show_legend else None
|
|
216
|
+
)
|
|
215
217
|
ax[d].set_ylabel(f"input[{d}]" if n_dims > 1 else "input")
|
|
216
218
|
if show_legend and n_nodes > 1:
|
|
217
219
|
ax[d].legend(loc="best", fontsize="small")
|