brainx-skill 1.0.11 → 1.0.13
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 +4 -0
- package/installation/lib/bundle.js +51 -13
- package/manifest.json +2 -0
- package/mcp-servers/codex/README.md +62 -0
- package/mcp-servers/codex/UPSTREAM.md +20 -0
- package/mcp-servers/codex/server.mjs +140 -0
- package/mcp-servers/codex/skills.json +10 -0
- package/mcp-servers/codex/system-prompt.md +62 -0
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +6 -0
- package/mcp-servers/codex/test/server.test.mjs +88 -0
- package/package.json +6 -9
- package/skills/brainx-acceleration/SKILL.md +459 -0
- package/skills/brainx-general-guard/SKILL.md +67 -37
- package/skills/brainx-install/SKILL.md +21 -24
- package/skills/brainx-modeling-loop/SKILL.md +268 -0
- package/skills/brainx-modeling-loop/agents/openai.yaml +4 -0
- package/skills/brainx-modeling-loop/references/monitor-experiment.md +49 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow/scripts/fitting_hh_neuron.py +254 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +232 -0
- package/skills/brainx-modeling-loop/references/run-experiment.md +179 -0
- package/skills/brainx-modeling-loop/references/training-workflow.md +270 -0
- package/skills/{braincell → package-skills/braincell}/SKILL.md +3 -16
- package/skills/{braincell → package-skills/braincell}/references/mixions-for-adaptation.md +26 -3
- package/skills/{braincell → package-skills/braincell}/references/multicompartment/multicompartment-cell-workflow.md +2 -2
- package/skills/package-skills/braincell/references/scripts/fitting_hh_neuron.py +254 -0
- package/skills/package-skills/braincell/references/scripts/spike_frequency_adaptation.py +135 -0
- package/skills/{brainevent → package-skills/brainevent}/SKILL.md +0 -1
- package/skills/package-skills/brainevent/references/synaptic-plasticity.md +129 -0
- package/skills/{brainmass → package-skills/brainmass}/SKILL.md +10 -5
- package/skills/{brainmass → package-skills/brainmass}/references/batch-transform-acceleration.md +44 -3
- package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-constraints-regularization.md +1 -1
- package/skills/{brainmass → package-skills/brainmass}/references/coupling-network-api.md +121 -3
- package/skills/{brainmass → package-skills/brainmass}/references/modellibrary.md +90 -1
- package/skills/package-skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +188 -0
- package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +98 -0
- package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md +6 -6
- package/skills/{brainpy-state → package-skills/brainpy-state}/SKILL.md +17 -8
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/brain-dynamics-delay-protocol.md +52 -1
- package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +206 -0
- package/skills/package-skills/brainpy-state/references/braintools/input-current.md +199 -0
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/component-selection.md +20 -5
- package/skills/package-skills/brainpy-state/references/perturbation-experiment-validity.md +76 -0
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/projection-patterns.md +3 -1
- package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +240 -0
- package/skills/{brainstate → package-skills/brainstate}/SKILL.md +12 -15
- package/skills/package-skills/brainstate/agents/openai.yaml +4 -0
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-constraints-regularization.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/randomness-and-reproducibility.md +1 -1
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-grad-expansion.md +2 -2
- package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-vmap-expansion.md +58 -8
- package/skills/{brainstate → package-skills/brainstate}/references/collective_model_operations.md +26 -27
- package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/paired-perturbation-execution.md +113 -0
- package/skills/package-skills/braintrace/SKILL.md +187 -0
- package/skills/package-skills/braintrace/references/Drtrl.md +133 -0
- package/skills/{braintrace → package-skills/braintrace}/references/ETP operators.md +31 -4
- package/skills/package-skills/braintrace/references/algorithm selection.md +64 -0
- package/skills/package-skills/braintrace/references/batching.md +140 -0
- package/skills/{braintrace → package-skills/braintrace}/references/compiler_internal.md +2 -2
- package/skills/{braintrace → package-skills/braintrace}/references/custom algorithms.md +8 -10
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +179 -0
- package/skills/{braintrace → package-skills/braintrace}/references/pre-built-braintrace-layer.md +2 -2
- package/skills/{brainpy-state → package-skills/brainunit}/references/array-creation.md +2 -2
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +0 -75
- package/skills/brainevent/references/synaptic-plasticity.md +0 -285
- package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +0 -130
- package/skills/brainstate/references/braintools/optimizer.md +0 -179
- package/skills/braintrace/SKILL.md +0 -161
- package/skills/braintrace/references/Drtrl.md +0 -179
- package/skills/braintrace/references/algorithm selection.md +0 -120
- package/skills/braintrace/references/batching.md +0 -150
- package/skills/braintrace/references/pp_pprop workflow.md +0 -196
- /package/skills/{braincell → package-skills/braincell}/references/area-scaled-hh-pattern.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/braincell-custom-ion-channel-authoring.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/channel-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/ion-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/braincell-manual-morphology-construction.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/cv-policy-reference.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/filter-function-library.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/morphology-io-loading-validation.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/probe-reference.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/multicompartment/topology-building-and-visualization.md +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/calcium_channel_gating.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/cell_multicompartment_reference.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/channel_ablation.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/fi_curve.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/hh_neuron_basics.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/t_current_rebound.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/scripts/thalamic_neurons.py +0 -0
- /package/skills/{braincell → package-skills/braincell}/references/solver-library-with-effects.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/connectivity-variants.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-cpu.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-gpu.md +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/102_EI_net_1996.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/204_joglekar_2018_propagation.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/scripts/coba_ei_teaching.py +0 -0
- /package/skills/{brainevent → package-skills/brainevent}/references/sparse-formats.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/cogtask.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/data-preprocessing.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/metric.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/optimizer.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/parameter-initializer.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/braintools/surrogate.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/datasets-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/fitting-with-objectives-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/forward-observation-api.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/horn-task-training.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/noiseprocesses.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/eeg-fitting-with-gradients.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/gradient-free-fitting.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/hopf-bifurcation-single-node.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/horn-cognitive-task-training.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/jansen-rit-eeg-proxy.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/kuramoto-synchronization.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/linear-baseline-node.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/resting-state-meg-whole-brain-pipeline.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/seizure-epileptor-case-study.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wilson-cowan-ei-dynamics.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-decision-making.py +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-dmf-resting-state.py +0 -0
- /package/skills/{brainunit → package-skills/brainpy-state}/references/array-creation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/analysis.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/brainpy legacy workflow.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/connecting neurons.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/customize neuron and synpase.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Input generation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/delays.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/integrators.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/route activity through connectivity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synaptic projections.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synpase properties.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/loss library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/optimizers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/parameter initializers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/surrogate gradients.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainer library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainingworkflows.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/brainstate-control-flow-patterns.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/data-preprocessing.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/metric.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/optimizer.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/parameter-initializer.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/surrogate.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/devices.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/divergence-and-parity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/integration-categories.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/model-library.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/nest-workflow.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/network-building.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brette_et_al_2007.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_alpha.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_delta.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/spatial_gaussex.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/synapsecollection.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/synapse-and-connectivity.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/103_COBA_2005.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/106_COBA_HH_2007.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/107_gamma_oscillation_1996.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/109_fast_global_oscillation.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/training-snn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-jit-expansion.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/extension_mechanisms.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-activation-library.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/model-interop-and-migration.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/simulation-environment.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/size-inference-variations.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/state-graph-operations.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/state_collections_and_utilities.md +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/integrator_rnn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/lif_neuron_model.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/modern_cnn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/scripts/resnet.py +0 -0
- /package/skills/{braintrace → package-skills/braintrace}/references/custom ETP primitives.md +0 -0
- /package/skills/{braintrace → package-skills/braintrace}/references/customizing_primitive_transforms.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/SKILL.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics/functional-structural-api.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/math-function-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/physical-constant-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/prefix-library.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/quantity-inspection-and-conversion.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/typing-and-runtime-validation.md +0 -0
- /package/skills/{brainunit → package-skills/brainunit}/references/unit-structure-and-definition.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Coupling and network API
|
|
2
2
|
|
|
3
|
-
Use this reference when configuring structural connectivity, delays, coupling families, self-connections, network-level noise, trainable coupling parameters, or direct coupling objects. Use `brainmass.Network` unless custom wiring
|
|
3
|
+
Use this reference when configuring structural connectivity, delays, coupling families, self-connections, network-level noise, trainable coupling parameters, or direct coupling objects. Use `brainmass.Network` unless custom wiring or an independent drive on the coupled input channel requires direct composition.
|
|
4
4
|
|
|
5
5
|
## Construct the network
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Use this reference when configuring structural connectivity, delays, coupling fa
|
|
|
10
10
|
|---|---|
|
|
11
11
|
| `brainmass.Network(node, *, conn, distance=None, speed=None, coupling="diffusive", coupled_var, k=1.0, delay_init=..., self_connection=False, noise=None)` | Use for the high-level whole-brain path; it validates `coupled_var`, constructs delays and coupling, and exposes the wrapped dynamics as `.node`. |
|
|
12
12
|
| `Network.init_state(...)` | Use indirectly through `Simulator`; it initializes the node, coupling, delay history, and optional network noise. |
|
|
13
|
-
| `Network.update(*node_inputs)` | Use for one custom step; it
|
|
13
|
+
| `Network.update(*node_inputs)` | Use for one custom step; it inserts coupling plus optional noise as the node's first positional input, forwards `node_inputs` after it, and returns the node update result. |
|
|
14
14
|
| `brainmass.Simulator(network, dt=...)` | Use for the canonical execution path; monitor wrapped State through `network.node`. |
|
|
15
15
|
|
|
16
16
|
```python
|
|
@@ -43,6 +43,18 @@ assert result["output"].shape == (3000, n_region)
|
|
|
43
43
|
|
|
44
44
|
**Invariant:** set global `dt` before constructing a delayed network and use the same value in `Simulator`. The delay buffer is sized at construction.
|
|
45
45
|
|
|
46
|
+
### Route coupling and external inputs
|
|
47
|
+
|
|
48
|
+
Choose the path from the node's positional input contract.
|
|
49
|
+
|
|
50
|
+
| Need | Use |
|
|
51
|
+
|---|---|
|
|
52
|
+
| Coupling alone on the first node input | `Network`; do not pass another input. |
|
|
53
|
+
| Coupling on the first input plus an independent drive on the second or later input | `Network`; pass the drive through `Simulator.run(inputs=...)`, which `Network.update()` forwards after coupling. |
|
|
54
|
+
| Coupling plus an independent drive summed on the same first input | Direct composition; retrieve the delayed source, call the functional coupling kernel, add the drive, and pass the sum to the node. |
|
|
55
|
+
|
|
56
|
+
Do not expect a caller-supplied first value to be added to `Network` coupling. It becomes the node's second positional input.
|
|
57
|
+
|
|
46
58
|
## Preserve connectivity semantics
|
|
47
59
|
|
|
48
60
|
Use the convention `W[i, j] = source j -> target i`. Each row therefore contains the incoming weights for one target.
|
|
@@ -98,7 +110,7 @@ Use the `Network` string selector for standard defaults. Construct a coupling cl
|
|
|
98
110
|
|
|
99
111
|
Start with normalized or otherwise scientifically calibrated weights and a modest `k`. Changing weight normalization changes the meaning of `k`.
|
|
100
112
|
|
|
101
|
-
##
|
|
113
|
+
## Compose custom source and target wiring
|
|
102
114
|
|
|
103
115
|
Use direct construction only when a built-in `Network` cannot represent the source/target wiring. A diffusive coupling requires one delayed `(target, source)` read and one current target read.
|
|
104
116
|
|
|
@@ -127,6 +139,112 @@ coupling = brainmass.DiffusiveCoupling(
|
|
|
127
139
|
|
|
128
140
|
Do not replace the delay prefetch protocol with a manually shifted Python container.
|
|
129
141
|
|
|
142
|
+
## Vary delay with a same-channel drive
|
|
143
|
+
|
|
144
|
+
Use a fixed-capacity `brainstate.nn.Delay` when mapped conditions vary retrieval delay while State shape must remain static; construct it under the final `dt`, insert the current source once per step, then retrieve the declared integer offset.
|
|
145
|
+
|
|
146
|
+
| API | Description |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `brainstate.nn.Delay(target_info, time=max_delay, init=...)` | Use for package-owned short-term history with capacity fixed by `max_delay`; construct it while the rollout's `dt` is active and initialize the intended prehistory explicitly. |
|
|
149
|
+
| `Delay.update(current)` | Use exactly once at the start of each model step to insert the source State at the current simulation time. |
|
|
150
|
+
| `Delay.retrieve_at_step(delay_steps)` | Use after insertion with a scalar or traced integer offset no greater than the fixed capacity; step 0 is current and step `d` is exactly `d` completed updates earlier. |
|
|
151
|
+
| `brainmass.<coupling>_coupling(...)` | Use the functional kernel to compute coupling before adding an independent same-channel drive. |
|
|
152
|
+
|
|
153
|
+
Initialize delay history from the intended pre-run source State, not from an
|
|
154
|
+
arbitrary numeric zero. For diffusive coupling, startup history should reproduce
|
|
155
|
+
the source baseline that the current target sees; a homogeneous equilibrium then
|
|
156
|
+
produces zero startup current. If no defensible prehistory exists, warm up the
|
|
157
|
+
same model and coupling path and exclude the warm-up from classification. Verify
|
|
158
|
+
the first retrieved value and resulting coupling current before interpreting
|
|
159
|
+
timing.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import brainmass
|
|
163
|
+
import brainstate
|
|
164
|
+
import braintools
|
|
165
|
+
import brainunit as u
|
|
166
|
+
import jax.numpy as jnp
|
|
167
|
+
|
|
168
|
+
dt = 0.1 * u.ms
|
|
169
|
+
max_delay = 12.0 * u.ms
|
|
170
|
+
conn = jnp.asarray([
|
|
171
|
+
[0.0, 0.0, 0.0],
|
|
172
|
+
[1.0, 0.0, 0.0],
|
|
173
|
+
[0.0, 1.0, 0.0],
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class DrivenChain(brainstate.nn.Module):
|
|
178
|
+
def __init__(self):
|
|
179
|
+
super().__init__()
|
|
180
|
+
self.node = brainmass.FitzHughNagumoStep(
|
|
181
|
+
in_size=3,
|
|
182
|
+
init_V=braintools.init.Constant(0.0),
|
|
183
|
+
init_w=braintools.init.Constant(0.0),
|
|
184
|
+
)
|
|
185
|
+
self.history = brainstate.nn.Delay(
|
|
186
|
+
jnp.zeros(3),
|
|
187
|
+
time=max_delay,
|
|
188
|
+
init=braintools.init.Constant(0.0),
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
def update(self, stimulus, k, delay):
|
|
192
|
+
self.history.update(self.node.V.value)
|
|
193
|
+
delay_steps = jnp.rint(delay / dt).astype(jnp.int32)
|
|
194
|
+
delayed = self.history.retrieve_at_step(delay_steps)
|
|
195
|
+
sources = jnp.broadcast_to(delayed, conn.shape)
|
|
196
|
+
current = brainmass.additive_coupling(sources, conn, k)
|
|
197
|
+
return self.node(current + stimulus)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def run_condition(k, delay):
|
|
201
|
+
with brainstate.environ.context(dt=dt):
|
|
202
|
+
model = DrivenChain()
|
|
203
|
+
brainstate.nn.init_all_states(model)
|
|
204
|
+
indices = jnp.arange(200)
|
|
205
|
+
|
|
206
|
+
def step(i):
|
|
207
|
+
stimulus = jnp.where(
|
|
208
|
+
i < 20,
|
|
209
|
+
jnp.asarray([0.5, 0.0, 0.0]),
|
|
210
|
+
jnp.zeros(3),
|
|
211
|
+
)
|
|
212
|
+
with brainstate.environ.context(i=i, t=i * dt):
|
|
213
|
+
return model(stimulus, k, delay)
|
|
214
|
+
|
|
215
|
+
return brainstate.transform.for_loop(step, indices)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
traces = brainstate.transform.vmap(run_condition)(
|
|
219
|
+
jnp.asarray([0.2, 0.4]),
|
|
220
|
+
jnp.asarray([4.0, 8.0]) * u.ms,
|
|
221
|
+
)
|
|
222
|
+
assert traces.shape == (2, 200, 3)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Keep `max_delay` static. Constructing `Network` or `Delay` with a mapped delay can make buffer capacity depend on a tracer and fail during shape allocation. Map the complete independent condition, vary only the integer retrieval step, and preserve the same `dt` across construction, initialization, and execution.
|
|
226
|
+
|
|
227
|
+
Lock the phase convention with an impulse check before interpreting neural output:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
with brainstate.environ.context(dt=1.0 * u.ms):
|
|
231
|
+
delay = brainstate.nn.Delay(jnp.zeros(()), time=3.0 * u.ms)
|
|
232
|
+
brainstate.nn.init_all_states(delay)
|
|
233
|
+
|
|
234
|
+
def delayed_impulse(value):
|
|
235
|
+
delay.update(value)
|
|
236
|
+
return delay.retrieve_at_step(jnp.asarray(3, dtype=jnp.int32))
|
|
237
|
+
|
|
238
|
+
observed = brainstate.transform.for_loop(
|
|
239
|
+
delayed_impulse,
|
|
240
|
+
jnp.asarray([1.0, 0.0, 0.0, 0.0, 0.0]),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
assert jnp.array_equal(observed, jnp.asarray([0.0, 0.0, 0.0, 1.0, 0.0]))
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
If retrieval occurs before insertion, the buffer still ends at the previous simulation time and the same integer offset shifts the physical delay by one `dt`. Do not compensate with an unexplained `delay_steps - 1`; keep one call order and verify it directly.
|
|
247
|
+
|
|
130
248
|
## Application script
|
|
131
249
|
|
|
132
250
|
Open `scripts/resting-state-meg-whole-brain-pipeline.py` when the task needs the complete connectome-to-network-to-MEG-to-functional-connectivity workflow.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BrainMass model library
|
|
2
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.
|
|
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/package-skills/brainmass/SKILL.md` after selection for the canonical `Simulator` workflow.
|
|
4
4
|
|
|
5
5
|
## Inspect the public catalogue
|
|
6
6
|
|
|
@@ -74,6 +74,93 @@ assert result["output"].shape == (3000, 8)
|
|
|
74
74
|
|
|
75
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
76
|
|
|
77
|
+
## Choose an inhibitory intervention
|
|
78
|
+
|
|
79
|
+
Match the intervention to the model's equations; similarly named inhibitory parameters do not represent the same mechanism or unit.
|
|
80
|
+
|
|
81
|
+
| API | Description |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `JansenRitStep(Ai=...)` | Use for inhibitory postsynaptic gain in an alpha/EEG cortical column; `Ai` is measured in mV and scales the inhibitory-population filter, so lowering it weakens the inhibitory postsynaptic potential represented in `eeg() = E - I`. |
|
|
84
|
+
| `WilsonCowanStep(wEI=...)` | Use for inhibitory feedback onto the excitatory rate population; `wEI` is dimensionless I-to-E coupling and enters the excitatory equation subtractively, so lowering it weakens that coupling. |
|
|
85
|
+
|
|
86
|
+
Change only the selected inhibitory parameter in a matched causal comparison. Treat defaults and source-documented estimation ranges as context, not as evidence for a chosen intervention magnitude. Label an unsourced, outcome-tuned, or outside-range value as phenomenological and show nearby sensitivity before claiming a robust regime change.
|
|
87
|
+
|
|
88
|
+
## Choose an Epileptor focus and input path
|
|
89
|
+
|
|
90
|
+
Use `x0` to represent autonomous regional epileptogenicity; use `x1_inp` or `x2_inp` only when the scientific intervention or network current is an input, and enable the corresponding gain explicitly.
|
|
91
|
+
|
|
92
|
+
| API | Description |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `EpileptorStep(x0=...)` | Use a region-wise value to distinguish an epileptogenic focus from healthier tissue; less-negative `x0` increases epileptogenicity, while more-negative values render a region healthy. |
|
|
95
|
+
| `EpileptorStep(Kvf=..., Ks=...)` | Use when `x1_inp` should affect the fast `x1` subsystem and/or slow `z` recruitment path; `Kvf` scales its effect on `x1`, `Ks` scales its effect on `z`, and both default to zero. |
|
|
96
|
+
| `EpileptorStep(Kf=...)` | Use when `x2_inp` should affect the ultra-slow `x2` subsystem; `Kf` scales that input and defaults to zero. |
|
|
97
|
+
| `EpileptorStep.update(x1_inp=None, x2_inp=None)` | Use for one explicit step with population-specific coupling or external inputs; an input has no deterministic effect through a gain left at its zero default. |
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import jax.numpy as jnp
|
|
101
|
+
|
|
102
|
+
epileptor = brainmass.EpileptorStep(
|
|
103
|
+
in_size=3,
|
|
104
|
+
x0=jnp.asarray([-1.6, -2.4, -2.4]),
|
|
105
|
+
Kvf=0.5,
|
|
106
|
+
Ks=0.1,
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
This construction represents one autonomous focus and enables a first-channel network current to affect both fast activity and the slow permittivity path. Set only the gains required by the declared mechanism. Do not conclude that Epileptor lacks driven inputs from a trial that leaves `Kvf`, `Kf`, and `Ks` at zero.
|
|
111
|
+
|
|
112
|
+
## Extend Wong-Wang population currents
|
|
113
|
+
|
|
114
|
+
Use stock `update()` for bounded sensory evidence; compose the public current, transfer, derivative, and integration APIs only when a mechanism adds a distinct population-specific current.
|
|
115
|
+
|
|
116
|
+
| API | Description |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `WongWangStep.update(coherence=...)` | Use for one standard decision step; `coherence` is motion evidence in `[-1, 1]`, not an arbitrary current. |
|
|
119
|
+
| `WongWangStep.compute_inputs(coherence=..., noise_1_val=..., noise_2_val=...)` | Use when extending the current path; it combines valid coherence and actual stochastic currents and returns total population currents `I1` and `I2`. |
|
|
120
|
+
| `WongWangStep.phi(I)` | Use after all current-valued mechanisms are applied; it maps one nA input current to a firing rate in Hz. |
|
|
121
|
+
| `WongWangStep.dS1_dt(S1, r1)` | Use with the population-1 rate to preserve the model's public `S1` gating equation. |
|
|
122
|
+
| `WongWangStep.dS2_dt(S2, r2)` | Use with the population-2 rate to preserve the model's public `S2` gating equation. |
|
|
123
|
+
| `brainstate.nn.exp_euler_step(fn, state, *args)` | Use under an active `dt` context to advance each public gating derivative and return its next State value. |
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
import brainmass
|
|
127
|
+
import brainstate
|
|
128
|
+
import brainunit as u
|
|
129
|
+
|
|
130
|
+
model = brainmass.WongWangStep(in_size=1)
|
|
131
|
+
brainstate.nn.init_all_states(model)
|
|
132
|
+
|
|
133
|
+
adaptation_1 = 0.02 * u.nA
|
|
134
|
+
adaptation_2 = 0.0 * u.nA
|
|
135
|
+
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
136
|
+
current_1, current_2 = model.compute_inputs(coherence=0.0)
|
|
137
|
+
rate_1 = model.phi(current_1 - adaptation_1)
|
|
138
|
+
rate_2 = model.phi(current_2 - adaptation_2)
|
|
139
|
+
model.S1.value = u.math.clip(
|
|
140
|
+
brainstate.nn.exp_euler_step(model.dS1_dt, model.S1.value, rate_1),
|
|
141
|
+
0.0,
|
|
142
|
+
1.0,
|
|
143
|
+
)
|
|
144
|
+
model.S2.value = u.math.clip(
|
|
145
|
+
brainstate.nn.exp_euler_step(model.dS2_dt, model.S2.value, rate_2),
|
|
146
|
+
0.0,
|
|
147
|
+
1.0,
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Keep actual noise in `noise_1_val` and `noise_2_val`; apply adaptation, stimulation, or another named mechanism explicitly to the returned currents. Do not force a current through out-of-range coherence or copy the model equations when these public methods preserve them.
|
|
152
|
+
|
|
153
|
+
## Choose Wong-Wang decision semantics
|
|
154
|
+
|
|
155
|
+
Choose the decision rule from the scientific definition; thresholded firing-rate decisions and final gating dominance are not equivalent.
|
|
156
|
+
|
|
157
|
+
| API | Description |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `WongWangStep.get_decision(threshold=15 * u.Hz)` | Use when a firing-rate threshold defines commitment; it returns `1`, `-1`, or `0` for population 1, population 2, or undecided. |
|
|
160
|
+
| `(model.S1.value - model.S2.value) > 0` | Use when final gating dominance intentionally forces every trial into a binary choice; keep it as explicit model-analysis logic. |
|
|
161
|
+
|
|
162
|
+
Do not replace one rule with the other without updating probability denominators, uncertainty calculations, and handling of undecided trials.
|
|
163
|
+
|
|
77
164
|
## Application scripts
|
|
78
165
|
|
|
79
166
|
Open only the script that matches the selected model or scientific regime.
|
|
@@ -93,6 +180,7 @@ Open only the script that matches the selected model or scientific regime.
|
|
|
93
180
|
|
|
94
181
|
- Choosing a complex six-State model before a cheap model establishes the regime.
|
|
95
182
|
- Treating `WongWangStep` and `WongWangExcInhStep` as interchangeable.
|
|
183
|
+
- Passing an arbitrary current through bounded Wong-Wang `coherence` or hiding a non-noise mechanism in `noise_1_val` or `noise_2_val`.
|
|
96
184
|
- Fitting a BOLD target without a suitable slow neural source and hemodynamic observation model.
|
|
97
185
|
- Treating a neural-mass model as a point-neuron or cellular model.
|
|
98
186
|
- Assuming the inventory from this file supersedes `list_models()` in another installed release.
|
|
@@ -100,5 +188,6 @@ Open only the script that matches the selected model or scientific regime.
|
|
|
100
188
|
## Official sources
|
|
101
189
|
|
|
102
190
|
- `https://brainx.chaobrain.com/brainmass/reference/models.html`
|
|
191
|
+
- `https://brainx.chaobrain.com/brainmass/reference/generated/brainmass.WongWangStep.html`
|
|
103
192
|
- `https://brainx.chaobrain.com/brainmass/reference/utilities.html`
|
|
104
193
|
- `https://brainx.chaobrain.com/brainmass/howto/choose_a_model.html`
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Parameter sweeps and regime analysis
|
|
2
|
+
|
|
3
|
+
Use this reference when mapping regimes, sensitivities, or identifiability over a fixed parameter grid. Use `Fitter` instead when the task is to minimize one target objective rather than characterize the landscape.
|
|
4
|
+
|
|
5
|
+
## Choose sweep or fit
|
|
6
|
+
|
|
7
|
+
| Goal | Use |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Visualize a bifurcation, regime boundary, sensitivity, or multiple equivalent solutions | Parameter sweep |
|
|
10
|
+
| Recover parameters that minimize one differentiable target | Gradient `Fitter` |
|
|
11
|
+
| Optimize a non-differentiable target without exhaustively mapping the grid | Gradient-free `Fitter` |
|
|
12
|
+
|
|
13
|
+
Return one scalar or fixed-shape scientific summary per grid point. Avoid retaining full trajectories unless they are required downstream.
|
|
14
|
+
|
|
15
|
+
## Run a one-dimensional sweep
|
|
16
|
+
|
|
17
|
+
Construct the model inside the mapped function so BrainState can trace one independent simulation per parameter value.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import brainmass
|
|
21
|
+
import brainstate
|
|
22
|
+
import brainunit as u
|
|
23
|
+
import braintools
|
|
24
|
+
import jax.numpy as jnp
|
|
25
|
+
|
|
26
|
+
def amplitude_for(a):
|
|
27
|
+
node = brainmass.HopfStep(
|
|
28
|
+
in_size=1,
|
|
29
|
+
a=a,
|
|
30
|
+
w=0.3,
|
|
31
|
+
init_x=braintools.init.Constant(0.5),
|
|
32
|
+
)
|
|
33
|
+
result = brainmass.Simulator(node, dt=0.1 * u.ms).run(
|
|
34
|
+
150.0 * u.ms,
|
|
35
|
+
monitors=["x"],
|
|
36
|
+
transient=50.0 * u.ms,
|
|
37
|
+
)
|
|
38
|
+
x = u.get_magnitude(result["x"])[:, 0]
|
|
39
|
+
return jnp.sqrt(jnp.mean(x**2)) * jnp.sqrt(2.0)
|
|
40
|
+
|
|
41
|
+
a_values = jnp.linspace(0.0, 1.5, 16)
|
|
42
|
+
amplitudes = brainstate.transform.vmap(amplitude_for)(a_values)
|
|
43
|
+
|
|
44
|
+
assert amplitudes.shape == a_values.shape
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The mapped function must return the same PyTree structure and leaf shapes for every point.
|
|
48
|
+
|
|
49
|
+
## Run a two-dimensional grid
|
|
50
|
+
|
|
51
|
+
Flatten coordinate grids, map all coordinate arrays together, then reshape the fixed-shape result back to grid order.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
a_grid = jnp.linspace(0.1, 1.5, 6)
|
|
55
|
+
w_grid = jnp.linspace(0.1, 0.6, 5)
|
|
56
|
+
aa, ww = jnp.meshgrid(a_grid, w_grid, indexing="ij")
|
|
57
|
+
|
|
58
|
+
def amplitude_for_pair(a, w):
|
|
59
|
+
node = brainmass.HopfStep(
|
|
60
|
+
in_size=1,
|
|
61
|
+
a=a,
|
|
62
|
+
w=w,
|
|
63
|
+
init_x=braintools.init.Constant(0.5),
|
|
64
|
+
)
|
|
65
|
+
result = brainmass.Simulator(node, dt=0.1 * u.ms).run(
|
|
66
|
+
150.0 * u.ms,
|
|
67
|
+
monitors=["x"],
|
|
68
|
+
transient=50.0 * u.ms,
|
|
69
|
+
)
|
|
70
|
+
x = u.get_magnitude(result["x"])[:, 0]
|
|
71
|
+
return jnp.sqrt(jnp.mean(x**2)) * jnp.sqrt(2.0)
|
|
72
|
+
|
|
73
|
+
flat = brainstate.transform.vmap(amplitude_for_pair)(
|
|
74
|
+
aa.reshape(-1),
|
|
75
|
+
ww.reshape(-1),
|
|
76
|
+
)
|
|
77
|
+
grid = flat.reshape(aa.shape)
|
|
78
|
+
assert grid.shape == (6, 5)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Preserve `indexing="ij"` and record axis values with the reshaped result. A heatmap without physical axis values is not a reproducible regime map.
|
|
82
|
+
|
|
83
|
+
Plot sparse coordinates as discrete cells, `scatter(x, y)`, or `plot(x, y, marker="o", linestyle="none")`. Do not assume that adding markers removes a line: `plot(..., marker="o")` still connects samples by default. Connect or interpolate only when the grid resolves behavior between adjacent coordinates or a declared interpolation model supports that inference.
|
|
84
|
+
|
|
85
|
+
## Sweep a delayed network
|
|
86
|
+
|
|
87
|
+
Set global `dt` before `vmap` traces construction of each delayed `Network`.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
brainstate.environ.set(dt=0.1 * u.ms)
|
|
91
|
+
connectome = brainmass.datasets.load_dataset("example_connectome")
|
|
92
|
+
|
|
93
|
+
def mean_activity_for(k):
|
|
94
|
+
n_region = connectome.weights.shape[0]
|
|
95
|
+
node = brainmass.HopfStep(
|
|
96
|
+
in_size=n_region,
|
|
97
|
+
a=0.2,
|
|
98
|
+
w=0.3,
|
|
99
|
+
init_x=braintools.init.Constant(0.3),
|
|
100
|
+
)
|
|
101
|
+
network = brainmass.Network(
|
|
102
|
+
node,
|
|
103
|
+
conn=connectome.weights,
|
|
104
|
+
distance=connectome.distances,
|
|
105
|
+
speed=10.0 * u.mm / u.ms,
|
|
106
|
+
coupling="diffusive",
|
|
107
|
+
coupled_var="x",
|
|
108
|
+
k=k,
|
|
109
|
+
)
|
|
110
|
+
output = brainmass.Simulator(network, dt=0.1 * u.ms).run(
|
|
111
|
+
600.0 * u.ms,
|
|
112
|
+
monitors=lambda model: model.node.x.value,
|
|
113
|
+
transient=100.0 * u.ms,
|
|
114
|
+
)["output"]
|
|
115
|
+
return jnp.mean(jnp.abs(u.get_magnitude(output)))
|
|
116
|
+
|
|
117
|
+
k_values = jnp.linspace(0.0, 1.5, 8)
|
|
118
|
+
summary = brainstate.transform.vmap(mean_activity_for)(k_values)
|
|
119
|
+
assert summary.shape == k_values.shape
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Use FC, FCD, spectrum, amplitude, synchrony, or another domain summary when mean absolute activity does not answer the scientific question.
|
|
123
|
+
|
|
124
|
+
## Classify time-resolved regimes
|
|
125
|
+
|
|
126
|
+
Match the temporal predicate to the claimed regime; a threshold crossing, a sustained event, and routed propagation are different outcomes.
|
|
127
|
+
|
|
128
|
+
| Claim | Required predicate |
|
|
129
|
+
|---|---|
|
|
130
|
+
| Threshold crossing | At least one sample crosses the fixed threshold; onset is the first crossing. |
|
|
131
|
+
| Sustained event or burst | Every sample in a fixed minimum-duration window crosses the threshold; onset is the start of the first qualifying window. |
|
|
132
|
+
| Routed propagation | Every required region satisfies its event predicate and the qualifying onsets follow the declared route in strict order. |
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
import jax
|
|
136
|
+
import jax.numpy as jnp
|
|
137
|
+
|
|
138
|
+
# activity has shape (time, region); minimum_steps is fixed before the sweep.
|
|
139
|
+
above = activity >= threshold
|
|
140
|
+
window_hits = jax.lax.reduce_window(
|
|
141
|
+
above.astype(jnp.int32),
|
|
142
|
+
0,
|
|
143
|
+
jax.lax.add,
|
|
144
|
+
(minimum_steps, 1),
|
|
145
|
+
(1, 1),
|
|
146
|
+
"VALID",
|
|
147
|
+
)
|
|
148
|
+
qualifying_windows = window_hits == minimum_steps
|
|
149
|
+
recruited = jnp.any(qualifying_windows, axis=0)
|
|
150
|
+
first_start = jnp.argmax(qualifying_windows, axis=0)
|
|
151
|
+
onset = jnp.where(recruited, first_start + 1, jnp.nan) * dt
|
|
152
|
+
max_window_hits = jnp.max(window_hits, axis=0)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Fix the observable, direction, threshold, minimum duration, and route before inspecting outcomes. If outcome inspection changes any part of that predicate, label the result exploratory; do not describe the rule as pre-specified. Freeze the calibrated predicate and evaluate it unchanged on independently declared conditions, trials, seeds, or a later confirmation run before making a confirmatory claim.
|
|
156
|
+
|
|
157
|
+
Apply the same disclosure to every model parameter, protocol value, grid axis, or displayed case selected after inspecting outcomes, even when the predicate stayed fixed. Record which settings were outcome-calibrated and label the result exploratory or outcome-calibrated. Show nearby sensitivity or independently declared confirmation before claiming a robust regime or confirmatory result.
|
|
158
|
+
|
|
159
|
+
Retain continuous decision evidence beside every categorical label. For the reduction above, save `max_window_hits` or its duration equivalent for every condition and region, not only the onset and an unrelated peak. Also save the exact tested reduction, observable, direction, threshold, minimum duration, and `dt` so a consumer can reconstruct the decision margin without rerunning the sweep.
|
|
160
|
+
|
|
161
|
+
Align event times with the monitor phase. When a custom step updates model State and then returns it, stacked output sample zero is observed at one `dt`, not time zero. Save post-update time as `(arange(n_steps) + 1) * dt`, compute first-window onset as `(first_start + 1) * dt`, and record that phase in result metadata. Use zero-based times only when the monitor explicitly returns pre-update State.
|
|
162
|
+
|
|
163
|
+
## Include mechanism controls
|
|
164
|
+
|
|
165
|
+
When a regime claim attributes an outcome to a drive, coupling, intervention, or other varied mechanism, append its causal controls to the same flattened parameter arrays before the mapped call. Tag each control, run the identical model and metric path, and verify its expected outcome independently.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import numpy as np
|
|
169
|
+
|
|
170
|
+
condition_type = np.asarray(["grid"] * flat_k.size + ["no_coupling", "no_drive"])
|
|
171
|
+
k = jnp.concatenate([flat_k, jnp.asarray([0.0, test_k])])
|
|
172
|
+
drive = jnp.concatenate([flat_drive, jnp.asarray([test_drive, 0.0])])
|
|
173
|
+
results = brainstate.transform.vmap(run_condition)(k, drive)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Append matching control values to every other mapped coordinate when the condition has additional axes such as delay. Do not run controls through a separate Python path or omit them because the positive parameter grid contains a visually local case. A local case tests a regime; zeroing the proposed mechanism tests causality.
|
|
177
|
+
|
|
178
|
+
## Store results
|
|
179
|
+
|
|
180
|
+
Write one self-describing numeric result bundle before plotting or reporting. A figure, stdout, or value left only in memory does not retain a sweep.
|
|
181
|
+
|
|
182
|
+
Store the original grid shape and every ordered axis as dedicated named fields alongside flattened condition columns and tags so the exact mapped layout can be reconstructed. Flattened coordinates do not replace the grid shape or axis-order contract. Store continuous evidence, categorical labels, explicit units, model identity, connectivity and its direction convention, coupling kernel, non-default or mechanism-selecting parameters, protocol timing, `dt`, duration, transient, integration method, seed, predicate settings, monitor phase, and code version together. When delay retrieval varies, also record fixed buffer capacity, prehistory, and update/retrieval phase. Save full trajectories when they are required downstream; otherwise save the exact tested reduction plus every continuous boundary observable needed to audit the labels. Record code version as a repository revision when available or as an explicit script or artifact-schema version otherwise; a model name or filename is not a code version. Do not duplicate every untouched constructor default when the model identity and code version already define it.
|
|
183
|
+
|
|
184
|
+
Seed stochastic sweeps deliberately. One common seed across parameter values reduces random differences but couples their noise realization; independent seeds estimate uncertainty instead. State which design was used.
|
|
185
|
+
|
|
186
|
+
## Official source
|
|
187
|
+
|
|
188
|
+
- `https://brainx.chaobrain.com/brainmass/howto/parameter_sweeps.html`
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Simulator input and monitor API
|
|
2
|
+
|
|
3
|
+
Use this reference when a BrainMass run needs driven inputs, custom observables, sampling, independent trials, or explicit initialization and JIT controls; use `batch-transform-acceleration.md` only when this runner cannot express the workflow.
|
|
4
|
+
|
|
5
|
+
## Use the standard runner
|
|
6
|
+
|
|
7
|
+
`Simulator` owns the normal initialization, environment, transformed time loop, monitoring, transient, and sampling lifecycle.
|
|
8
|
+
|
|
9
|
+
| API | Description |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `brainmass.Simulator(model, dt=...)` | Use to bind a model or `Network` to an integration step for the standard run path. |
|
|
12
|
+
| `Simulator.run(duration, *, inputs=None, monitors=None, transient=None, sample_every=None, batch_size=None, init_states=True, jit=True)` | Use to execute a duration and return a dict of time-major monitored values plus unit-aware `ts`. It initializes State and JIT-compiles by default. |
|
|
13
|
+
|
|
14
|
+
Do not manually derive the number of steps, initialize State, scope `dt`, build a transformed loop, downsample, or reconstruct timestamps when these controls express the run.
|
|
15
|
+
|
|
16
|
+
## Supply model inputs
|
|
17
|
+
|
|
18
|
+
Choose the input form from how `model.update()` receives its arguments.
|
|
19
|
+
|
|
20
|
+
| `inputs` form | Behavior |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `None` | Call `model.update()` without arguments. |
|
|
23
|
+
| Array shaped `(n_steps, ...)` | Slice the leading time axis and pass each row as one update argument. |
|
|
24
|
+
| Callable `(i, t)` returning one value | Evaluate it each step and pass the result as one update argument. |
|
|
25
|
+
| Callable `(i, t)` returning a tuple | Evaluate it each step and splat the tuple into positional update arguments. |
|
|
26
|
+
|
|
27
|
+
Use a callable for a constant vector drive. Passing that vector directly makes `Simulator` interpret its leading axis as time.
|
|
28
|
+
|
|
29
|
+
## Select monitors
|
|
30
|
+
|
|
31
|
+
Monitors record values after each model update.
|
|
32
|
+
|
|
33
|
+
| `monitors` form | Result |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `None` | Store the return from `model.update()` under `"output"`. |
|
|
36
|
+
| List of State names | Store each named State under its own key. |
|
|
37
|
+
| Callable accepting the model | Store the returned observable under `"output"`. |
|
|
38
|
+
| Dict from output names to State names or callables | Store each selected State or derived observable under its dict key. |
|
|
39
|
+
|
|
40
|
+
`transient` discards a leading duration or step count. `sample_every=k` keeps every `k`th post-update sample and applies the same selection to `ts`.
|
|
41
|
+
|
|
42
|
+
## Run driven conditions as independent trials
|
|
43
|
+
|
|
44
|
+
Keep the scientific condition axis in `in_size` and the stochastic realization axis in `batch_size`.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import brainmass
|
|
48
|
+
import brainstate
|
|
49
|
+
import brainunit as u
|
|
50
|
+
import jax.numpy as jnp
|
|
51
|
+
|
|
52
|
+
brainstate.random.seed(7)
|
|
53
|
+
evidence = jnp.asarray([-0.2, 0.0, 0.2])
|
|
54
|
+
model = brainmass.WongWangStep(
|
|
55
|
+
in_size=evidence.size,
|
|
56
|
+
noise_s1=brainmass.GaussianNoise(evidence.size, sigma=0.02 * u.nA),
|
|
57
|
+
noise_s2=brainmass.GaussianNoise(evidence.size, sigma=0.02 * u.nA),
|
|
58
|
+
)
|
|
59
|
+
result = brainmass.Simulator(model, dt=0.1 * u.ms).run(
|
|
60
|
+
2.0 * u.ms,
|
|
61
|
+
inputs=lambda _i, _t: evidence,
|
|
62
|
+
monitors={"decision_variable": lambda m: m.S1.value - m.S2.value},
|
|
63
|
+
sample_every=5,
|
|
64
|
+
batch_size=4,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assert result["decision_variable"].shape == (4, 4, 3)
|
|
68
|
+
assert model.S1.value.shape == (4, 3)
|
|
69
|
+
assert u.math.allclose(
|
|
70
|
+
result["ts"],
|
|
71
|
+
jnp.asarray([0.1, 0.6, 1.1, 1.6]) * u.ms,
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The result layout is `(sampled_time, trial, evidence)`. Transpose or remove units only at an explicit analysis or serialization boundary.
|
|
76
|
+
|
|
77
|
+
## Override lifecycle controls only deliberately
|
|
78
|
+
|
|
79
|
+
| Control | Use when |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `init_states=False` | Continuing intentionally from existing model State; otherwise keep the default reset. |
|
|
82
|
+
| `jit=False` | Debugging transformed execution or isolating compilation behavior; otherwise keep JIT enabled. |
|
|
83
|
+
| `batch_size=N` | Initializing and running `N` independent model and noise State realizations. |
|
|
84
|
+
|
|
85
|
+
Use a custom BrainState rollout only when required inputs, monitors, State effects, explicit carry, checkpointing, or a stable benchmark boundary cannot be represented here.
|
|
86
|
+
|
|
87
|
+
## Common failures
|
|
88
|
+
|
|
89
|
+
- Passing a constant condition vector as an array and unintentionally treating it as time-major input.
|
|
90
|
+
- Flattening conditions and trials into `in_size` even though `batch_size` represents independent realizations.
|
|
91
|
+
- Reconstructing time from `dt` instead of using the sampled, unit-aware `ts` result.
|
|
92
|
+
- Disabling initialization or JIT without a continuation, debugging, or benchmarking requirement.
|
|
93
|
+
- Rebuilding the runner with `environ.context()` and `for_loop` for a workflow already covered by `Simulator.run()`.
|
|
94
|
+
|
|
95
|
+
## Official sources
|
|
96
|
+
|
|
97
|
+
- `https://brainx.chaobrain.com/brainmass/reference/orchestration.html`
|
|
98
|
+
- `https://brainx.chaobrain.com/brainmass/reference/generated/brainmass.Simulator.html`
|
package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md
RENAMED
|
@@ -24,7 +24,7 @@ Strip units explicitly before a metric that operates on scale-free raw arrays. K
|
|
|
24
24
|
|---|---|
|
|
25
25
|
| `braintools.metric.functional_connectivity(signal)` | Compute pairwise correlation across regions from a `(time, regions)` trajectory. |
|
|
26
26
|
| `braintools.metric.functional_connectivity_dynamics(signal, window_size, step_size)` | Slide an FC window and correlate windowed FC matrices to return an `(n_window, n_window)` FCD matrix. |
|
|
27
|
-
| `braintools.metric.power_spectral_density(signal,
|
|
27
|
+
| `braintools.metric.power_spectral_density(signal, dt, nperseg=None, noverlap=None, freq_range=None)` | Use for a one-sided Welch PSD of a `(time,)` or `(time, channels)` signal; pass `dt` as a time `Quantity` or a float in seconds, and it returns frequencies in Hz plus PSD shaped `(frequency,)` or `(frequency, channels)`. |
|
|
28
28
|
| `brainmass.objectives.fc_corr()` | Score correlation between prediction and target FC without manually recomputing the comparison logic. |
|
|
29
29
|
| `brainmass.objectives.fcd_distribution(fcd_matrix, ...)` | Estimate the off-diagonal FCD value distribution used by distributional FCD objectives. |
|
|
30
30
|
|
|
@@ -103,17 +103,17 @@ Use `as_loss=True` only when the score is passed to a minimizer. A high FC score
|
|
|
103
103
|
Use one channel at a time unless the metric explicitly accepts multichannel input.
|
|
104
104
|
|
|
105
105
|
```python
|
|
106
|
-
|
|
107
|
-
(result["ts"][1] - result["ts"][0]).to(u.ms).mantissa
|
|
108
|
-
)
|
|
106
|
+
record_dt = result["ts"][1] - result["ts"][0]
|
|
109
107
|
frequencies, power = braintools.metric.power_spectral_density(
|
|
110
108
|
signal[:, 0],
|
|
111
|
-
|
|
109
|
+
record_dt,
|
|
112
110
|
)
|
|
113
111
|
assert frequencies.shape == power.shape
|
|
114
112
|
```
|
|
115
113
|
|
|
116
|
-
|
|
114
|
+
The returned frequencies are in hertz. A plain numeric `dt` is always interpreted in seconds; do not pass a value expressed in milliseconds without its unit. Use the difference between recorded timestamps because `sample_every` can make it differ from the integration step.
|
|
115
|
+
|
|
116
|
+
Freeze a signal-amplitude or in-band-power floor before inspecting condition outcomes. Report the dominant frequency as undefined below that floor: `argmax` always selects a bin even when the trace contains no scientifically identifiable oscillation. Choose `nperseg` deliberately when the default resolution cannot distinguish the claimed frequency band.
|
|
117
117
|
|
|
118
118
|
## Common failures
|
|
119
119
|
|