brainx-skill 1.0.12 → 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 +14 -9
- 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 +2 -1
- 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/{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 +79 -1
- package/skills/package-skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +188 -0
- package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md +6 -6
- package/skills/{brainpy-state → package-skills/brainpy-state}/SKILL.md +4 -3
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/connectivity.md +1 -1
- package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/input-current.md +1 -1
- 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 +1 -1
- package/skills/{brainstate → package-skills/brainstate}/SKILL.md +1 -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 +1 -1
- 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/brainmass/references/parameter-sweeps-and-regime-analysis.md +0 -130
- 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/mixions-for-adaptation.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/spike_frequency_adaptation.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}/SKILL.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/{brainevent → package-skills/brainevent}/references/synaptic-plasticity.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/SKILL.md +0 -0
- /package/skills/{brainmass → package-skills/brainmass}/references/batch-transform-acceleration.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/{brainmass → package-skills/brainmass}/references/simulator-input-monitor-api.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/array-creation.md +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brain-dynamics-delay-protocol.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/component-selection.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/sound_localization.py +0 -0
- /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/training-snn.py +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/agents/openai.yaml +0 -0
- /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-control-flow-patterns.md +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/collective_model_operations.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-creation.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,82 @@ 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
|
+
|
|
77
153
|
## Choose Wong-Wang decision semantics
|
|
78
154
|
|
|
79
155
|
Choose the decision rule from the scientific definition; thresholded firing-rate decisions and final gating dominance are not equivalent.
|
|
@@ -104,6 +180,7 @@ Open only the script that matches the selected model or scientific regime.
|
|
|
104
180
|
|
|
105
181
|
- Choosing a complex six-State model before a cheap model establishes the regime.
|
|
106
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`.
|
|
107
184
|
- Fitting a BOLD target without a suitable slow neural source and hemodynamic observation model.
|
|
108
185
|
- Treating a neural-mass model as a point-neuron or cellular model.
|
|
109
186
|
- Assuming the inventory from this file supersedes `list_models()` in another installed release.
|
|
@@ -111,5 +188,6 @@ Open only the script that matches the selected model or scientific regime.
|
|
|
111
188
|
## Official sources
|
|
112
189
|
|
|
113
190
|
- `https://brainx.chaobrain.com/brainmass/reference/models.html`
|
|
191
|
+
- `https://brainx.chaobrain.com/brainmass/reference/generated/brainmass.WongWangStep.html`
|
|
114
192
|
- `https://brainx.chaobrain.com/brainmass/reference/utilities.html`
|
|
115
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`
|
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
|
|
|
@@ -160,7 +160,7 @@ assert post_voltage.shape == (2000, 10)
|
|
|
160
160
|
assert conductance.shape == (2000, 10)
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
Open `references/braintools/connectivity.md` first when geometry, distance, degree, modules, or another named topology determines which neuron pairs connect; generate the topology before choosing its BrainEvent representation. Open `references/projection-patterns.md` before implementing recurrent excitation, mutual inhibition, or other spike-driven connectivity; it owns AlignPre versus AlignPost, communication, delays, direct/delta input, short-term plasticity, and electrical coupling. Open `skills/brainevent/references/scripts/coba_ei_teaching.py` when a BrainPy network should use BrainEvent for efficient event-driven communication; it keeps BrainPy neuron and synapse dynamics while replacing the communication step with `BinaryArray @ connectivity` over fixed-degree, CSR, or dense storage.
|
|
163
|
+
Open `references/braintools/connectivity.md` first when geometry, distance, degree, modules, or another named topology determines which neuron pairs connect; generate the topology before choosing its BrainEvent representation. Open `references/projection-patterns.md` before implementing recurrent excitation, mutual inhibition, or other spike-driven connectivity; it owns AlignPre versus AlignPost, communication, delays, direct/delta input, short-term plasticity, and electrical coupling. Open `skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py` when a BrainPy network should use BrainEvent for efficient event-driven communication; it keeps BrainPy neuron and synapse dynamics while replacing the communication step with `BinaryArray @ connectivity` over fixed-degree, CSR, or dense storage.
|
|
164
164
|
|
|
165
165
|
### 3. Train a spiking network
|
|
166
166
|
|
|
@@ -228,10 +228,11 @@ Open only the smallest reference that owns the decision.
|
|
|
228
228
|
| `references/braintools/input-current.md` | Generating or composing direct unit-aware current sections, pulses, waveforms, or stochastic processes |
|
|
229
229
|
| `references/component-selection.md` | Choosing a neuron, synapse, synaptic output, plasticity model, input generator, or readout from the documented native API families |
|
|
230
230
|
| `references/projection-patterns.md` | Choosing projection alignment or API form, adding delays or short-term plasticity, using direct/delta projections, or adding gap junctions |
|
|
231
|
+
| `references/perturbation-experiment-validity.md` | Estimating baseline tuning or features before matched point-neuron perturbations, calibrating delivered target dose, or deciding whether activity and analysis support justify a formal causal run |
|
|
231
232
|
| `references/nest-compatible/nest-workflow.md` | Using NEST/PyNEST model names, `Simulator`, devices, connection rules, spatial networks, parity, porting, or the bundled NEST-compatible full scripts |
|
|
232
233
|
| `references/brainPy(legacy)/brainpy legacy workflow.md` | Use as the only first-level legacy entry when existing legacy `brainpy` has no BrainUnit, unit-aware, or BrainTrace code and the user explicitly requests it; this workflow routes all second-level legacy references |
|
|
233
|
-
| `skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
234
|
-
| `skills/brainevent/references/scripts/coba_ei_teaching.py` | Learning how to incorporate efficient BrainEvent communication into a complete BrainPy COBA E/I network while preserving BrainPy dynamics and BrainState execution |
|
|
234
|
+
| `skills/package-skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
235
|
+
| `skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py` | Learning how to incorporate efficient BrainEvent communication into a complete BrainPy COBA E/I network while preserving BrainPy dynamics and BrainState execution |
|
|
235
236
|
|
|
236
237
|
|
|
237
238
|
## Application script examples
|
package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/connectivity.md
RENAMED
|
@@ -137,7 +137,7 @@ matching value permutation separately. If the topology has no generated
|
|
|
137
137
|
weights, supply an intentional scalar or edge-aligned weight array before
|
|
138
138
|
constructing `CSR`.
|
|
139
139
|
|
|
140
|
-
Open `skills/brainevent/references/sparse-formats.md` when choosing among CSR,
|
|
140
|
+
Open `skills/package-skills/brainevent/references/sparse-formats.md` when choosing among CSR,
|
|
141
141
|
CSC, dense, generated, or fixed-degree event representations after topology is
|
|
142
142
|
defined.
|
|
143
143
|
|
package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/input-current.md
RENAMED
|
@@ -115,7 +115,7 @@ Do not reconstruct the same sections with comparisons against `t` inside
|
|
|
115
115
|
`step`. For a mapped parameter sweep that shares this protocol, keep the
|
|
116
116
|
per-step current sample unmapped (`in_axes=None`) while mapping the independent
|
|
117
117
|
condition parameters and dynamical State. Open
|
|
118
|
-
`skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for
|
|
118
|
+
`skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for
|
|
119
119
|
the mapped-State contract.
|
|
120
120
|
|
|
121
121
|
## Basic currents
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Validate perturbation experiments before scaling
|
|
2
|
+
|
|
3
|
+
Open this reference when a point-neuron experiment estimates tuning or other
|
|
4
|
+
baseline features and then compares matched control and intervention trials. It
|
|
5
|
+
settles which scientific-validity gates must pass before a full causal mapping
|
|
6
|
+
run and how to calibrate intervention delivery without tuning the requested
|
|
7
|
+
outcome.
|
|
8
|
+
|
|
9
|
+
## Separate model validity from the tested result
|
|
10
|
+
|
|
11
|
+
Freeze the hypothesis tests only after establishing that the model produces
|
|
12
|
+
observable baseline responses and that the intervention reaches its declared
|
|
13
|
+
target. Use pilot data only for these protocol checks. Do not inspect downstream
|
|
14
|
+
influence signs, distance profiles, feature effects, or other requested outcomes
|
|
15
|
+
while choosing the operating regime or intervention strength.
|
|
16
|
+
|
|
17
|
+
| Gate | Required evidence before a formal run |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Baseline operating regime | Report population and subgroup firing-rate distributions, silent fractions, and trial-count windows; reject a regime whose response statistic is almost always zero or saturated. |
|
|
20
|
+
| Stimulus identifiability | Show that repeated unperturbed trials yield non-degenerate response vectors, adequate reliability or dynamic range, and enough supported preferences or feature values for the planned comparisons. |
|
|
21
|
+
| Analysis support | Construct the exact planned eligibility filters and bins on pilot data; report finite-value, unique-value, bin, target, and effective-cluster counts, and reject empty or tie-dominated contrasts. |
|
|
22
|
+
| Intervention delivery | Measure the paired target-neuron response in the declared dose window and compare it with the stated protocol tolerance or cited benchmark. |
|
|
23
|
+
| Causal pairing | Verify identical initial State and external inputs before intervention onset and zero pre-intervention response mismatches. |
|
|
24
|
+
|
|
25
|
+
Define numerical acceptance rules from the scientific question, cited protocol,
|
|
26
|
+
measurement resolution, and planned estimator before running the pilot. Do not
|
|
27
|
+
invent universal firing-rate or bin-count thresholds. Preserve the rules and all
|
|
28
|
+
failed gate results in the run artifacts.
|
|
29
|
+
|
|
30
|
+
## Calibrate only the delivered intervention
|
|
31
|
+
|
|
32
|
+
When the stimulus waveform is an implementation proxy for a published
|
|
33
|
+
intervention, select its amplitude using target-neuron dose alone. Use a small,
|
|
34
|
+
predeclared candidate grid or monotone search, run matched pilot trials, and
|
|
35
|
+
choose according to the predeclared dose tolerance. Record every candidate,
|
|
36
|
+
trial count, measured target increment, uncertainty, and selection rule.
|
|
37
|
+
|
|
38
|
+
Do not select amplitude from non-target influence, suppression, feature
|
|
39
|
+
specificity, distance dependence, or any other reproduction outcome. If no
|
|
40
|
+
candidate satisfies the target-dose rule without invalidating the baseline
|
|
41
|
+
regime, classify the protocol as invalid and stop.
|
|
42
|
+
|
|
43
|
+
Generate each pilot's unit-aware waveform once and pass it through the same
|
|
44
|
+
BrainPy-State neuron and projection path used by the formal run. Measure the
|
|
45
|
+
executed spike increment; a requested current or pulse count is not the delivered
|
|
46
|
+
biological dose.
|
|
47
|
+
|
|
48
|
+
## Freeze and scale
|
|
49
|
+
|
|
50
|
+
After all gates pass, freeze model parameters, randomization rules, target
|
|
51
|
+
selection, intervention, eligibility filters, estimators, uncertainty method,
|
|
52
|
+
and success criteria. Then start a new immutable formal run and allow its result
|
|
53
|
+
to be positive, negative, or inconclusive.
|
|
54
|
+
|
|
55
|
+
Keep the pilot and formal artifacts distinct. A failed pilot is protocol
|
|
56
|
+
development evidence, not a scientific non-reproduction. A completed formal run
|
|
57
|
+
with adequate observability and support may legitimately fail every requested
|
|
58
|
+
hypothesis.
|
|
59
|
+
|
|
60
|
+
Open `skills/package-skills/brainstate/references/paired-perturbation-execution.md` for exact
|
|
61
|
+
State branching, fixed-shape batching, resource gates, and execution-status
|
|
62
|
+
classification. Open `references/braintools/input-current.md` when constructing
|
|
63
|
+
the unit-aware intervention waveform.
|
|
64
|
+
|
|
65
|
+
## Boundaries and common failures
|
|
66
|
+
|
|
67
|
+
- Treating a successfully executed but nearly silent network as an informative
|
|
68
|
+
null experiment.
|
|
69
|
+
- Estimating preferences by `argmax` when most response vectors are tied at
|
|
70
|
+
zero, then interpreting the tie-broken labels as tuning.
|
|
71
|
+
- Plotting nominal quantile bins without reporting empty bins, tied values, or
|
|
72
|
+
effective target counts.
|
|
73
|
+
- Matching the requested current waveform but failing to measure the added
|
|
74
|
+
target spikes or other delivered dose.
|
|
75
|
+
- Adjusting connectivity or intervention strength after seeing the sign of a
|
|
76
|
+
downstream influence statistic.
|
package/skills/{brainpy-state → package-skills/brainpy-state}/references/projection-patterns.md
RENAMED
|
@@ -111,7 +111,7 @@ Choose projection alignment before adding a delay. Open `references/brain-dynami
|
|
|
111
111
|
|
|
112
112
|
## Communication boundary
|
|
113
113
|
|
|
114
|
-
Use `brainstate.nn.EventFixedProb` for the canonical probabilistic sparse-spike connection shown in BrainPy-State tutorials. Open `skills/brainevent/SKILL.md` when the decision involves `EventLinear`, fixed-number event connectivity, sparse formats, plasticity operators, custom kernels, or dense-to-event performance conversion.
|
|
114
|
+
Use `brainstate.nn.EventFixedProb` for the canonical probabilistic sparse-spike connection shown in BrainPy-State tutorials. Open `skills/package-skills/brainevent/SKILL.md` when the decision involves `EventLinear`, fixed-number event connectivity, sparse formats, plasticity operators, custom kernels, or dense-to-event performance conversion.
|
|
115
115
|
|
|
116
116
|
Open `references/scripts/103_COBA_2005.py` for a complete E/I COBA projection workflow. Open `references/scripts/109_fast_global_oscillation.py` when the projection uses `DeltaProj` with delayed recurrent input.
|
|
117
117
|
|
|
@@ -352,6 +352,7 @@ Route by the outcome the task needs, then open only the smallest reference that
|
|
|
352
352
|
| `references/state-graph-operations.md` | Splitting, transforming, checkpointing, or reconstructing Module graphs while preserving sharing and cycles |
|
|
353
353
|
| `references/state_collections_and_utilities.md` | Filtering, freezing, flattening, configuring, or inspecting supporting mappings without graph identity |
|
|
354
354
|
| `references/collective_model_operations.md` | Initializing, resetting, restoring, or invoking methods across a Module graph, including vmapped lifecycle operations |
|
|
355
|
+
| `references/paired-perturbation-execution.md` | Running matched baseline-perturbation simulations with exact causal branching, fixed-shape chunks, progressive resource gates, and explicit execution-versus-science outcome classification |
|
|
355
356
|
|
|
356
357
|
### Simulation environment
|
|
357
358
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BrainState transformed diagnostics
|
|
2
2
|
|
|
3
|
-
Use this reference after `skills/brainstate/SKILL.md` when runtime values, State
|
|
3
|
+
Use this reference after `skills/package-skills/brainstate/SKILL.md` when runtime values, State
|
|
4
4
|
updates, or failures must be inspected from transformed BrainState code. The
|
|
5
5
|
skill owns the core transformation model; this reference only adds diagnostics
|
|
6
6
|
that execute after tracing or turn value-dependent failures into data or
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BrainState constrained and regularized parameters
|
|
2
2
|
|
|
3
|
-
Use this reference after `skills/brainstate/SKILL.md` has selected
|
|
3
|
+
Use this reference after `skills/package-skills/brainstate/SKILL.md` has selected
|
|
4
4
|
`brainstate.nn.Param` for a value that needs a valid-domain transform, a
|
|
5
5
|
regularization penalty, a modeling prior, or fixed parameter-like storage. It
|
|
6
6
|
owns the operational workflow and common patterns. Open
|