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
|
@@ -35,11 +35,12 @@ Align synaptic State to a neuron dimension instead of each connection, reduce th
|
|
|
35
35
|
|
|
36
36
|
### 1. Choose and run neuron dynamics
|
|
37
37
|
|
|
38
|
-
A neuron call advances one `dt`, mutates its registered dynamical State, and exposes the current spike through `get_spike()`; initialize before every independent rollout and lower the complete time loop through `brainstate.transform`.
|
|
38
|
+
A neuron call advances one `dt`, mutates its registered dynamical State, and exposes the current spike through `get_spike()`; initialize before every independent rollout, set `V_initializer` whenever startup voltage affects the result, and lower the complete time loop through `brainstate.transform`.
|
|
39
39
|
|
|
40
40
|
| API | Description |
|
|
41
41
|
|---|---|
|
|
42
|
-
| `brainpy.state.LIFRef(
|
|
42
|
+
| `brainpy.state.LIFRef(..., V_initializer=...)` | Use for the canonical point-neuron rollout when leak and refractory timing are required; each call integrates one `dt`, updates membrane/refractory State, and returns the current spike. `V_rest` sets the resting dynamics but does not set the initial membrane State, so pass an intentional initializer when startup spikes or transients matter. |
|
|
43
|
+
| `braintools.init.Constant(value)` | Use as `V_initializer` when every neuron must start at one known voltage; initialization creates membrane State at that value. Use a documented distribution instead when initial heterogeneity is part of the model. |
|
|
43
44
|
| `brainstate.nn.init_all_states(model, batch_size=...)` | Use after construction and before a rollout; it allocates or resets dynamical State across the Module graph and adds a leading batch dimension when `batch_size` is given. |
|
|
44
45
|
| `brainstate.environ.context(dt=..., t=...)` | Use around the rollout for `dt` and inside the step for `t`; dynamics read the active values and the context restores previous settings on exit. |
|
|
45
46
|
| `brainstate.environ.get_dt()` | Use when constructing the time axis or a numerical update from the active simulation step; it returns `dt` and raises when no value is set. |
|
|
@@ -50,6 +51,7 @@ A neuron call advances one `dt`, mutates its registered dynamical State, and exp
|
|
|
50
51
|
```python
|
|
51
52
|
import brainpy
|
|
52
53
|
import brainstate
|
|
54
|
+
import braintools
|
|
53
55
|
import brainunit as u
|
|
54
56
|
|
|
55
57
|
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
@@ -61,6 +63,7 @@ with brainstate.environ.context(dt=0.1 * u.ms):
|
|
|
61
63
|
V_th=-50.0 * u.mV,
|
|
62
64
|
V_reset=-60.0 * u.mV,
|
|
63
65
|
tau_ref=5.0 * u.ms,
|
|
66
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
64
67
|
)
|
|
65
68
|
brainstate.nn.init_all_states(neuron)
|
|
66
69
|
times = u.math.arange(
|
|
@@ -80,11 +83,11 @@ assert voltages.shape == (2000, 1)
|
|
|
80
83
|
assert spikes.shape == (2000, 1)
|
|
81
84
|
```
|
|
82
85
|
|
|
83
|
-
Open `references/array-creation.md` when constructing specialized unit-aware current ranges, grids, filled arrays, template-shaped arrays, or matrix patterns. Open `references/component-selection.md` when choosing among documented neuron, input, synapse, output, plasticity, or readout variants, for the decision boundary and complete category list. Open `references/braintools/brainstate-control-flow-patterns.md` when the rollout needs explicit carry, branching, or checkpointed control flow.
|
|
86
|
+
Open `references/braintools/input-current.md` when a direct current protocol needs timed sections, pulses, waveforms, stochastic processes, or composition. Generate the complete time-major protocol once under the rollout `dt` and pass it as an input to `for_loop`; do not rebuild named sections or pulses from time predicates inside the model step. Open `references/array-creation.md` when constructing specialized unit-aware current ranges, grids, filled arrays, template-shaped arrays, or matrix patterns. Open `references/component-selection.md` when choosing among documented neuron, input, synapse, output, plasticity, or readout variants, for the decision boundary and complete category list. Open `references/braintools/brainstate-control-flow-patterns.md` when the rollout needs explicit carry, branching, or checkpointed control flow.
|
|
84
87
|
|
|
85
88
|
### 2. Compose synapses and projections
|
|
86
89
|
|
|
87
|
-
A projection deposits current into `post` before the postsynaptic neuron integrates the step, while its alignment determines which neuron dimension owns synaptic State and which kinetics remain exact.
|
|
90
|
+
A projection deposits current into `post` before the postsynaptic neuron integrates the step, while its alignment determines which neuron dimension owns synaptic State and which kinetics remain exact; when recurrent excitation, mutual inhibition, or spike-driven connectivity is a point-neuron mechanism, represent it with explicit projections instead of a hand-written population-rate feedback `State`, and route aggregate rate coupling to BrainMass.
|
|
88
91
|
|
|
89
92
|
| API | Description |
|
|
90
93
|
|---|---|
|
|
@@ -98,6 +101,7 @@ A projection deposits current into `post` before the postsynaptic neuron integra
|
|
|
98
101
|
```python
|
|
99
102
|
import brainpy
|
|
100
103
|
import brainstate
|
|
104
|
+
import braintools
|
|
101
105
|
import brainunit as u
|
|
102
106
|
|
|
103
107
|
|
|
@@ -111,6 +115,7 @@ class TwoPop(brainstate.nn.Module):
|
|
|
111
115
|
V_rest=-60.0 * u.mV,
|
|
112
116
|
V_th=-50.0 * u.mV,
|
|
113
117
|
V_reset=-60.0 * u.mV,
|
|
118
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
114
119
|
)
|
|
115
120
|
self.post = brainpy.state.LIFRef(
|
|
116
121
|
n_post,
|
|
@@ -119,6 +124,7 @@ class TwoPop(brainstate.nn.Module):
|
|
|
119
124
|
V_rest=-60.0 * u.mV,
|
|
120
125
|
V_th=-50.0 * u.mV,
|
|
121
126
|
V_reset=-60.0 * u.mV,
|
|
127
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
122
128
|
)
|
|
123
129
|
self.proj = brainpy.state.AlignPostProj(
|
|
124
130
|
comm=brainstate.nn.EventFixedProb(
|
|
@@ -154,7 +160,7 @@ assert post_voltage.shape == (2000, 10)
|
|
|
154
160
|
assert conductance.shape == (2000, 10)
|
|
155
161
|
```
|
|
156
162
|
|
|
157
|
-
Open `references/projection-patterns.md`
|
|
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.
|
|
158
164
|
|
|
159
165
|
### 3. Train a spiking network
|
|
160
166
|
|
|
@@ -218,21 +224,24 @@ Open only the smallest reference that owns the decision.
|
|
|
218
224
|
| Reference | Open when |
|
|
219
225
|
|---|---|
|
|
220
226
|
| `references/array-creation.md` | Constructing specialized unit-aware current ranges, grids, filled arrays, template-shaped arrays, or matrix patterns |
|
|
227
|
+
| `references/braintools/connectivity.md` | Selecting spatial, topological, biological E/I, kernel, or compartment-aware connection pairs and exporting a `ConnectionResult` to BrainEvent storage |
|
|
228
|
+
| `references/braintools/input-current.md` | Generating or composing direct unit-aware current sections, pulses, waveforms, or stochastic processes |
|
|
221
229
|
| `references/component-selection.md` | Choosing a neuron, synapse, synaptic output, plasticity model, input generator, or readout from the documented native API families |
|
|
222
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 |
|
|
223
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 |
|
|
224
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 |
|
|
225
|
-
| `skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
226
|
-
| `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 |
|
|
227
236
|
|
|
228
237
|
|
|
229
238
|
## Application script examples
|
|
230
|
-
|
|
231
239
|
| Reference | Open when |
|
|
232
240
|
|---|---|
|
|
233
241
|
| `references/scripts/103_COBA_2005.py` | Needing a complete canonical E/I COBA network built from native BrainPy-State projections |
|
|
234
242
|
| `references/scripts/106_COBA_HH_2007.py` | Reproducing a conductance-based E/I network with a custom Hodgkin-Huxley neuron |
|
|
235
243
|
| `references/scripts/107_gamma_oscillation_1996.py` | Reproducing gamma oscillations with custom neuron and synapse dynamics |
|
|
236
244
|
| `references/scripts/109_fast_global_oscillation.py` | Needing a complete `DeltaProj` network with delayed recurrent input |
|
|
245
|
+
| `references/scripts/sound_localization.py` | Needing a mapped delay-line coincidence network with heterogeneous integer event taps and BrainEvent fixed fan-out |
|
|
237
246
|
| `references/scripts/201_surrogate_grad_lif_fashion_mnist.py` | Needing a complete real-data surrogate-gradient LIF training workflow |
|
|
238
247
|
| `references/scripts/training-snn.py` | Needing a complete runnable surrogate-gradient SNN training workflow |
|
|
@@ -84,9 +84,60 @@ Keep the projection-before-post order. The delayed signal must be communicated b
|
|
|
84
84
|
|
|
85
85
|
Do not validate a delay only from postsynaptic spike time. Membrane integration, thresholding, refractory State, and other inputs can shift or suppress the postsynaptic spike even when the transmission delay is correct.
|
|
86
86
|
|
|
87
|
+
## Use a manual BrainState delay
|
|
88
|
+
|
|
89
|
+
Insert the current sample before retrieval so step 0 always means current and step `d` means exactly `d` completed updates earlier.
|
|
90
|
+
|
|
91
|
+
| API | Description |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `brainstate.nn.Delay(target_info, max_time)` | Use when model logic needs an explicit reusable history buffer rather than a projection-owned delay; it allocates enough history for `max_time` under the initialization `dt`. |
|
|
94
|
+
| `delay.update(value)` | Insert the current sample once per step before any retrieval that should include the updated history. |
|
|
95
|
+
| `delay.retrieve_at_step(step)` | Retrieve an integer-offset sample; after the current update, step 0 is `value` and step `d` is the value from `d` updates earlier. |
|
|
96
|
+
| `delay.retrieve_at_time(time)` | Retrieve by a unit-bearing time when the model is defined in physical time; select the documented interpolation behavior rather than manually rounding an off-grid delay. |
|
|
97
|
+
| `delay.register_entry(name, vector_delays, indices)` and `delay.at(name)` | Use for one named heterogeneous tap per selected source element; register before State initialization, then retrieve the selected delayed values after each update. |
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import brainstate
|
|
101
|
+
import brainunit as u
|
|
102
|
+
import jax
|
|
103
|
+
import jax.numpy as jnp
|
|
104
|
+
|
|
105
|
+
with brainstate.environ.context(dt=1.0 * u.ms):
|
|
106
|
+
delay = brainstate.nn.Delay(
|
|
107
|
+
jax.ShapeDtypeStruct((), jnp.float32),
|
|
108
|
+
3.0 * u.ms,
|
|
109
|
+
)
|
|
110
|
+
brainstate.nn.init_all_states(delay)
|
|
111
|
+
impulse = jnp.array([1.0, 0.0, 0.0, 0.0, 0.0])
|
|
112
|
+
|
|
113
|
+
def step(value):
|
|
114
|
+
delay.update(value)
|
|
115
|
+
return delay.retrieve_at_step(jnp.asarray(3, dtype=jnp.int32))
|
|
116
|
+
|
|
117
|
+
delayed = brainstate.transform.for_loop(step, impulse)
|
|
118
|
+
|
|
119
|
+
assert jnp.array_equal(delayed, jnp.array([0.0, 0.0, 0.0, 1.0, 0.0]))
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
If retrieval occurs before `update(value)`, the buffer still represents the previous completed step and the index for the same observed latency changes by one. Do not compensate with an unexplained `d - 1`; choose one call order, document it beside the step, and lock the convention with an impulse assertion before interpreting neural output.
|
|
123
|
+
|
|
124
|
+
Reinitialize the delay for every independent rollout. A silent input interval advances the buffer but does not establish an independent State lifecycle.
|
|
125
|
+
|
|
126
|
+
For grid-aligned binary spikes, retrieve exact integer steps or use named entries whose delays are integer multiples of `dt`. Linear time interpolation can produce fractional numeric values, which no longer satisfy binary-event semantics. Use continuous interpolation only when the modeled signal and off-grid timing require it.
|
|
127
|
+
|
|
128
|
+
When a unit-bearing event time feeds an integer delay bank, convert `time / dt` to one documented integer step before the rollout and generate the event on that grid. Do not rediscover its step inside the time loop with a half-open `abs(t - arrival) < dt / 2` window; exact half-step results can depend on floating representation.
|
|
129
|
+
|
|
130
|
+
## Map delay State across independent conditions
|
|
131
|
+
|
|
132
|
+
Keep every writable part of a delay on one compatible mapped axis. A ring buffer whose history is per lane but whose mutable write pointer remains scalar cannot be shared across a mapped step, even when every lane advances in lockstep.
|
|
133
|
+
|
|
134
|
+
Prefer `brainstate.nn.Delay` when its complete mutable State can be initialized and mapped per condition. If its bookkeeping cannot satisfy the State-axis policy, use a small pointer-free `HiddenState` shift register only for a fixed integer delay bank; keep step 0 as the current event and prove at least one nonzero tap with an impulse assertion. Do not generalize this fallback to long histories because shifting the full buffer costs work proportional to the maximum delay.
|
|
135
|
+
|
|
136
|
+
Open `references/scripts/sound_localization.py` when building a mapped multi-tap coincidence detector, for the verified pointer-free fallback, semantic State filters, integer event taps, and impulse check.
|
|
137
|
+
|
|
87
138
|
## General BrainState boundary
|
|
88
139
|
|
|
89
|
-
Open the official BrainState [Delay Protocol](https://brainx.chaobrain.com/brainstate/tutorials/brain_dynamics/02_synaptic_delays.html) when implementing `brainstate.nn.
|
|
140
|
+
Open the official BrainState [Delay Protocol](https://brainx.chaobrain.com/brainstate/tutorials/brain_dynamics/02_synaptic_delays.html) when implementing `brainstate.nn.DelayAccess`, `brainstate.nn.StateWithDelay`, rotation versus concatenation buffers, named entries, multiple taps, or linear-versus-round interpolation. Those mechanisms are more general than BrainPy projection delays and should not be reconstructed inside a projection unless the projection APIs cannot express the required history.
|
|
90
141
|
|
|
91
142
|
## Official sources
|
|
92
143
|
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Braintools connectivity
|
|
2
|
+
|
|
3
|
+
Use this reference to choose and construct point-neuron or
|
|
4
|
+
multi-compartment connection patterns. It covers which pairs exist, their
|
|
5
|
+
indices, optional weights and delays, spatial structure, topology, and
|
|
6
|
+
compartment targeting. Use `braintools.init.DistanceModulated` only when an
|
|
7
|
+
existing connection's weight should be scaled by distance.
|
|
8
|
+
|
|
9
|
+
## Choose a connectivity family
|
|
10
|
+
|
|
11
|
+
| Family | Use when | Representative choice |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| Basic point-neuron | Connection probability or deterministic pairing is enough | `Random`, `AllToAll`, or `OneToOne` |
|
|
14
|
+
| Spatial point-neuron | Positions or spatial neighborhoods determine connection probability | `DistanceDependent`, `Gaussian`, `Ring`, or `Grid2d` |
|
|
15
|
+
| Topological | Degree, clustering, modularity, hierarchy, or core/periphery structure matters | `SmallWorld`, `ScaleFree`, `ModularRandom`, or `HierarchicalRandom` |
|
|
16
|
+
| Biological E/I | Presynaptic sign must follow Dale's principle | `ExcitatoryInhibitory` |
|
|
17
|
+
| Kernel based | Receptive-field geometry should follow an image-like kernel | `GaussianKernel`, `GaborKernel`, or `DoGKernel` |
|
|
18
|
+
| Multi-compartment | Synapses must target soma, axon, or dendritic compartments | `CompartmentSpecific` or an anatomical targeting subclass |
|
|
19
|
+
|
|
20
|
+
## Construction and results
|
|
21
|
+
|
|
22
|
+
Every connectivity object is a reusable pattern. Call it with population sizes
|
|
23
|
+
and any required positions or morphology metadata to obtain a
|
|
24
|
+
`ConnectionResult`.
|
|
25
|
+
|
|
26
|
+
| API | Description |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `Connectivity(pre_size=None, post_size=None, seed=None)` | Subclass for a new general pattern. Implement `generate(...)`; use `weight_scale(factor)` or `delay_scale(factor)` to wrap a pattern. |
|
|
29
|
+
| `PointConnectivity` | Subclass for a new single-compartment pattern. |
|
|
30
|
+
| `MultiCompartmentConnectivity` | Subclass for a new morphology-aware pattern. |
|
|
31
|
+
| `ScaledConnectivity` | Returned when weights or delays are scaled. |
|
|
32
|
+
| `CompositeConnectivity` | Use when combining several connectivity patterns. |
|
|
33
|
+
| `ConnectionResult(pre_indices, post_indices, pre_size, post_size, ..., weights=None, delays=None, model_type='point', metadata=None)` | Inspect the generated edge list and optional annotations. `shape` is `(pre_size, post_size)` and `n_connections` is the number of edges. |
|
|
34
|
+
| `ConnectionResult.weight2dense()` / `weight2csr()` | Convert weights to a dense or CSR connectivity matrix. |
|
|
35
|
+
| `ConnectionResult.delay2matrix()` / `delay2csr()` | Convert delays to a dense or CSR connectivity matrix. |
|
|
36
|
+
| `ConnectionResult.get_distances()` | Compute distances for connected pairs when positions are available. |
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import brainunit as u
|
|
40
|
+
from braintools.conn import ExcitatoryInhibitory
|
|
41
|
+
|
|
42
|
+
pattern = ExcitatoryInhibitory(
|
|
43
|
+
exc_ratio=0.8,
|
|
44
|
+
exc_prob=0.1,
|
|
45
|
+
inh_prob=0.2,
|
|
46
|
+
exc_weight=1.0 * u.nS,
|
|
47
|
+
inh_weight=-0.8 * u.nS,
|
|
48
|
+
)
|
|
49
|
+
result = pattern(pre_size=1000, post_size=1000)
|
|
50
|
+
|
|
51
|
+
assert result.shape == (1000, 1000)
|
|
52
|
+
assert result.pre_indices.shape == result.post_indices.shape
|
|
53
|
+
assert result.weights.shape[0] == result.n_connections
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Invariant:** a `ConnectionResult` edge is identified by matching entries in
|
|
57
|
+
`pre_indices` and `post_indices`. Keep any weights and delays aligned with that
|
|
58
|
+
edge order when converting or filtering.
|
|
59
|
+
|
|
60
|
+
## Basic and spatial point-neuron patterns
|
|
61
|
+
|
|
62
|
+
| API | Description |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `Random(prob, allow_self_connections=False, weight=None, delay=None, **kwargs)` | Use for independent fixed-probability edges. Supply initializer objects or values for optional weights and delays. |
|
|
65
|
+
| `FixedProb(...)` | Use only as the alias for `Random`. |
|
|
66
|
+
| `AllToAll(...)` | Connect every allowed presynaptic/postsynaptic pair. |
|
|
67
|
+
| `OneToOne(...)` | Connect neuron `i` to neuron `i`; use only when the population indexing is aligned. |
|
|
68
|
+
| `DistanceDependent(distance_profile, weight=None, delay=None, allow_self_connections=False, **kwargs)` | Use when a `braintools.init.DistanceProfile` should determine connection probability from positions or precomputed distances. |
|
|
69
|
+
| `Gaussian(...)` | Use for Gaussian distance-dependent connection probability. |
|
|
70
|
+
| `Exponential(...)` | Use for exponentially decaying connection probability. |
|
|
71
|
+
| `Ring(...)` | Use for neurons arranged on a circular topology. |
|
|
72
|
+
| `Grid2d(connectivity='von_neumann', weight=None, delay=None, periodic=False, **kwargs)` | Use for immediate four-neighbor (`'von_neumann'`) or eight-neighbor (`'moore'`) connections on matching two-dimensional pre/post grids. Set `periodic=True` only for wraparound boundaries. |
|
|
73
|
+
| `RadialPatches(...)` | Use for several localized spatial connection patches. |
|
|
74
|
+
| `ClusteredRandom(...)` | Use for random connectivity enhanced within spatial clusters. |
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import brainunit as u
|
|
78
|
+
import numpy as np
|
|
79
|
+
from braintools.conn import DistanceDependent
|
|
80
|
+
from braintools.init import GaussianProfile, LogNormal
|
|
81
|
+
|
|
82
|
+
positions = np.random.default_rng(0).uniform(0, 1000, (500, 2)) * u.um
|
|
83
|
+
pattern = DistanceDependent(
|
|
84
|
+
GaussianProfile(sigma=100 * u.um, max_distance=300 * u.um),
|
|
85
|
+
weight=LogNormal(mean=1.0 * u.nS, std=0.5 * u.nS),
|
|
86
|
+
)
|
|
87
|
+
result = pattern(500, 500, positions, positions)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`DistanceDependent` consumes the profile's connection probability and samples
|
|
91
|
+
which pairs exist. In contrast, `braintools.init.DistanceModulated` multiplies
|
|
92
|
+
every supplied base weight by a profile value and never removes an edge.
|
|
93
|
+
|
|
94
|
+
## Export a `ConnectionResult` to BrainEvent CSR
|
|
95
|
+
|
|
96
|
+
Choose topology with BrainTools before choosing BrainEvent storage. Convert the
|
|
97
|
+
result's coordinate edge list to CSR when binary presynaptic events should drive
|
|
98
|
+
event-based communication.
|
|
99
|
+
|
|
100
|
+
| API | Description |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `brainevent.coo2csr(row_ids, col_ids, *, shape)` | Convert `pre_indices` and `post_indices` to row-compressed structure; it returns `(indptr, indices, order)`, where `order` is the required edge-value permutation. |
|
|
103
|
+
| `brainevent.CSR((data, indices, indptr), shape=...)` | Store the reordered weights with presynaptic rows and postsynaptic columns for `BinaryArray @ CSR`. |
|
|
104
|
+
| `brainevent.BinaryArray(spikes) @ connectivity` | Communicate active presynaptic events and return one accumulated value per postsynaptic index. |
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import brainevent
|
|
108
|
+
import brainunit as u
|
|
109
|
+
from braintools.conn import Grid2d
|
|
110
|
+
from braintools.init import Constant
|
|
111
|
+
|
|
112
|
+
pattern = Grid2d(
|
|
113
|
+
connectivity="von_neumann",
|
|
114
|
+
weight=Constant(1.0 * u.nS),
|
|
115
|
+
periodic=False,
|
|
116
|
+
)
|
|
117
|
+
result = pattern(pre_size=(10, 10), post_size=(10, 10))
|
|
118
|
+
|
|
119
|
+
indptr, indices, order = brainevent.coo2csr(
|
|
120
|
+
result.pre_indices,
|
|
121
|
+
result.post_indices,
|
|
122
|
+
shape=result.shape,
|
|
123
|
+
)
|
|
124
|
+
connectivity = brainevent.CSR(
|
|
125
|
+
(result.weights[order], indices, indptr),
|
|
126
|
+
shape=result.shape,
|
|
127
|
+
)
|
|
128
|
+
postsynaptic_input = brainevent.BinaryArray(
|
|
129
|
+
u.math.zeros(result.shape[0], dtype=bool)
|
|
130
|
+
) @ connectivity
|
|
131
|
+
|
|
132
|
+
assert postsynaptic_input.shape == (result.shape[1],)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Keep `result.weights[order]`: `coo2csr()` sorts edges by row and returns the
|
|
136
|
+
matching value permutation separately. If the topology has no generated
|
|
137
|
+
weights, supply an intentional scalar or edge-aligned weight array before
|
|
138
|
+
constructing `CSR`.
|
|
139
|
+
|
|
140
|
+
Open `skills/package-skills/brainevent/references/sparse-formats.md` when choosing among CSR,
|
|
141
|
+
CSC, dense, generated, or fixed-degree event representations after topology is
|
|
142
|
+
defined.
|
|
143
|
+
|
|
144
|
+
## Topological and biological patterns
|
|
145
|
+
|
|
146
|
+
| API | Description |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `SmallWorld(...)` | Use for Watts-Strogatz small-world structure. |
|
|
149
|
+
| `ScaleFree(...)` | Use for Barabasi-Albert preferential attachment. |
|
|
150
|
+
| `Regular(...)` | Use when each neuron should have the same degree. |
|
|
151
|
+
| `ModularRandom(...)` | Use for random within-module and between-module probabilities. |
|
|
152
|
+
| `ModularGeneral(...)` | Use when intra- and inter-module structure each need their own `Connectivity` object. |
|
|
153
|
+
| `HierarchicalRandom(...)` | Use for multilevel modules with asymmetric feedforward and feedback connectivity. |
|
|
154
|
+
| `CorePeripheryRandom(...)` | Use for a dense core and sparse periphery. |
|
|
155
|
+
| `ExcitatoryInhibitory(exc_ratio=0.8, exc_prob=0.1, inh_prob=0.2, exc_weight=None, inh_weight=None, exc_delay=None, inh_delay=None, **kwargs)` | Use for separate excitatory and inhibitory presynaptic populations whose outgoing signs follow Dale's principle. |
|
|
156
|
+
|
|
157
|
+
## Kernel-based patterns
|
|
158
|
+
|
|
159
|
+
Use kernel patterns when source and target neurons occupy image-like spatial
|
|
160
|
+
grids and a local receptive-field operator defines edges.
|
|
161
|
+
|
|
162
|
+
| API | Description |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `Conv2dKernel(...)` | Use a general convolutional kernel. |
|
|
165
|
+
| `GaussianKernel(...)` | Use a Gaussian receptive field. |
|
|
166
|
+
| `GaborKernel(...)` | Use an orientation-selective Gabor field. |
|
|
167
|
+
| `DoGKernel(...)` | Use a difference-of-Gaussians center-surround field. |
|
|
168
|
+
| `MexicanHat(...)` | Use a Laplacian-of-Gaussian field. |
|
|
169
|
+
| `SobelKernel(...)` | Use a Sobel orientation/edge kernel. |
|
|
170
|
+
| `LaplacianKernel(...)` | Use a Laplacian edge kernel. |
|
|
171
|
+
| `CustomKernel(...)` | Supply a user-defined kernel function. |
|
|
172
|
+
|
|
173
|
+
## Multi-compartment patterns
|
|
174
|
+
|
|
175
|
+
Use `SOMA`, `BASAL_DENDRITE`, `APICAL_DENDRITE`, and `AXON` as the documented
|
|
176
|
+
compartment identifiers. Choose the narrowest pattern that expresses the
|
|
177
|
+
anatomical constraint.
|
|
178
|
+
|
|
179
|
+
| Family | API | Description |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| General | `CompartmentSpecific(...)` | Define source and target compartment rules directly. |
|
|
182
|
+
| General | `AllToAllCompartments(...)` | Connect all allowed compartment pairs. |
|
|
183
|
+
| General | `CustomCompartment(...)` | Supply a custom compartment-selection function. |
|
|
184
|
+
| Anatomical | `SomaToDendrite(...)` | Target dendrites from somatic sources. |
|
|
185
|
+
| Anatomical | `AxonToSoma(...)` | Target soma from axons. |
|
|
186
|
+
| Anatomical | `DendriteToSoma(...)` | Target soma from dendrites. |
|
|
187
|
+
| Anatomical | `AxonToDendrite(target_dendrites=None, **kwargs)` | Target selected dendritic compartments from axons. |
|
|
188
|
+
| Anatomical | `DendriteToDendrite(...)` | Connect dendritic compartments. |
|
|
189
|
+
| Morphology | `ProximalTargeting(...)` | Prefer proximal dendritic compartments. |
|
|
190
|
+
| Morphology | `DistalTargeting(...)` | Prefer distal dendritic compartments. |
|
|
191
|
+
| Morphology | `BranchSpecific(...)` | Restrict targets to specified branches. |
|
|
192
|
+
| Morphology | `MorphologyDistance(...)` | Use morphology-aware distances. |
|
|
193
|
+
| Dendritic | `DendriticTree(...)` | Configure separate basal/apical probabilities. |
|
|
194
|
+
| Dendritic | `BasalDendriteTargeting(...)` | Restrict targets to basal dendrites. |
|
|
195
|
+
| Dendritic | `ApicalDendriteTargeting(...)` | Restrict targets to apical dendrites. |
|
|
196
|
+
| Dendritic | `DendriticIntegration(...)` | Express dendritic integration patterns. |
|
|
197
|
+
| Axonal | `AxonalProjection(...)` | Build topographic axonal projections. |
|
|
198
|
+
| Axonal | `AxonalBranching(...)` | Build branching axonal patterns. |
|
|
199
|
+
| Axonal | `AxonalArborization(...)` | Build axonal arborization patterns. |
|
|
200
|
+
| Axonal | `TopographicProjection(...)` | Preserve source/target topography. |
|
|
201
|
+
| Synaptic | `SynapticPlacement(...)` | Apply synapse-placement rules. |
|
|
202
|
+
| Synaptic | `SynapticClustering(...)` | Cluster synapses on target morphology. |
|
|
203
|
+
|
|
204
|
+
## Official source
|
|
205
|
+
|
|
206
|
+
- `https://brainx.chaobrain.com/braintools/apis/conn.html`
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# Braintools input currents
|
|
2
|
+
|
|
3
|
+
Use this reference to generate unit-aware stimulation currents, waveforms,
|
|
4
|
+
pulses, and stochastic processes. Prefer the composable class API when a
|
|
5
|
+
protocol combines, transforms, repeats, or sequences several signals; use the
|
|
6
|
+
functional API for one direct array.
|
|
7
|
+
|
|
8
|
+
## Choose an interface
|
|
9
|
+
|
|
10
|
+
| Interface | Use when | Result |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| Composable classes | The protocol needs algebra, clipping, smoothing, time shifts, repetition, overlays, or concatenation | Returns an `Input` object; call it to generate the array. |
|
|
13
|
+
| Functional helpers | One signal can be generated in a single call | Returns the generated array immediately. |
|
|
14
|
+
|
|
15
|
+
Names ending in `Input` or `_input` are deprecated aliases. Use the class and
|
|
16
|
+
function names documented below.
|
|
17
|
+
|
|
18
|
+
## Time-step and composition model
|
|
19
|
+
|
|
20
|
+
An `Input` stores a duration and reads its time step from
|
|
21
|
+
`brainstate.environ`. Calling it generates a cached array; pass
|
|
22
|
+
`recompute=True` when the stochastic or environmental inputs must be evaluated
|
|
23
|
+
again.
|
|
24
|
+
|
|
25
|
+
| API | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `Input(duration)` | Base class for composable currents. It exposes `duration`, `dt`, `n_steps`, and `shape`. |
|
|
28
|
+
| `input_obj(recompute=False)` | Generate and return the current array. |
|
|
29
|
+
| `input_obj.scale(factor)` | Multiply all values by a factor. |
|
|
30
|
+
| `input_obj.shift(time_shift)` | Delay or advance the signal in time. |
|
|
31
|
+
| `input_obj.clip(min_val, max_val)` | Bound the signal values. |
|
|
32
|
+
| `input_obj.smooth(tau)` | Apply exponential smoothing. |
|
|
33
|
+
| `input_obj.repeat(n_times)` | Repeat the pattern. |
|
|
34
|
+
| `input_obj.apply(func)` | Apply a custom transformation to the generated values. |
|
|
35
|
+
| `a + b`, `a - b`, `a * b`, `a / b`, `-a` | Combine compatible signals pointwise. |
|
|
36
|
+
| `a & b` | Concatenate signals sequentially in time. |
|
|
37
|
+
| `a \| b` | Overlay signals by taking their pointwise maximum. |
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import brainstate
|
|
41
|
+
import brainunit as u
|
|
42
|
+
from braintools.input import Constant, Ramp, Sinusoidal
|
|
43
|
+
|
|
44
|
+
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
45
|
+
baseline = Constant([(0.2 * u.nA, 500 * u.ms)])
|
|
46
|
+
ramp = Ramp(0 * u.nA, 1 * u.nA, 500 * u.ms)
|
|
47
|
+
oscillation = Sinusoidal(
|
|
48
|
+
amplitude=0.5 * u.nA,
|
|
49
|
+
frequency=10 * u.Hz,
|
|
50
|
+
duration=500 * u.ms,
|
|
51
|
+
)
|
|
52
|
+
protocol = (baseline + ramp + 0.5 * oscillation).clip(
|
|
53
|
+
0 * u.nA,
|
|
54
|
+
2 * u.nA,
|
|
55
|
+
)
|
|
56
|
+
current = protocol()
|
|
57
|
+
assert current.shape[0] == protocol.n_steps
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Invariant:** set or scope `brainstate.environ.dt` before constructing and
|
|
61
|
+
generating the protocol. A different `dt` changes the number of samples.
|
|
62
|
+
|
|
63
|
+
## Feed a protocol into a BrainPy-State rollout
|
|
64
|
+
|
|
65
|
+
A generated protocol is time-major data: construct it under the rollout `dt`,
|
|
66
|
+
then give it to `for_loop` so one current sample reaches each model step.
|
|
67
|
+
|
|
68
|
+
| API | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `Constant([(value, duration), ...])` | Use for a baseline-pulse-baseline protocol; calling it under the active `dt` returns one unit-aware sample per step. |
|
|
71
|
+
| `brainstate.transform.for_loop(step, times, current)` | Slice `times` and `current` together along their leading axes and stack the step outputs. |
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import brainpy
|
|
75
|
+
import brainstate
|
|
76
|
+
import braintools
|
|
77
|
+
import brainunit as u
|
|
78
|
+
from braintools.input import Constant
|
|
79
|
+
|
|
80
|
+
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
81
|
+
neuron = brainpy.state.LIFRef(
|
|
82
|
+
3,
|
|
83
|
+
R=100.0 * u.Mohm,
|
|
84
|
+
tau=20.0 * u.ms,
|
|
85
|
+
V_rest=-65.0 * u.mV,
|
|
86
|
+
V_th=-50.0 * u.mV,
|
|
87
|
+
V_reset=-60.0 * u.mV,
|
|
88
|
+
tau_ref=2.0 * u.ms,
|
|
89
|
+
V_initializer=braintools.init.Constant(-65.0 * u.mV),
|
|
90
|
+
)
|
|
91
|
+
brainstate.nn.init_all_states(neuron)
|
|
92
|
+
protocol = Constant([
|
|
93
|
+
(0.0 * u.nA, 15.0 * u.ms),
|
|
94
|
+
(0.65 * u.nA, 4.0 * u.ms),
|
|
95
|
+
(0.0 * u.nA, 81.0 * u.ms),
|
|
96
|
+
])
|
|
97
|
+
spark = protocol()
|
|
98
|
+
times = u.math.arange(
|
|
99
|
+
0.0 * u.ms,
|
|
100
|
+
protocol.duration,
|
|
101
|
+
brainstate.environ.get_dt(),
|
|
102
|
+
)
|
|
103
|
+
edge_mask = u.math.asarray([True, False, False])
|
|
104
|
+
|
|
105
|
+
def step(t, spark_current):
|
|
106
|
+
with brainstate.environ.context(t=t):
|
|
107
|
+
return neuron(0.13 * u.nA + edge_mask * spark_current)
|
|
108
|
+
|
|
109
|
+
spikes = brainstate.transform.for_loop(step, times, spark)
|
|
110
|
+
|
|
111
|
+
assert spikes.shape == (1000, 3)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Do not reconstruct the same sections with comparisons against `t` inside
|
|
115
|
+
`step`. For a mapped parameter sweep that shares this protocol, keep the
|
|
116
|
+
per-step current sample unmapped (`in_axes=None`) while mapping the independent
|
|
117
|
+
condition parameters and dynamical State. Open
|
|
118
|
+
`skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for
|
|
119
|
+
the mapped-State contract.
|
|
120
|
+
|
|
121
|
+
## Basic currents
|
|
122
|
+
|
|
123
|
+
| Composable API | Functional API | Use |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `Section(values, durations)` | `section(values, durations, return_length=False)` | Build consecutive constant sections from parallel value and duration sequences. |
|
|
126
|
+
| `Constant(I_and_duration)` | `constant(I_and_duration)` | Build piecewise-constant sections from `(value, duration)` pairs. |
|
|
127
|
+
| `Step(amplitudes, step_times, duration=None)` | `step(amplitudes, step_times, duration=None)` | Change among discrete levels at specified times. |
|
|
128
|
+
| `Ramp(c_start, c_end, duration, t_start=None, t_end=None)` | `ramp(c_start, c_end, duration, t_start=None, t_end=None)` | Interpolate linearly, optionally only within a subinterval. |
|
|
129
|
+
|
|
130
|
+
`Constant` takes a sequence of pairs:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from braintools.input import Constant
|
|
134
|
+
|
|
135
|
+
protocol = Constant([
|
|
136
|
+
(0.0 * u.nA, 100 * u.ms),
|
|
137
|
+
(1.0 * u.nA, 200 * u.ms),
|
|
138
|
+
(0.0 * u.nA, 100 * u.ms),
|
|
139
|
+
])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Use `Section(values=[...], durations=[...])` when separate arrays are more
|
|
143
|
+
convenient.
|
|
144
|
+
|
|
145
|
+
## Pulse generators
|
|
146
|
+
|
|
147
|
+
| Composable API | Functional API | Use |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| `Spike(sp_times, duration, sp_lens=..., sp_sizes=...)` | `spike(sp_times, sp_lens, sp_sizes, duration)` | Place short current spikes at explicit times. |
|
|
150
|
+
| `GaussianPulse(amplitude, center, sigma, duration)` | `gaussian_pulse(amplitude, center, sigma, duration, ...)` | Generate a Gaussian-shaped pulse. |
|
|
151
|
+
| `ExponentialDecay(amplitude, tau, duration, ...)` | `exponential_decay(amplitude, tau, duration, ...)` | Generate a one-sided exponential decay. |
|
|
152
|
+
| `DoubleExponential(amplitude, tau_rise, tau_decay, ...)` | `double_exponential(amplitude, tau_rise, tau_decay, ...)` | Generate a rise-and-decay synaptic-current shape. |
|
|
153
|
+
| `Burst(...)` | `burst(...)` | Generate repeated pulses within one or more bursts. |
|
|
154
|
+
|
|
155
|
+
## Waveforms
|
|
156
|
+
|
|
157
|
+
| Composable API | Functional API | Use |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `Sinusoidal(amplitude, frequency, duration, ...)` | `sinusoidal(amplitude, frequency, duration, ...)` | Generate a fixed-frequency sine wave. |
|
|
160
|
+
| `Square(amplitude, frequency, duration, ...)` | `square(amplitude, frequency, duration, ...)` | Generate a square wave; configure its duty cycle deliberately. |
|
|
161
|
+
| `Triangular(amplitude, frequency, duration, ...)` | `triangular(amplitude, frequency, duration, ...)` | Generate a triangular periodic wave. |
|
|
162
|
+
| `Sawtooth(amplitude, frequency, duration, ...)` | `sawtooth(amplitude, frequency, duration, ...)` | Generate a sawtooth periodic wave. |
|
|
163
|
+
| `Chirp(amplitude, f_start, f_end, duration, ...)` | `chirp(amplitude, f_start, f_end, duration, ...)` | Sweep frequency over time. |
|
|
164
|
+
| `NoisySinusoidal(amplitude, frequency, ..., noise_amplitude=...)` | `noisy_sinusoidal(amplitude, frequency, ..., noise_amplitude=...)` | Add stochastic noise to a sinusoid. |
|
|
165
|
+
|
|
166
|
+
## Stochastic processes
|
|
167
|
+
|
|
168
|
+
| Composable API | Functional API | Use |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `WienerProcess(duration, n=1, t_start=None, t_end=None, sigma=1.0, seed=None)` | `wiener_process(duration, sigma=1.0, n=1, ...)` | Model Brownian fluctuations with independent Gaussian increments. |
|
|
171
|
+
| `OUProcess(mean, sigma, tau, duration, n=1, t_start=None, t_end=None, seed=None)` | `ou_process(mean, sigma, tau, duration, n=1, ...)` | Model mean-reverting fluctuations around `mean`. |
|
|
172
|
+
| `Poisson(rate, duration, n=1, t_start=None, t_end=None, amplitude=1.0, seed=None)` | `poisson(rate, duration, amplitude=1.0, n=1, ...)` | Generate independent Poisson spike-current trains. |
|
|
173
|
+
|
|
174
|
+
Use `seed=` for reproducibility and `n=` for multiple independent processes.
|
|
175
|
+
For Poisson input, ensure `rate * dt` is a valid per-bin spike probability.
|
|
176
|
+
Call with `recompute=True` only when a new stochastic realization is intended.
|
|
177
|
+
|
|
178
|
+
## Composition wrappers
|
|
179
|
+
|
|
180
|
+
These classes are normally created through operators or methods rather than
|
|
181
|
+
instantiated directly.
|
|
182
|
+
|
|
183
|
+
| API | Description |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `Composite(input1, input2, operator)` | Pointwise combination of two inputs. |
|
|
186
|
+
| `ConstantValue(value, duration)` | Promote a scalar to a duration-matched input. |
|
|
187
|
+
| `Sequential(*inputs)` | Time concatenation corresponding to `&`. |
|
|
188
|
+
| `TimeShifted(input_obj, time_shift)` | Result of `.shift()`. |
|
|
189
|
+
| `Clipped(input_obj, min_val=None, max_val=None)` | Result of `.clip()`. |
|
|
190
|
+
| `Smoothed(input_obj, tau)` | Result of `.smooth()`. |
|
|
191
|
+
| `Repeated(input_obj, n_times)` | Result of `.repeat()`. |
|
|
192
|
+
| `Transformed(input_obj, func)` | Result of `.apply()`. |
|
|
193
|
+
|
|
194
|
+
Pointwise operands must have compatible duration, shape, and units. Use `&`
|
|
195
|
+
when durations differ and should occur one after another.
|
|
196
|
+
|
|
197
|
+
## Official source
|
|
198
|
+
|
|
199
|
+
- `https://brainx.chaobrain.com/braintools/apis/input.html`
|
package/skills/{brainpy-state → package-skills/brainpy-state}/references/component-selection.md
RENAMED
|
@@ -9,11 +9,16 @@ Choose components in dependency order so later decisions preserve earlier semant
|
|
|
9
9
|
| Step | Decide | Result |
|
|
10
10
|
|---|---|---|
|
|
11
11
|
| 1 | Which firing mechanism must the neuron reproduce? | Neuron family and required numerical resolution |
|
|
12
|
-
| 2 | Is the
|
|
13
|
-
| 3 | Which
|
|
14
|
-
| 4 |
|
|
15
|
-
| 5 |
|
|
16
|
-
| 6 |
|
|
12
|
+
| 2 | Is the drive a direct current protocol, scheduled or stochastic spike source, encoded value, or direct State injection? | BrainTools current protocol, BrainPy input generator, encoder, or input function |
|
|
13
|
+
| 3 | Which presynaptic/postsynaptic pairs exist, and does geometry or topology determine them? | Connection topology and a `ConnectionResult` when BrainTools owns pair selection |
|
|
14
|
+
| 4 | Which temporal response must a presynaptic event create? | Synaptic dynamics and the valid projection alignment |
|
|
15
|
+
| 5 | Should synaptic activity become voltage-dependent conductance or voltage-independent current? | Synaptic output, weight units, signs, and scale |
|
|
16
|
+
| 6 | Must efficacy change over recent presynaptic history? | Optional `STP` or `STD` |
|
|
17
|
+
| 7 | What tensor and temporal statistic does the loss or analysis consume? | Readout Module or explicit time reduction |
|
|
18
|
+
|
|
19
|
+
Complete steps 3 through 6 whenever a point-neuron task names recurrent excitation, mutual inhibition, or spike-driven connectivity. Use explicit synapses, outputs, communication, and projections; do not substitute a scalar mean-spike feedback `State`. If scalar population rates and rate coupling are the scientific variables, route that scale to BrainMass or open both skills for an explicit hybrid model.
|
|
20
|
+
|
|
21
|
+
When geometry, spatial distance, graph topology, Dale's principle, or compartment targeting determines the edge set, open `references/braintools/connectivity.md` and generate the `ConnectionResult` before selecting CSR, CSC, dense, generated, or fixed-degree BrainEvent storage. Let a projection communication operator own pair selection only when its documented fixed-probability or fixed-degree contract expresses the intended topology directly.
|
|
17
22
|
|
|
18
23
|
After these choices, open `references/projection-patterns.md` to choose AlignPre versus AlignPost, communication, delay integration, and projection construction form.
|
|
19
24
|
|
|
@@ -110,6 +115,16 @@ Compare firing rate, adaptation, spike onset, and stability at the intended `dt`
|
|
|
110
115
|
|
|
111
116
|
Choose the source from what is already known and where the generated input should be applied.
|
|
112
117
|
|
|
118
|
+
### Direct current protocols
|
|
119
|
+
|
|
120
|
+
Use a BrainTools current protocol when known time-varying values should enter a neuron's current argument rather than emit spikes or mutate target State.
|
|
121
|
+
|
|
122
|
+
| API family | Use when |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `braintools.input` | Use for unit-aware constant sections, steps, pulses, waveforms, stochastic current processes, and composed protocols; generate a time-major array under the intended `brainstate.environ.dt`. |
|
|
125
|
+
|
|
126
|
+
Open `references/braintools/input-current.md` for API selection, composition, and the BrainPy-State rollout handoff. Generate the complete time-major current once under the rollout `dt`, pass it as an `xs` argument to `for_loop`, and apply spatial masks through unit-aware broadcasting after each sample is sliced. Do not rebuild named sections or pulses from time predicates inside the model step.
|
|
127
|
+
|
|
113
128
|
### Scheduled and autonomous spike sources
|
|
114
129
|
|
|
115
130
|
Use this family when the source owns either a prescribed event schedule or a persistent stochastic firing-rate configuration.
|