brainx-skill 1.0.10 → 1.0.12
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 +6 -0
- package/adapters/antigravity.js +8 -0
- package/installation/lib/installer.js +60 -20
- package/installation/lib/paths.js +41 -3
- package/installation/lib/prompts.js +13 -7
- package/manifest.json +2 -1
- package/package.json +3 -2
- package/skills/braincell/SKILL.md +1 -1
- package/skills/braincell/references/mixions-for-adaptation.md +26 -3
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +113 -53
- package/skills/brainevent/references/synaptic-plasticity.md +74 -230
- package/skills/brainmass/SKILL.md +11 -6
- package/skills/brainmass/references/batch-transform-acceleration.md +44 -3
- package/skills/brainmass/references/modellibrary.md +11 -0
- package/skills/brainmass/references/simulator-input-monitor-api.md +98 -0
- package/skills/brainpy-state/SKILL.md +20 -6
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +52 -1
- package/skills/brainpy-state/references/brainPy(legacy)/analysis.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +373 -0
- package/skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +175 -0
- package/skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +286 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +111 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +163 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +113 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +136 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +222 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +123 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +185 -0
- package/skills/brainpy-state/references/brainPy(legacy)/integrators.md +181 -0
- package/skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +102 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +147 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +159 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +127 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +167 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +186 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +104 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +89 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +253 -0
- package/skills/brainpy-state/references/braintools/connectivity.md +206 -0
- package/skills/brainpy-state/references/braintools/input-current.md +199 -0
- package/skills/brainpy-state/references/component-selection.md +20 -5
- package/skills/brainpy-state/references/projection-patterns.md +2 -0
- package/skills/brainpy-state/references/scripts/sound_localization.py +240 -0
- package/skills/brainstate/SKILL.md +1 -1
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +57 -7
- package/skills/brainstate/references/collective_model_operations.md +26 -27
- package/skills/braintrace/SKILL.md +161 -0
- package/skills/braintrace/references/Drtrl.md +179 -0
- package/skills/braintrace/references/ETP operators.md +161 -0
- package/skills/braintrace/references/algorithm selection.md +120 -0
- package/skills/braintrace/references/batching.md +150 -0
- package/skills/braintrace/references/compiler_internal.md +162 -0
- package/skills/braintrace/references/custom ETP primitives.md +200 -0
- package/skills/braintrace/references/custom algorithms.md +206 -0
- package/skills/braintrace/references/customizing_primitive_transforms.md +191 -0
- package/skills/braintrace/references/pp_pprop workflow.md +196 -0
- package/skills/braintrace/references/pre-built-braintrace-layer.md +149 -0
- package/skills/brainx-general-guard/SKILL.md +64 -21
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: brainpy-state
|
|
3
|
-
description: Use for point-neuron modeling, from individual neurons to spiking networks with synapses and projections. Use alone for point-neuron studies or together with BrainCell and/or BrainMass when point-neuron dynamics participate in a multiscale model.
|
|
3
|
+
description: Use for point-neuron modeling, from individual neurons to spiking networks with synapses and projections. Use alone for point-neuron studies or together with BrainCell and/or BrainMass when point-neuron dynamics participate in a multiscale model. Use as the legacy BrainPy routing entry only when an existing codebase uses legacy `brainpy`, uses neither units nor BrainTrace, and the user explicitly asks to preserve it.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# BrainPy-State
|
|
@@ -11,6 +11,10 @@ Use this skill for the native `brainpy.state` modeling path: compose point neuro
|
|
|
11
11
|
|
|
12
12
|
Route NEST-compatible work to `references/nest-compatible/nest-workflow.md`, and online-learning execution to BrainTrace.
|
|
13
13
|
|
|
14
|
+
Open `references/brainPy(legacy)/brainpy legacy workflow.md` only when the workspace already contains legacy `brainpy` code, contains no BrainUnit quantities, unit-aware APIs, and when the user explicitly asks to preserve old BrainPy. Use native BrainPy-State for new project is HIGHLY RECOMMENDED; use BrainPy-State with BrainCell for all cellular modeling.
|
|
15
|
+
|
|
16
|
+
Treat that workflow as the only first-level legacy reference. Do not open or route directly to any other Markdown under `references/brainPy(legacy)/`; let the workflow select those second-level references.
|
|
17
|
+
|
|
14
18
|
## Underlying principle of BrainPy-State
|
|
15
19
|
|
|
16
20
|
BrainPy-State composes unit-aware, stateful neuron and synapse `Dynamics` into projections that separate `comm`, `syn`, `out`, and `post`; BrainState transforms run the same Module graph for simulation or surrogate-gradient training.
|
|
@@ -31,11 +35,12 @@ Align synaptic State to a neuron dimension instead of each connection, reduce th
|
|
|
31
35
|
|
|
32
36
|
### 1. Choose and run neuron dynamics
|
|
33
37
|
|
|
34
|
-
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`.
|
|
35
39
|
|
|
36
40
|
| API | Description |
|
|
37
41
|
|---|---|
|
|
38
|
-
| `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. |
|
|
39
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. |
|
|
40
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. |
|
|
41
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. |
|
|
@@ -46,6 +51,7 @@ A neuron call advances one `dt`, mutates its registered dynamical State, and exp
|
|
|
46
51
|
```python
|
|
47
52
|
import brainpy
|
|
48
53
|
import brainstate
|
|
54
|
+
import braintools
|
|
49
55
|
import brainunit as u
|
|
50
56
|
|
|
51
57
|
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
@@ -57,6 +63,7 @@ with brainstate.environ.context(dt=0.1 * u.ms):
|
|
|
57
63
|
V_th=-50.0 * u.mV,
|
|
58
64
|
V_reset=-60.0 * u.mV,
|
|
59
65
|
tau_ref=5.0 * u.ms,
|
|
66
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
60
67
|
)
|
|
61
68
|
brainstate.nn.init_all_states(neuron)
|
|
62
69
|
times = u.math.arange(
|
|
@@ -76,11 +83,11 @@ assert voltages.shape == (2000, 1)
|
|
|
76
83
|
assert spikes.shape == (2000, 1)
|
|
77
84
|
```
|
|
78
85
|
|
|
79
|
-
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.
|
|
80
87
|
|
|
81
88
|
### 2. Compose synapses and projections
|
|
82
89
|
|
|
83
|
-
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.
|
|
84
91
|
|
|
85
92
|
| API | Description |
|
|
86
93
|
|---|---|
|
|
@@ -94,6 +101,7 @@ A projection deposits current into `post` before the postsynaptic neuron integra
|
|
|
94
101
|
```python
|
|
95
102
|
import brainpy
|
|
96
103
|
import brainstate
|
|
104
|
+
import braintools
|
|
97
105
|
import brainunit as u
|
|
98
106
|
|
|
99
107
|
|
|
@@ -107,6 +115,7 @@ class TwoPop(brainstate.nn.Module):
|
|
|
107
115
|
V_rest=-60.0 * u.mV,
|
|
108
116
|
V_th=-50.0 * u.mV,
|
|
109
117
|
V_reset=-60.0 * u.mV,
|
|
118
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
110
119
|
)
|
|
111
120
|
self.post = brainpy.state.LIFRef(
|
|
112
121
|
n_post,
|
|
@@ -115,6 +124,7 @@ class TwoPop(brainstate.nn.Module):
|
|
|
115
124
|
V_rest=-60.0 * u.mV,
|
|
116
125
|
V_th=-50.0 * u.mV,
|
|
117
126
|
V_reset=-60.0 * u.mV,
|
|
127
|
+
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
118
128
|
)
|
|
119
129
|
self.proj = brainpy.state.AlignPostProj(
|
|
120
130
|
comm=brainstate.nn.EventFixedProb(
|
|
@@ -150,7 +160,7 @@ assert post_voltage.shape == (2000, 10)
|
|
|
150
160
|
assert conductance.shape == (2000, 10)
|
|
151
161
|
```
|
|
152
162
|
|
|
153
|
-
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/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.
|
|
154
164
|
|
|
155
165
|
### 3. Train a spiking network
|
|
156
166
|
|
|
@@ -214,9 +224,12 @@ Open only the smallest reference that owns the decision.
|
|
|
214
224
|
| Reference | Open when |
|
|
215
225
|
|---|---|
|
|
216
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 |
|
|
217
229
|
| `references/component-selection.md` | Choosing a neuron, synapse, synaptic output, plasticity model, input generator, or readout from the documented native API families |
|
|
218
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 |
|
|
219
231
|
| `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
|
+
| `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 |
|
|
220
233
|
| `skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
221
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 |
|
|
222
235
|
|
|
@@ -228,5 +241,6 @@ Open only the smallest reference that owns the decision.
|
|
|
228
241
|
| `references/scripts/106_COBA_HH_2007.py` | Reproducing a conductance-based E/I network with a custom Hodgkin-Huxley neuron |
|
|
229
242
|
| `references/scripts/107_gamma_oscillation_1996.py` | Reproducing gamma oscillations with custom neuron and synapse dynamics |
|
|
230
243
|
| `references/scripts/109_fast_global_oscillation.py` | Needing a complete `DeltaProj` network with delayed recurrent input |
|
|
244
|
+
| `references/scripts/sound_localization.py` | Needing a mapped delay-line coincidence network with heterogeneous integer event taps and BrainEvent fixed fan-out |
|
|
231
245
|
| `references/scripts/201_surrogate_grad_lif_fashion_mnist.py` | Needing a complete real-data surrogate-gradient LIF training workflow |
|
|
232
246
|
| `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,150 @@
|
|
|
1
|
+
# Legacy BrainPy analysis
|
|
2
|
+
|
|
3
|
+
Use this reference when a legacy BrainPy 2.x model needs low-dimensional phase-plane or bifurcation analysis, fast-slow analysis, or numerical fixed-point discovery in a high-dimensional state space. Keep model construction and simulation in `brainpy legacy workflow.md`.
|
|
4
|
+
|
|
5
|
+
## Choose the analyzer
|
|
6
|
+
|
|
7
|
+
Low-dimensional analyzers work from named model variables and parameters. `SlowPointFinder` instead optimizes candidate states and is the normal choice once plotting the full state space is no longer meaningful.
|
|
8
|
+
|
|
9
|
+
| API | Use when |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `bp.analysis.PhasePlane1D(model, target_vars, ...)` | Inspect the vector field and fixed points of one state variable. |
|
|
12
|
+
| `bp.analysis.PhasePlane2D(model, target_vars, ...)` | Inspect nullclines, vector fields, fixed points, and trajectories of two state variables. |
|
|
13
|
+
| `bp.analysis.Bifurcation1D(model, target_pars, target_vars, ...)` | Continue equilibria of a one-variable system while sweeping one or two parameters. |
|
|
14
|
+
| `bp.analysis.Bifurcation2D(model, target_pars, target_vars, ...)` | Continue equilibria of a two-variable system and classify local stability while parameters change. |
|
|
15
|
+
| `bp.analysis.FastSlow1D(model, fast_vars, slow_vars, ...)` | Treat one variable as fast and one or more variables as slowly varying bifurcation parameters. |
|
|
16
|
+
| `bp.analysis.FastSlow2D(model, fast_vars, slow_vars, ...)` | Analyze a two-variable fast subsystem across one or more slow variables. |
|
|
17
|
+
| `bp.analysis.SlowPointFinder(f_cell, ...)` | Find fixed or slow points in a high-dimensional callable or `DynamicalSystem` from supplied candidate states. |
|
|
18
|
+
|
|
19
|
+
Enable 64-bit computation before constructing an analyzer when numerical root finding or stability classification is sensitive to precision:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import brainpy as bp
|
|
23
|
+
import brainpy.math as bm
|
|
24
|
+
|
|
25
|
+
bm.enable_x64()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Define variables, parameters, and resolution
|
|
29
|
+
|
|
30
|
+
The analyzer separates coordinates being solved, parameters being swept, and values held fixed; preserve that distinction so the resulting diagram represents the intended system.
|
|
31
|
+
|
|
32
|
+
| Argument | Description |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `target_vars={'name': [low, high]}` | Give each analyzed state variable and its search interval. Names must match model or integrator arguments. |
|
|
35
|
+
| `target_pars={'name': [low, high]}` | Give each parameter to sweep in a bifurcation analysis. |
|
|
36
|
+
| `pars_update={'name': value}` | Hold model parameters or external inputs at fixed values during analysis. |
|
|
37
|
+
| `fixed_vars={'name': value}` | Hold non-target state variables fixed when reducing a larger system. |
|
|
38
|
+
| `resolutions=step` | Use one grid step for all target dimensions. |
|
|
39
|
+
| `resolutions={'name': step}` | Control grid density per variable or parameter; refine only regions that need it. |
|
|
40
|
+
|
|
41
|
+
Do not place a swept value in `pars_update`; a value is either varied through `target_pars` or fixed through `pars_update` for one analysis.
|
|
42
|
+
|
|
43
|
+
## Analyze a two-variable phase plane
|
|
44
|
+
|
|
45
|
+
Use `PhasePlane2D` when the decision depends on nullcline intersections, flow direction, stability, or trajectories in a two-state system.
|
|
46
|
+
|
|
47
|
+
| API | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `plot_nullcline(...)` | Compute and optionally plot the two zero-derivative curves. |
|
|
50
|
+
| `plot_vector_field(plot_method='streamplot', ...)` | Plot the local flow; use `plot_method='quiver'` for arrows instead of streamlines. |
|
|
51
|
+
| `plot_fixed_point(...)` | Find and classify fixed points from the analysis grid. |
|
|
52
|
+
| `plot_trajectory(initials, duration, ...)` | Integrate trajectories from explicit initial states on the phase plane. |
|
|
53
|
+
| `show_figure()` | Display accumulated analysis plots when individual plot calls use `show=False`. |
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import brainpy as bp
|
|
57
|
+
import brainpy.math as bm
|
|
58
|
+
|
|
59
|
+
bm.enable_x64()
|
|
60
|
+
|
|
61
|
+
model = bp.neurons.FHN(1)
|
|
62
|
+
plane = bp.analysis.PhasePlane2D(
|
|
63
|
+
model=model,
|
|
64
|
+
target_vars={'V': [-3.0, 3.0], 'w': [-3.0, 3.0]},
|
|
65
|
+
pars_update={'I_ext': 0.8},
|
|
66
|
+
resolutions={'V': 0.01, 'w': 0.01},
|
|
67
|
+
)
|
|
68
|
+
plane.plot_nullcline(x_style={'fmt': '-'}, y_style={'fmt': '-'})
|
|
69
|
+
plane.plot_vector_field()
|
|
70
|
+
plane.plot_fixed_point()
|
|
71
|
+
plane.plot_trajectory(
|
|
72
|
+
initials={'V': [-2.0], 'w': [0.0]},
|
|
73
|
+
duration=100.0,
|
|
74
|
+
show=True,
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Invariant:** `target_vars` keys must identify the variables whose derivatives define the phase plane. A visually plausible plot with the wrong variable or parameter names analyzes a different system.
|
|
79
|
+
|
|
80
|
+
## Continue equilibria across parameters
|
|
81
|
+
|
|
82
|
+
Use a bifurcation analyzer when the question is how equilibria or their stability change as a parameter varies.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import brainpy as bp
|
|
86
|
+
import brainpy.math as bm
|
|
87
|
+
|
|
88
|
+
bm.enable_x64()
|
|
89
|
+
|
|
90
|
+
model = bp.dyn.ExpIF(1, delta_T=1.0)
|
|
91
|
+
bifurcation = bp.analysis.Bifurcation1D(
|
|
92
|
+
model=model,
|
|
93
|
+
target_vars={'V': [-70.0, -55.0]},
|
|
94
|
+
target_pars={'I': [0.0, 6.0]},
|
|
95
|
+
resolutions={'I': 0.01},
|
|
96
|
+
)
|
|
97
|
+
bifurcation.plot_bifurcation(show=True)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Use a dictionary of per-parameter resolutions when a narrow transition region needs a finer grid. Use `num_rank` on two-dimensional bifurcation plots to increase the number of initial candidates only after verifying the variable and parameter ranges.
|
|
101
|
+
|
|
102
|
+
## Find high-dimensional fixed or slow points
|
|
103
|
+
|
|
104
|
+
`SlowPointFinder` minimizes state change rather than drawing a state-space grid; candidate coverage therefore determines which fixed points can be found.
|
|
105
|
+
|
|
106
|
+
| API | Description |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `SlowPointFinder(f_cell, f_type=..., target_vars=..., inputs=...)` | Bind a callable or model, optionally restrict the optimized variables, and hold explicit model inputs fixed. |
|
|
109
|
+
| `find_fps_with_gd_method(candidates, tolerance=..., num_batch=..., num_opt=...)` | Optimize batches of candidate states with gradient descent. |
|
|
110
|
+
| `find_fps_with_opt_solver(candidates, opt_solver='BFGS')` | Use a named optimization solver instead of the gradient-descent path. |
|
|
111
|
+
| `filter_loss(tolerance)` | Remove candidates whose fixed-point loss remains above the threshold. |
|
|
112
|
+
| `keep_unique(tolerance)` | Remove fixed points closer than the uniqueness tolerance. |
|
|
113
|
+
| `compute_jacobians(points, plot=False, ...)` | Linearize the dynamics at retained points and return their Jacobians. |
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Given a constructed legacy BrainPy model with Variables V and w:
|
|
117
|
+
finder = bp.analysis.SlowPointFinder(
|
|
118
|
+
f_cell=model,
|
|
119
|
+
target_vars={'V': model.V, 'w': model.w},
|
|
120
|
+
inputs=[model.Iext, fixed_input],
|
|
121
|
+
)
|
|
122
|
+
finder.find_fps_with_gd_method(
|
|
123
|
+
candidates={
|
|
124
|
+
'V': bm.random.normal(0.0, 2.0, (1000, model.num)),
|
|
125
|
+
'w': bm.random.normal(0.0, 1.0, (1000, model.num)),
|
|
126
|
+
},
|
|
127
|
+
tolerance=1e-5,
|
|
128
|
+
num_batch=200,
|
|
129
|
+
)
|
|
130
|
+
finder.filter_loss(1e-5)
|
|
131
|
+
finder.keep_unique(1e-3)
|
|
132
|
+
jacobians = finder.compute_jacobians(finder.fixed_points)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Treat the last example as a composition pattern: `model`, `model.Iext`, and `fixed_input` must come from the actual model. Sample candidates around states reached in simulation when random candidates do not cover the relevant attractor basin.
|
|
136
|
+
|
|
137
|
+
## Common failures
|
|
138
|
+
|
|
139
|
+
- Enable x64 before creating analyzers, not after an analysis has already been traced.
|
|
140
|
+
- Do not infer exhaustive fixed-point coverage from one candidate distribution.
|
|
141
|
+
- Filter by loss before interpreting or deduplicating optimized points.
|
|
142
|
+
- Use `f_type='continuous'` when a raw callable returns continuous-time derivatives; verify the callable convention before optimization.
|
|
143
|
+
- Compare analysis predictions with a `DSRunner` trajectory before treating a fixed point or bifurcation branch as scientifically meaningful.
|
|
144
|
+
|
|
145
|
+
## Sources mirrored
|
|
146
|
+
|
|
147
|
+
- https://brainpy.readthedocs.io/apis/analysis.html
|
|
148
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/lowdim_analysis.html
|
|
149
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/highdim_analysis.html
|
|
150
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/decision_making_model.html
|