brainx-skill 1.0.6 → 1.0.9
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.
- package/README.md +10 -8
- package/adapters/gemini.js +7 -0
- package/adapters/opencode.js +7 -0
- package/adapters/windsurf.js +7 -0
- package/installation/lib/installer.js +4 -1
- package/manifest.json +6 -1
- package/package.json +8 -2
- package/skills/braincell/SKILL.md +182 -0
- package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
- package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +273 -0
- package/skills/braincell/references/channel-library.md +85 -0
- package/skills/braincell/references/ion-library.md +87 -0
- package/skills/braincell/references/mixions-for-adaptation.md +81 -0
- package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
- package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
- package/skills/braincell/references/multicompartment/filter-function-library.md +154 -0
- package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
- package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
- package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
- package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +260 -0
- package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
- package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
- package/skills/braincell/references/scripts/channel_ablation.py +61 -0
- package/skills/braincell/references/scripts/fi_curve.py +68 -0
- package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
- package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
- package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
- package/skills/braincell/references/solver-library-with-effects.md +188 -0
- package/skills/brainevent/SKILL.md +268 -0
- package/skills/brainevent/references/connectivity-variants.md +312 -0
- package/skills/brainevent/references/custom-operators-cpu.md +304 -0
- package/skills/brainevent/references/custom-operators-gpu.md +468 -0
- package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
- package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
- package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
- package/skills/brainevent/references/sparse-formats.md +182 -0
- package/skills/brainevent/references/synaptic-plasticity.md +285 -0
- package/skills/brainmass/SKILL.md +290 -0
- package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
- package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
- package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
- package/skills/brainmass/references/braintools/cogtask.md +190 -0
- package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
- package/skills/brainmass/references/braintools/metric.md +157 -0
- package/skills/brainmass/references/braintools/optimizer.md +187 -0
- package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
- package/skills/brainmass/references/braintools/surrogate.md +151 -0
- package/skills/brainmass/references/coupling-network-api.md +148 -0
- package/skills/brainmass/references/datasets-api.md +72 -0
- package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
- package/skills/brainmass/references/forward-observation-api.md +131 -0
- package/skills/brainmass/references/horn-task-training.md +199 -0
- package/skills/brainmass/references/modellibrary.md +104 -0
- package/skills/brainmass/references/noiseprocesses.md +121 -0
- package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
- package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
- package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
- package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
- package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
- package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
- package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
- package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
- package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
- package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
- package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
- package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
- package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
- package/skills/brainmass/references/visualization-analysis-api.md +130 -0
- package/skills/brainpy-state/SKILL.md +232 -0
- package/skills/brainpy-state/references/array-creation.md +158 -0
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
- package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
- package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
- package/skills/brainpy-state/references/braintools/metric.md +152 -0
- package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
- package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
- package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
- package/skills/brainpy-state/references/component-selection.md +273 -0
- package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
- package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
- package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
- package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
- package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
- package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
- package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
- package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
- package/skills/brainpy-state/references/projection-patterns.md +125 -0
- package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
- package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
- package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
- package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
- package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
- package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
- package/skills/brainstate/SKILL.md +1 -1
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +250 -399
- package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +6 -2
- package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +16 -2
- package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +8 -3
- package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +64 -143
- package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +13 -1
- package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +11 -1
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +35 -7
- package/skills/brainstate/references/collective_model_operations.md +9 -9
- package/skills/brainstate/references/extension_mechanisms.md +12 -1
- package/skills/brainstate/references/libraries/prebuilt-activation-library.md +106 -97
- package/skills/brainstate/references/libraries/prebuilt-layer-library.md +102 -176
- package/skills/brainstate/references/model-interop-and-migration.md +11 -1
- package/skills/brainstate/references/size-inference-variations.md +11 -0
- package/skills/brainstate/references/state-graph-operations.md +13 -15
- package/skills/brainstate/references/state_collections_and_utilities.md +12 -1
- package/skills/brainx-general-guard/SKILL.md +68 -0
- package/skills/brainstate/references/braintools-optimizer-reference.md +0 -133
- package/skills/brainstate/references/libraries/solver-library-with-effects.md +0 -85
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# BrainMass datasets
|
|
2
|
+
|
|
3
|
+
Use this reference when loading bundled BrainMass examples, inspecting typed connectome or signal containers, generating delayed-match task data, or registering a small local dataset loader.
|
|
4
|
+
|
|
5
|
+
## Registry
|
|
6
|
+
|
|
7
|
+
| API | Description |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `brainmass.datasets.list_datasets()` | List names and descriptions currently registered in the installed release. |
|
|
10
|
+
| `brainmass.datasets.load_dataset(name)` | Resolve a registered loader and return its typed or generated value; an unknown name raises instead of guessing a path. |
|
|
11
|
+
| `brainmass.datasets.register_dataset(name, loader, description=...)` | Register a callable under one name for the current process; the callable runs each time the dataset is loaded. |
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import brainmass
|
|
15
|
+
|
|
16
|
+
available = brainmass.datasets.list_datasets()
|
|
17
|
+
connectome = brainmass.datasets.load_dataset("example_connectome")
|
|
18
|
+
signal = brainmass.datasets.load_dataset("example_signal")
|
|
19
|
+
|
|
20
|
+
assert connectome.weights.shape == connectome.distances.shape == (8, 8)
|
|
21
|
+
assert signal.signal.shape == (500, 8)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use the registry for small, deterministic tutorial or study-local loaders. It is not a remote dataset manager or a persistence format.
|
|
25
|
+
|
|
26
|
+
## Typed containers
|
|
27
|
+
|
|
28
|
+
| API | Description |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `brainmass.datasets.Connectome(weights, distances, labels)` | Hold square structural weights, unit-aware inter-region distances, and region labels used by `Network`. |
|
|
31
|
+
| `brainmass.datasets.Signal(signal, dt, labels, fc)` | Hold a time-major multi-region signal, its sampling step, labels, and precomputed functional connectivity. |
|
|
32
|
+
| `brainmass.datasets.delayed_match_task(n_samples=..., seq_len=..., n_symbols=..., seed=...)` | Generate reproducible delayed-match-to-sample inputs and binary targets for the HORN workflow. |
|
|
33
|
+
|
|
34
|
+
The built-in registry provides:
|
|
35
|
+
|
|
36
|
+
| Name | Result | Use |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `example_connectome` | `Connectome` | Small symmetric eight-region weights, millimeter distances, and labels for network tutorials. |
|
|
39
|
+
| `example_signal` | `Signal` | Short eight-region target trajectory, sampling `dt`, labels, and FC for fitting and analysis. |
|
|
40
|
+
| `delayed_match_task` | `(inputs, targets)` | Synthetic task data generated from the requested size and seed. |
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
inputs, targets = brainmass.datasets.delayed_match_task(
|
|
44
|
+
n_samples=32,
|
|
45
|
+
seq_len=8,
|
|
46
|
+
n_symbols=2,
|
|
47
|
+
seed=0,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
assert inputs.shape == (32, 8, 2)
|
|
51
|
+
assert targets.shape == (32,)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Treat BrainMass signals as time-major and HORN task inputs as `(sample, time, feature)` until the training workflow explicitly transposes them.
|
|
55
|
+
|
|
56
|
+
## Register a loader
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
brainmass.datasets.register_dataset(
|
|
60
|
+
"study_connectome",
|
|
61
|
+
lambda: connectome,
|
|
62
|
+
description="Validated connectome for the current study",
|
|
63
|
+
)
|
|
64
|
+
loaded = brainmass.datasets.load_dataset("study_connectome")
|
|
65
|
+
assert loaded is connectome
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Validate shape, symmetry or directionality, diagonal policy, units, labels, and sampling interval in the loader or immediately after loading. Registration alone does not validate scientific metadata.
|
|
69
|
+
|
|
70
|
+
## Official source
|
|
71
|
+
|
|
72
|
+
- `https://brainx.chaobrain.com/brainmass/reference/datasets.html`
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Fitting and objectives
|
|
2
|
+
|
|
3
|
+
Use this reference when choosing the `Fitter` interface, defining a scalar target, selecting a built-in objective, configuring a backend or search space, interpreting `FitResult`, or diagnosing a fit that optimizes the wrong quantity.
|
|
4
|
+
|
|
5
|
+
## Choose the fitting interface
|
|
6
|
+
|
|
7
|
+
| Interface | Use when | Loss ownership |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `Fitter(..., loss_fn=loss_fn)` | The model must be reduced to a derived scalar such as amplitude, spectral peak, or a custom statistic. | `loss_fn(model) -> (scalar_loss, aux)` owns the entire loss, including regularization. |
|
|
10
|
+
| `Fitter(..., predict=predict, objective=objective)` | A trajectory or observation is compared directly with a target through a reusable objective. | `Fitter` evaluates `objective(predict(model)[transient:], target) + model.reg_loss()`. |
|
|
11
|
+
|
|
12
|
+
Do not supply both `loss_fn` and `predict`. Use the derived-scalar route for phase-degenerate oscillators rather than pointwise time-series RMSE.
|
|
13
|
+
|
|
14
|
+
## Configure `Fitter`
|
|
15
|
+
|
|
16
|
+
| API | Description |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `brainstate.nn.Param(value, t=..., fit=True)` | Mark one parameter trainable; a transform keeps the physical value constrained while optimization occurs in its stored space. |
|
|
19
|
+
| `brainmass.Fitter(model, optimizer=None, *, loss_fn=None, objective=None, predict=None, backend="grad", callbacks=None, transient=None, search_space=None)` | Construct one fitting problem and discover the model's trainable `ParamState` values. |
|
|
20
|
+
| `Fitter.fit(target=None, n_steps=100, verbose=False)` | Execute optimizer steps, generations, or restarts according to the backend and return the best-seen `FitResult`. |
|
|
21
|
+
| `Fitter.optimizer` | Inspect the active optimizer; derivative-free backends create it lazily during `fit()`. |
|
|
22
|
+
|
|
23
|
+
`transient` on `Fitter` is a leading sample count applied to the prediction path. It is distinct from the unit-aware duration or step-count transient accepted by `Simulator.run()`.
|
|
24
|
+
|
|
25
|
+
## Use a reusable objective
|
|
26
|
+
|
|
27
|
+
Every objective builder returns a JIT-, gradient-, and vmap-compatible callable over `(prediction, target)`.
|
|
28
|
+
|
|
29
|
+
| API | Description |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `brainmass.objectives.timeseries_rmse()` | Use for aligned time series; subtraction remains unit-checked before reduction. |
|
|
32
|
+
| `brainmass.objectives.fc_corr(as_loss=True)` | Use to minimize `1 - correlation` between static FC matrices derived from trajectories. |
|
|
33
|
+
| `brainmass.objectives.fc_rmse()` | Use to minimize RMSE between static FC matrices. |
|
|
34
|
+
| `brainmass.objectives.cosine_sim(as_loss=True, epsilon=...)` | Use for scale-insensitive flattened trajectory comparison. |
|
|
35
|
+
| `brainmass.objectives.fcd(window_size=..., step_size=..., as_loss=True)` | Use to compare FCD matrices when matrix correlation is the intended target. |
|
|
36
|
+
| `brainmass.objectives.fcd_wasserstein(...)` | Use for a smooth FCD-distribution distance in gradient-based fitting. |
|
|
37
|
+
| `brainmass.objectives.fcd_ks(...)` | Use for the literature-standard non-smooth KS FCD-distribution distance in evaluation or gradient-free fitting. |
|
|
38
|
+
| `brainmass.objectives.combine((weight, objective), ...)` | Use to sum explicitly weighted objective callables into one scalar loss. |
|
|
39
|
+
|
|
40
|
+
Scores such as `fc_corr`, `cosine_sim`, and `fcd` maximize by default. Pass `as_loss=True` before handing them to a minimizer.
|
|
41
|
+
|
|
42
|
+
For FCD distribution fitting, compare the off-diagonal distribution rather than the raw FCD matrix unless matrix correspondence is scientifically intended. Constant zero-variance signals make KDE-based distribution objectives singular and can return `nan`.
|
|
43
|
+
|
|
44
|
+
## Canonical `predict` plus `objective` workflow
|
|
45
|
+
|
|
46
|
+
This minimal workflow isolates the interface: `predict` runs the model, the objective compares its result with the target, and `Fitter` adds registered regularization.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import brainmass
|
|
50
|
+
import brainstate
|
|
51
|
+
import brainunit as u
|
|
52
|
+
import braintools
|
|
53
|
+
import jax.numpy as jnp
|
|
54
|
+
from brainstate.nn import Param
|
|
55
|
+
|
|
56
|
+
class Gain(brainstate.nn.Module):
|
|
57
|
+
def __init__(self):
|
|
58
|
+
super().__init__()
|
|
59
|
+
self.gain = Param(0.0, fit=True)
|
|
60
|
+
|
|
61
|
+
def update(self):
|
|
62
|
+
return self.gain.value()
|
|
63
|
+
|
|
64
|
+
def predict(model):
|
|
65
|
+
output = brainmass.Simulator(model, dt=0.1 * u.ms).run(
|
|
66
|
+
1.0 * u.ms,
|
|
67
|
+
monitors=None,
|
|
68
|
+
)["output"]
|
|
69
|
+
return jnp.mean(output)
|
|
70
|
+
|
|
71
|
+
fitter = brainmass.Fitter(
|
|
72
|
+
Gain(),
|
|
73
|
+
braintools.optim.Adam(lr=0.2),
|
|
74
|
+
predict=predict,
|
|
75
|
+
objective=brainmass.objectives.timeseries_rmse(),
|
|
76
|
+
)
|
|
77
|
+
result = fitter.fit(target=jnp.asarray(2.0), n_steps=60)
|
|
78
|
+
|
|
79
|
+
assert result.backend == "grad"
|
|
80
|
+
assert result.best_loss <= result.history[0]
|
|
81
|
+
assert "gain" in result.best_params
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For scientific use, make `predict` return the observation space that matches the target and validate it before optimization.
|
|
85
|
+
|
|
86
|
+
## Choose a backend
|
|
87
|
+
|
|
88
|
+
| Backend | Optimizer argument | Use when | `n_steps` means |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| `"grad"` | A `braintools.optim` optimizer, normally `Adam` first | The model and objective are differentiable; use this default whenever gradients are usable. | Gradient updates |
|
|
91
|
+
| `"nevergrad"` | Options dict or method string | The objective is discrete, black-box, noisy, rugged, or otherwise lacks a reliable gradient. | Generations |
|
|
92
|
+
| `"scipy"` | Options dict or method string | A few parameters suit a classical local, bounded, or derivative-free SciPy method. | Random restarts |
|
|
93
|
+
|
|
94
|
+
Gradient-free backends need a finite box for every fitted parameter. Derive it from a finite parameter transform such as `SigmoidT(low, high)` or pass `search_space={name: (low, high)}`.
|
|
95
|
+
|
|
96
|
+
Open `scripts/gradient-free-fitting.py` for the complete shared-objective workflow with Nevergrad differential evolution and SciPy Nelder-Mead. Do not implement gradient-free fitting as only a `backend=` substitution because bounds and optimizer arguments also change.
|
|
97
|
+
|
|
98
|
+
Open `scripts/eeg-fitting-with-gradients.py` when the task needs a complete Jansen-Rit workflow that constructs a phase-invariant EEG target, fits the connectivity parameter with gradients, and compares the recovered trace.
|
|
99
|
+
|
|
100
|
+
Open `brainstate/parameter-constraints-regularization.md` when a fitted
|
|
101
|
+
parameter needs a valid-domain transform, penalty, or modeling prior; that
|
|
102
|
+
reference routes to the exhaustive transform and regularizer catalog. Open
|
|
103
|
+
`braintools/parameter-initializer.md` when the starting value needs a reusable
|
|
104
|
+
initialization policy. Open `braintools/metric.md` only when a custom statistic
|
|
105
|
+
is not already owned by `brainmass.objectives`. Open
|
|
106
|
+
`braintools/optimizer.md` when choosing a gradient optimizer, schedule, or
|
|
107
|
+
standalone optimizer family beyond the canonical `Adam` example.
|
|
108
|
+
|
|
109
|
+
## Interpret `FitResult`
|
|
110
|
+
|
|
111
|
+
| Field | Meaning |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `backend` | Backend that produced the result. |
|
|
114
|
+
| `best_loss` | Lowest scalar loss observed. |
|
|
115
|
+
| `best_params` | Mapping of fitted parameter names to best constrained physical values. |
|
|
116
|
+
| `history` | Per-step loss for gradient fitting, per-candidate loss for Nevergrad, or best loss per SciPy restart. |
|
|
117
|
+
| `n_steps` | Iterations actually run, including early stopping. |
|
|
118
|
+
| `prediction` | Best prediction for the `predict` plus `objective` path; `None` for a custom `loss_fn`. |
|
|
119
|
+
| `optimizer` | Underlying optimizer object. |
|
|
120
|
+
| `raw` | Backend-specific result, such as SciPy's result object. |
|
|
121
|
+
| `model` | Fitted model restored to the best-seen parameters. |
|
|
122
|
+
|
|
123
|
+
Use `best_loss <= history[0]` only as a minimal optimization check. Also validate recovered parameter plausibility, held-out observables, units, stability, and identifiability.
|
|
124
|
+
|
|
125
|
+
## Callbacks and regularization
|
|
126
|
+
|
|
127
|
+
Callbacks receive `{"step", "loss", "best_loss", "model"}` once per gradient step. Return `True` to stop early; this documented early-stop behavior belongs to the gradient backend.
|
|
128
|
+
|
|
129
|
+
Use the `predict` plus `objective` path when model `reg_loss()` should be included automatically. When using `loss_fn`, add any intended regularization yourself.
|
|
130
|
+
|
|
131
|
+
## Diagnose fitting failures
|
|
132
|
+
|
|
133
|
+
- No trainables: confirm every intended parameter is `Param(..., fit=True)` and fixed parameters remain plain.
|
|
134
|
+
- Flat or zero gradient: validate the observable, scalar reduction, State reset, and differentiable boundaries before changing optimizers.
|
|
135
|
+
- Oscillatory loss: replace pointwise time-series error with amplitude, spectrum, FC, FCD, or another phase-appropriate summary.
|
|
136
|
+
- Unit mismatch: keep units through physical subtraction; strip magnitude only for scale-free metrics.
|
|
137
|
+
- `nan` FCD loss: inspect constant signals, window length, sample count, and KDE degeneracy.
|
|
138
|
+
- Derivative-free construction error: provide finite transform-derived or explicit bounds.
|
|
139
|
+
- Good training loss but poor science: evaluate held-out observables and parameter identifiability; a low scalar loss does not validate the model.
|
|
140
|
+
|
|
141
|
+
## Official sources
|
|
142
|
+
|
|
143
|
+
- `https://brainx.chaobrain.com/brainmass/reference/orchestration.html`
|
|
144
|
+
- `https://brainx.chaobrain.com/brainmass/tutorials/06_fitting_with_gradients.html`
|
|
145
|
+
- `https://brainx.chaobrain.com/brainmass/tutorials/07_gradient_free_fitting.html`
|
|
146
|
+
- `https://brainx.chaobrain.com/brainmass/howto/custom_objective.html`
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Forward and observation models
|
|
2
|
+
|
|
3
|
+
Use this reference when mapping simulated regional activity to BOLD, EEG, or MEG; choosing an HRF kernel or hemodynamic path; downsampling a trajectory; or validating lead-field shapes and units.
|
|
4
|
+
|
|
5
|
+
## Choose the measurement path
|
|
6
|
+
|
|
7
|
+
| API | Need | Important boundary |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `HRFBold` | Fast differentiable BOLD for fitting | Linear HRF convolution over a completed trajectory; prefer this canonical BOLD path for optimization. |
|
|
10
|
+
| `BOLDSignal` | Biophysical hemodynamic State | Four-State Balloon-Windkessel ODE; choose for flow, volume, and deoxyhemoglobin dynamics. |
|
|
11
|
+
| `TemporalAverage` | Anti-aliased temporal downsampling | Block-average non-overlapping windows and drop a trailing partial window. |
|
|
12
|
+
| `EEGLeadFieldModel` | Physically calibrated EEG | Preserve lead-field, dipole, and voltage units. |
|
|
13
|
+
| `MEGLeadFieldModel` | Physically calibrated MEG | Preserve lead-field, dipole, and magnetic-field units. |
|
|
14
|
+
| `LeadFieldModel` | Generic calibrated sensor projection | Configure the source scale, dipole unit, and sensor unit explicitly. |
|
|
15
|
+
| `LeadfieldReadout` | Learnable unitless sensor head | Learn the projection matrix end to end; do not present it as a calibrated physical lead field. |
|
|
16
|
+
|
|
17
|
+
Choose the observation before defining the objective. Hidden neural State and empirical sensor data are not interchangeable targets.
|
|
18
|
+
|
|
19
|
+
## Convolution BOLD
|
|
20
|
+
|
|
21
|
+
`HRFBold` temporally averages the neural drive, convolves it with a closed-form HRF, and decimates the result to `period`.
|
|
22
|
+
|
|
23
|
+
| API | Description |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `brainmass.HRFBold(period, downsample_period, kernel)` | Use for a trajectory-level neural-to-BOLD operator; pass the simulation `dt` at call time and receive time-major BOLD. |
|
|
26
|
+
| `brainmass.FirstOrderVolterraHRFKernel(...)` | Use for the TVB first-order Volterra underdamped kernel. |
|
|
27
|
+
| `brainmass.GammaHRFKernel(...)` | Use for a peak-normalized gamma HRF. |
|
|
28
|
+
| `brainmass.DoubleExponentialHRFKernel(...)` | Use for the documented difference of damped oscillations. |
|
|
29
|
+
| `brainmass.MixtureOfGammasHRFKernel(...)` | Use for the SPM-style difference-of-gammas HRF. |
|
|
30
|
+
| `brainmass.HRFKernel` | Subclass only when the required impulse response is absent; a kernel call returns dimensionless `h(t)`. |
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import brainmass
|
|
34
|
+
import brainunit as u
|
|
35
|
+
import jax.numpy as jnp
|
|
36
|
+
|
|
37
|
+
time = jnp.arange(2000.0)
|
|
38
|
+
neural = 1.0 + 0.5 * jnp.sin(
|
|
39
|
+
2.0 * jnp.pi * time[:, None] / 800.0
|
|
40
|
+
)
|
|
41
|
+
observer = brainmass.HRFBold(
|
|
42
|
+
period=200.0 * u.ms,
|
|
43
|
+
downsample_period=4.0 * u.ms,
|
|
44
|
+
kernel=brainmass.FirstOrderVolterraHRFKernel(
|
|
45
|
+
duration=400.0 * u.ms,
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
bold = observer(neural, dt=1.0 * u.ms)
|
|
49
|
+
|
|
50
|
+
assert bold.ndim == 2
|
|
51
|
+
assert bold.shape[1] == 1
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use a raw magnitude only where `HRFBold` expects a unitless neural trajectory. Preserve the original `dt` and region ordering as explicit metadata.
|
|
55
|
+
|
|
56
|
+
## Balloon-Windkessel BOLD
|
|
57
|
+
|
|
58
|
+
`BOLDSignal` evolves vasodilatory signal, blood flow, blood volume, and deoxyhemoglobin State before computing dimensionless BOLD.
|
|
59
|
+
|
|
60
|
+
| API | Description |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `brainmass.BOLDSignal(in_size, **hemodynamic_params)` | Use for the nonlinear biophysical path; size it to the source regions and initialize all State before stepping. |
|
|
63
|
+
| `BOLDSignal.update(z)` | Advance the hemodynamic State from one neural-drive sample. |
|
|
64
|
+
| `BOLDSignal.bold()` | Read the BOLD observation derived from the current hemodynamic State. |
|
|
65
|
+
|
|
66
|
+
The current documented tutorial drives this ODE with a dimensionless environment `dt` and restores the unit-aware neural `dt` afterward. Do not pass a time `Quantity` into that path without checking the installed release, because its RK2 update mixes numeric hemodynamic time with `dt`.
|
|
67
|
+
|
|
68
|
+
Discard a physiologically justified hemodynamic transient before comparison. Do not compare HRF-convolution and Balloon-Windkessel traces at exactly zero lag and treat the mismatch as an implementation error.
|
|
69
|
+
|
|
70
|
+
## Temporal averaging
|
|
71
|
+
|
|
72
|
+
| API | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `brainmass.TemporalAverage(period)` | Use to average non-overlapping windows of `round(period / dt)` samples; it preserves units and drops the trailing incomplete window. |
|
|
75
|
+
| `Simulator.run(..., sample_every=k)` | Use for point decimation when averaging is not required; it records every `k`th post-update value. |
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
signal = jnp.arange(20.0).reshape(20, 1)
|
|
79
|
+
averaged = brainmass.TemporalAverage(period=5.0 * u.ms)(
|
|
80
|
+
signal,
|
|
81
|
+
dt=1.0 * u.ms,
|
|
82
|
+
)
|
|
83
|
+
assert averaged.shape == (4, 1)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use temporal averaging when aliasing matters; do not describe point decimation as an average.
|
|
87
|
+
|
|
88
|
+
## EEG and MEG lead fields
|
|
89
|
+
|
|
90
|
+
A physical lead-field operator applies a matrix from regional dipole sources to sensor measurements while enforcing dimensional compatibility.
|
|
91
|
+
|
|
92
|
+
| API | Description |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `brainmass.LeadFieldModel(in_size, out_size, L, sensor_unit, dipole_unit, scale=...)` | Use for an explicitly configured physical projection; `scale` converts the source observable to dipole moment when needed. |
|
|
95
|
+
| `brainmass.EEGLeadFieldModel(in_size, out_size, L, sensor_unit=..., ...)` | Use for the EEG specialization, normally producing volts from a lead field in voltage per dipole moment. |
|
|
96
|
+
| `brainmass.MEGLeadFieldModel(...)` | Use for the MEG specialization when its installed signature matches the required magnetic units. |
|
|
97
|
+
| `brainmass.LeadfieldReadout(...)` | Use for a unitless trainable matrix with optional normalization; fit it as a model parameter rather than claiming physical calibration. |
|
|
98
|
+
|
|
99
|
+
Keep region and sensor axes consistent with the installed constructor. In the current tutorial, the lead field is shaped `(regions, sensors)` and a time-major source `(time, regions)` produces `(time, sensors)`.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import numpy as np
|
|
103
|
+
|
|
104
|
+
n_region, n_sensor = 4, 6
|
|
105
|
+
rng = np.random.RandomState(1)
|
|
106
|
+
lead_field = jnp.asarray(rng.rand(n_region, n_sensor)) * (
|
|
107
|
+
u.volt / (u.nA * u.meter)
|
|
108
|
+
)
|
|
109
|
+
eeg_model = brainmass.EEGLeadFieldModel(
|
|
110
|
+
in_size=(n_region,),
|
|
111
|
+
out_size=(n_sensor,),
|
|
112
|
+
L=lead_field,
|
|
113
|
+
sensor_unit=u.volt,
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Use a source observable that represents the intended modality, such as `JansenRitStep.eeg()` for a cortical EEG proxy. A lead field cannot correct an inappropriate neural source model.
|
|
118
|
+
|
|
119
|
+
## Validate an observation
|
|
120
|
+
|
|
121
|
+
- Confirm source shape `(time, regions)` and output shape `(time, sensors)` or `(time, regions)` for BOLD.
|
|
122
|
+
- Confirm sampling interval and transient separately for neural and observation stages.
|
|
123
|
+
- Confirm region labels remain aligned with connectome and lead-field rows.
|
|
124
|
+
- Confirm units at every physical projection and strip them only at documented array boundaries.
|
|
125
|
+
- Compare simulated and empirical data in the same modality, reference, sampling rate, and preprocessing space.
|
|
126
|
+
|
|
127
|
+
## Official sources
|
|
128
|
+
|
|
129
|
+
- `https://brainx.chaobrain.com/brainmass/reference/forward.html`
|
|
130
|
+
- `https://brainx.chaobrain.com/brainmass/reference/observation.html`
|
|
131
|
+
- `https://brainx.chaobrain.com/brainmass/tutorials/05_forward_models.html`
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# HORN task training
|
|
2
|
+
|
|
3
|
+
Use this reference when training a HORN network over minibatched sequence-task examples and evaluating a held-out metric. Do not use `Fitter`: `Fitter` targets one fixed prediction and target, while task training owns data batches, epochs, hidden-State reset, and validation.
|
|
4
|
+
|
|
5
|
+
## Choose the HORN abstraction
|
|
6
|
+
|
|
7
|
+
| API | Description |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `brainmass.HORNStep(...)` | Use when composing one explicit harmonic-oscillator recurrent update. |
|
|
10
|
+
| `brainmass.HORNSeqLayer(...)` | Use for one HORN layer that processes sequential input. |
|
|
11
|
+
| `brainmass.HORNSeqNetwork(n_input, n_hidden, n_output, alpha=..., omega=...)` | Use for the documented task-training path; it maps a time-major sequence to final output logits. |
|
|
12
|
+
| `brainmass.datasets.delayed_match_task(...)` | Use for the bundled delayed match-to-sample benchmark with `(sample, time, symbol)` inputs and binary targets. |
|
|
13
|
+
|
|
14
|
+
Use the constructor names from the installed release. Older HORN API material may show `in_size`, `hidden_sizes`, and `out_size`; the current official task workflow uses `n_input`, `n_hidden`, and `n_output`.
|
|
15
|
+
|
|
16
|
+
## Prepare task data
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import brainmass
|
|
20
|
+
import brainstate
|
|
21
|
+
import braintools
|
|
22
|
+
import brainunit as u
|
|
23
|
+
import jax
|
|
24
|
+
import jax.numpy as jnp
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
brainstate.environ.set(dt=1.0 * u.ms)
|
|
28
|
+
brainstate.random.seed(0)
|
|
29
|
+
|
|
30
|
+
inputs_np, targets_np = brainmass.datasets.delayed_match_task(
|
|
31
|
+
n_samples=320,
|
|
32
|
+
seq_len=8,
|
|
33
|
+
n_symbols=2,
|
|
34
|
+
seed=0,
|
|
35
|
+
)
|
|
36
|
+
inputs = jnp.asarray(inputs_np, dtype=jnp.float32)
|
|
37
|
+
targets = jnp.asarray(targets_np, dtype=jnp.int32)
|
|
38
|
+
|
|
39
|
+
n_train = 256
|
|
40
|
+
x_train, y_train = inputs[:n_train], targets[:n_train]
|
|
41
|
+
x_test, y_test = inputs[n_train:], targets[n_train:]
|
|
42
|
+
|
|
43
|
+
assert inputs.shape == (320, 8, 2)
|
|
44
|
+
assert targets.shape == (320,)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Create train and held-out splits before optimization. Do not report the training metric as generalization.
|
|
48
|
+
|
|
49
|
+
Open `braintools/cogtask.md` when a pre-built or custom phase-structured
|
|
50
|
+
cognitive paradigm should generate the trials. Open
|
|
51
|
+
`braintools/data-preprocessing.md` only when custom inputs must be encoded before
|
|
52
|
+
they enter HORN; the ordinary feature sequences above need no spike encoder.
|
|
53
|
+
|
|
54
|
+
## Build the classifier and reset hidden State
|
|
55
|
+
|
|
56
|
+
The network consumes `(time, batch, feature)`. Reset every HORN layer to the current batch shape before each forward pass so one batch cannot leak memory into the next.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
network = brainmass.HORNSeqNetwork(
|
|
60
|
+
n_input=inputs.shape[2],
|
|
61
|
+
n_hidden=64,
|
|
62
|
+
n_output=2,
|
|
63
|
+
alpha=0.2,
|
|
64
|
+
omega=2.0 * np.pi / 28.0,
|
|
65
|
+
)
|
|
66
|
+
brainstate.nn.init_all_states(network)
|
|
67
|
+
|
|
68
|
+
def reset_hidden(batch_size):
|
|
69
|
+
for layer in network.layers:
|
|
70
|
+
shape = (batch_size,) + tuple(layer.horn.in_size)
|
|
71
|
+
layer.horn.x.value = jnp.zeros(shape)
|
|
72
|
+
layer.horn.y.value = jnp.zeros(shape)
|
|
73
|
+
|
|
74
|
+
def logits(batch_inputs):
|
|
75
|
+
reset_hidden(batch_inputs.shape[0])
|
|
76
|
+
time_major = jnp.transpose(batch_inputs, (1, 0, 2))
|
|
77
|
+
return network(time_major)
|
|
78
|
+
|
|
79
|
+
weights = network.states(brainstate.ParamState)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Invariant:** reset hidden State for training and evaluation. A held-out evaluation that begins from training State is invalid.
|
|
83
|
+
|
|
84
|
+
Open `braintools/parameter-initializer.md` when HORN weights or model parameters
|
|
85
|
+
need a reusable variance-scaling, orthogonal, bounded, or unit-aware
|
|
86
|
+
initialization policy.
|
|
87
|
+
|
|
88
|
+
## Define and compile the training step
|
|
89
|
+
|
|
90
|
+
Register the same `ParamState` collection used as the gradient target. The current official HORN workflow applies gradients with `optimizer.step(grads)`.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
optimizer = braintools.optim.Adam(lr=3e-2)
|
|
94
|
+
optimizer.register_trainable_weights(weights)
|
|
95
|
+
|
|
96
|
+
def loss_and_accuracy(batch_inputs, batch_targets):
|
|
97
|
+
output = logits(batch_inputs)
|
|
98
|
+
log_probability = jax.nn.log_softmax(output, axis=-1)
|
|
99
|
+
loss = -jnp.mean(
|
|
100
|
+
log_probability[
|
|
101
|
+
jnp.arange(batch_targets.shape[0]),
|
|
102
|
+
batch_targets,
|
|
103
|
+
]
|
|
104
|
+
)
|
|
105
|
+
accuracy = jnp.mean(
|
|
106
|
+
jnp.argmax(output, axis=-1) == batch_targets
|
|
107
|
+
)
|
|
108
|
+
return loss, accuracy
|
|
109
|
+
|
|
110
|
+
@brainstate.transform.jit
|
|
111
|
+
def train_step(batch_inputs, batch_targets):
|
|
112
|
+
gradient = brainstate.transform.grad(
|
|
113
|
+
lambda: loss_and_accuracy(batch_inputs, batch_targets),
|
|
114
|
+
weights,
|
|
115
|
+
has_aux=True,
|
|
116
|
+
return_value=True,
|
|
117
|
+
)
|
|
118
|
+
gradients, loss, accuracy = gradient()
|
|
119
|
+
optimizer.step(gradients)
|
|
120
|
+
return loss, accuracy
|
|
121
|
+
|
|
122
|
+
@brainstate.transform.jit
|
|
123
|
+
def evaluate(batch_inputs, batch_targets):
|
|
124
|
+
return loss_and_accuracy(batch_inputs, batch_targets)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If the installed Braintools release exposes `optimizer.update(grads)` instead
|
|
128
|
+
of `step(grads)`, use the installed optimizer contract consistently; do not mix
|
|
129
|
+
methods in one loop. Open `braintools/optimizer.md` for optimizer and scheduler
|
|
130
|
+
selection, and `braintools/metric.md` for supervised loss, reduction, and
|
|
131
|
+
held-out metric selection.
|
|
132
|
+
|
|
133
|
+
## Run epochs and evaluate held-out data
|
|
134
|
+
|
|
135
|
+
Use a reproducible permutation policy and keep incomplete-batch handling explicit.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
n_epoch = 20
|
|
139
|
+
batch_size = 32
|
|
140
|
+
history = []
|
|
141
|
+
|
|
142
|
+
for epoch in range(n_epoch):
|
|
143
|
+
permutation = np.random.RandomState(epoch).permutation(n_train)
|
|
144
|
+
train_losses = []
|
|
145
|
+
train_accuracies = []
|
|
146
|
+
|
|
147
|
+
for start in range(0, n_train, batch_size):
|
|
148
|
+
index = permutation[start:start + batch_size]
|
|
149
|
+
if len(index) < batch_size:
|
|
150
|
+
continue
|
|
151
|
+
loss, accuracy = train_step(
|
|
152
|
+
x_train[index],
|
|
153
|
+
y_train[index],
|
|
154
|
+
)
|
|
155
|
+
train_losses.append(float(loss))
|
|
156
|
+
train_accuracies.append(float(accuracy))
|
|
157
|
+
|
|
158
|
+
_, test_accuracy = evaluate(x_test, y_test)
|
|
159
|
+
history.append({
|
|
160
|
+
"epoch": epoch,
|
|
161
|
+
"train_loss": float(np.mean(train_losses)),
|
|
162
|
+
"train_accuracy": float(np.mean(train_accuracies)),
|
|
163
|
+
"test_accuracy": float(test_accuracy),
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Validate that chance-level accuracy, label balance, loss reduction, and held-out improvement are all consistent with the task. A final accuracy alone does not reveal leakage or class imbalance.
|
|
168
|
+
|
|
169
|
+
Open `scripts/horn-cognitive-task-training.py` when the task needs the complete delayed-match dataset, HORN network, compiled training loop, held-out evaluation, and learning curves.
|
|
170
|
+
|
|
171
|
+
## Choose task-training variations
|
|
172
|
+
|
|
173
|
+
- Use another `brainmass.datasets` generator or a validated external loader for a different task.
|
|
174
|
+
- Keep sequence inputs time-major inside the network even when storage is sample-major.
|
|
175
|
+
- Add a learning-rate scheduler only after the fixed-rate baseline trains correctly.
|
|
176
|
+
- Clip gradients only after confirming large or non-finite gradients.
|
|
177
|
+
- Tune oscillator `alpha`, `omega`, damping, and hidden size one decision at a time.
|
|
178
|
+
- Use direct Braintools metrics when the held-out criterion is not accuracy.
|
|
179
|
+
- Open `brainstate/parameter-constraints-regularization.md` when a directly
|
|
180
|
+
trained oscillator parameter needs a valid domain, penalty, or prior.
|
|
181
|
+
- Open `braintools/surrogate.md` only when a custom path introduces a hard
|
|
182
|
+
threshold or spike; canonical HORN training does not need a surrogate.
|
|
183
|
+
|
|
184
|
+
## Common failures
|
|
185
|
+
|
|
186
|
+
- Sending task training through `Fitter`.
|
|
187
|
+
- Omitting hidden-State reset between batches or between training and evaluation.
|
|
188
|
+
- Feeding `(batch, time, feature)` directly to a time-major HORN network.
|
|
189
|
+
- Collecting all `State` instead of only `ParamState` as trainable.
|
|
190
|
+
- Re-registering optimizer weights inside every compiled step.
|
|
191
|
+
- Using raw `jax.grad` or `jax.jit` around State-aware code.
|
|
192
|
+
- Reporting only training accuracy.
|
|
193
|
+
- Changing optimizer, loss, HORN dynamics, and reset policy simultaneously.
|
|
194
|
+
|
|
195
|
+
## Official sources
|
|
196
|
+
|
|
197
|
+
- `https://brainx.chaobrain.com/brainmass/reference/horn.html`
|
|
198
|
+
- `https://brainx.chaobrain.com/brainmass/tutorials/08_training_on_tasks.html`
|
|
199
|
+
- `https://brainx.chaobrain.com/brainmass/gallery/case_studies/horn_cognitive_task.html`
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# BrainMass model library
|
|
2
|
+
|
|
3
|
+
Use this reference when selecting a public BrainMass model, comparing dynamical cost, identifying its primary observable, or distinguishing variants with similar names. Return to `skills/brainmass/SKILL.md` after selection for the canonical `Simulator` workflow.
|
|
4
|
+
|
|
5
|
+
## Inspect the public catalogue
|
|
6
|
+
|
|
7
|
+
| API | Description |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `brainmass.list_models()` | Return one `ModelInfo` record per public model, including user-facing HORN and network models. |
|
|
10
|
+
| `brainmass.list_models.to_table()` | Format the current catalogue for quick REPL inspection without hard-coding the inventory. |
|
|
11
|
+
| `brainmass.ModelInfo(name, category, n_state_vars, use_case)` | Represent one immutable catalogue entry for filtering and routing. |
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import brainmass
|
|
15
|
+
|
|
16
|
+
models = brainmass.list_models()
|
|
17
|
+
cheap_physiological = [
|
|
18
|
+
model
|
|
19
|
+
for model in models
|
|
20
|
+
if model.category == "physiological" and model.n_state_vars <= 3
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
assert any(model.name == "WilsonCowanStep" for model in cheap_physiological)
|
|
24
|
+
assert next(
|
|
25
|
+
model for model in models if model.name == "JansenRitStep"
|
|
26
|
+
).n_state_vars == 6
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Use `list_models()` as the authority for the installed release. The table below is the source-documented inventory used by this skill, not a substitute for runtime discovery.
|
|
30
|
+
|
|
31
|
+
## Model inventory
|
|
32
|
+
|
|
33
|
+
Start with the cheapest model that represents the required regime, timescale, and observable. Add physiological detail only when it changes the scientific comparison; an optimizer cannot repair a mismatched model or measurement path.
|
|
34
|
+
|
|
35
|
+
| Model | Category | State variables | Use and boundary |
|
|
36
|
+
|---|---|---:|---|
|
|
37
|
+
| `HopfStep` | Phenomenological | 2 | Use as the cheap default for oscillation onset and rhythms; `a` crosses the supercritical Hopf bifurcation. |
|
|
38
|
+
| `VanDerPolStep` | Phenomenological | 2 | Use for nonlinear relaxation oscillations rather than near-Hopf amplitude dynamics. |
|
|
39
|
+
| `StuartLandauStep` | Phenomenological | 2 | Use when explicit amplitude and phase behavior matter beyond the canonical Hopf workflow. |
|
|
40
|
+
| `FitzHughNagumoStep` | Phenomenological | 2 | Use for fast-slow excitable population events, not conductance-based point neurons. |
|
|
41
|
+
| `ThresholdLinearStep` | Phenomenological | 2 | Use for fast threshold-linear E/I responses without a detailed physiological mechanism. |
|
|
42
|
+
| `Generic2dOscillatorStep` | Phenomenological | 2 | Use for configurable planar TVB dynamics when the fixed oscillator forms are too restrictive. |
|
|
43
|
+
| `LorenzStep` | Phenomenological | 3 | Use for chaos studies or as a nonlinear coupling test fixture. |
|
|
44
|
+
| `LinearStep` | Phenomenological | 1 | Use as an analytically simple baseline before diagnosing integration or coupling in a complex model. |
|
|
45
|
+
| `WilsonCowanStep` | Physiological | 2 | Use as the canonical physiological two-population E/I firing-rate model. |
|
|
46
|
+
| `JansenRitStep` | Physiological | 6 | Use for EEG and alpha-rhythm cortical columns; compare the derived `eeg()` observable. |
|
|
47
|
+
| `WongWangStep` | Physiological | 2 | Use the reduced `S1`/`S2` competing-population model for perceptual decisions. |
|
|
48
|
+
| `WongWangExcInhStep` | Physiological | 2 | Use the `S_E`/`S_I` model for resting-state BOLD, FC, or local E/I balance; it is not `WongWangStep`. |
|
|
49
|
+
| `MontbrioPazoRoxinStep` | Physiological | 2 | Use when firing rate and mean membrane potential must follow the exact QIF mean-field reduction. |
|
|
50
|
+
| `CoombesByrneStep` | Physiological | 2 | Use when synaptic conductance belongs explicitly in a next-generation mean-field model. |
|
|
51
|
+
| `LarterBreakspearStep` | Physiological | 3 | Use for conductance-based cortical limit cycles and chaotic dynamics. |
|
|
52
|
+
| `EpileptorStep` | Physiological | 6 | Use for seizure onset and offset; `x0` controls epileptogenicity and `lfp()` provides the proxy. |
|
|
53
|
+
| `KuramotoNetwork` | Network | 1 | Use when phase is the modeled State and synchronization order is the main summary. |
|
|
54
|
+
| `HORNStep` | Network | 2 | Use for one explicit harmonic-oscillator recurrent update. |
|
|
55
|
+
| `HORNSeqLayer` | Network | 2 | Use when composing one sequential HORN layer inside a larger model. |
|
|
56
|
+
| `HORNSeqNetwork` | Network | 2 | Use for oscillatory sequence learning; open `horn-task-training.md` instead of `Fitter`. |
|
|
57
|
+
|
|
58
|
+
## Validate a candidate
|
|
59
|
+
|
|
60
|
+
Use the uniform `Simulator` call to compare candidates under the same duration, `dt`, transient, and number of regions. Compare the actual scientific observable, not arbitrary internal State.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import brainunit as u
|
|
64
|
+
|
|
65
|
+
jansen_rit = brainmass.JansenRitStep(in_size=8)
|
|
66
|
+
result = brainmass.Simulator(jansen_rit, dt=0.1 * u.ms).run(
|
|
67
|
+
400.0 * u.ms,
|
|
68
|
+
monitors=lambda model: model.eeg(),
|
|
69
|
+
transient=100.0 * u.ms,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
assert result["output"].shape == (3000, 8)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Use `JansenRitTR` only when its internal substep-to-TR behavior is explicitly required. Instantiate concrete model classes rather than shared bases such as `XY_Oscillator` or `WilsonCowanThreePopBase`.
|
|
76
|
+
|
|
77
|
+
## Application scripts
|
|
78
|
+
|
|
79
|
+
Open only the script that matches the selected model or scientific regime.
|
|
80
|
+
|
|
81
|
+
| Script | Open when |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `scripts/hopf-bifurcation-single-node.py` | Demonstrating oscillation onset across the Hopf bifurcation or checking settled amplitude against `sqrt(a)`. |
|
|
84
|
+
| `scripts/wilson-cowan-ei-dynamics.py` | Simulating E/I population rates, their phase portrait, or an excitatory-drive sweep. |
|
|
85
|
+
| `scripts/jansen-rit-eeg-proxy.py` | Simulating the Jansen-Rit EEG proxy, its spectrum, or an input-rate sweep. |
|
|
86
|
+
| `scripts/seizure-epileptor-case-study.py` | Comparing healthy and seizure-like Epileptor regimes across epileptogenicity `x0`. |
|
|
87
|
+
| `scripts/wong-wang-decision-making.py` | Running stochastic competing-population decisions or estimating a psychometric curve. |
|
|
88
|
+
| `scripts/kuramoto-synchronization.py` | Measuring synchronization through the Kuramoto order parameter while varying coupling strength. |
|
|
89
|
+
| `scripts/wong-wang-dmf-resting-state.py` | Inspecting resting excitatory rate and gating in the Wong-Wang excitatory-inhibitory dynamic mean-field model. |
|
|
90
|
+
| `scripts/linear-baseline-node.py` | Checking integration against the analytical linear decay before diagnosing a more complex model. |
|
|
91
|
+
|
|
92
|
+
## Common selection failures
|
|
93
|
+
|
|
94
|
+
- Choosing a complex six-State model before a cheap model establishes the regime.
|
|
95
|
+
- Treating `WongWangStep` and `WongWangExcInhStep` as interchangeable.
|
|
96
|
+
- Fitting a BOLD target without a suitable slow neural source and hemodynamic observation model.
|
|
97
|
+
- Treating a neural-mass model as a point-neuron or cellular model.
|
|
98
|
+
- Assuming the inventory from this file supersedes `list_models()` in another installed release.
|
|
99
|
+
|
|
100
|
+
## Official sources
|
|
101
|
+
|
|
102
|
+
- `https://brainx.chaobrain.com/brainmass/reference/models.html`
|
|
103
|
+
- `https://brainx.chaobrain.com/brainmass/reference/utilities.html`
|
|
104
|
+
- `https://brainx.chaobrain.com/brainmass/howto/choose_a_model.html`
|