brainx-skill 1.0.17 → 1.0.18
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/package.json +1 -1
- package/skills/brainx-modeling-loop/SKILL.md +13 -11
- package/skills/package-skills/brainmass/SKILL.md +3 -1
- package/skills/package-skills/brainmass/references/braintools/metric.md +10 -0
- package/skills/package-skills/brainmass/references/braintools/parameter-initializer.md +37 -7
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +16 -6
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +35 -2
- package/skills/package-skills/brainspike/SKILL.md +3 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +1 -1
- package/skills/package-skills/brainspike/references/spatial-connectivity.md +53 -0
package/package.json
CHANGED
|
@@ -103,13 +103,15 @@ Turn the researcher's request and inspected data into a short `NeuroSpecificatio
|
|
|
103
103
|
|
|
104
104
|
### Clarification gate
|
|
105
105
|
|
|
106
|
-
Inspect the request, repository, supplied data, and referenced specifications first.
|
|
106
|
+
Inspect the request, repository, supplied data, and referenced specifications first. Build the decision frontier from unresolved scientific intent or data and experimental facts that cannot reasonably be inferred and require the researcher's decision. Include conflicts in the requested goal or represented scale, unknown data units or semantics, missing experimental conditions, an unclear explicit reproduction target, or a proposed change to fixed design or acceptance criteria.
|
|
107
107
|
|
|
108
|
-
Apply this gate before opening step-1 package skills. **Hard stop:** if
|
|
108
|
+
Apply this gate before opening step-1 package skills. **Hard stop:** if such a consequential choice remains unresolved and has not been delegated, ask the researcher and wait for the answer in the current conversation. Do not invoke step 1, write model or experiment code, run experiments, or silently lock the specification while that answer is pending. Do not treat a development request as permission to change user-fixed goals, scales, mechanisms, data meaning, or acceptance criteria.
|
|
109
|
+
|
|
110
|
+
For open model development, choose reasonable unspecified implementation details, parameters, solvers, sample sizes, controls, and analysis definitions within the supplied scientific scope; record them as agent choices, validate their consequences, and bound the claims. Their effect on numerical results alone does not make them researcher decisions. Use the development request as authorization to proceed within that scope, without a second specification-approval gate. A reference list supplies context, not an instruction to reproduce a paper quantitatively; ask about reproduction scope only when reproduction is explicitly requested or the supplied requirements conflict.
|
|
109
111
|
|
|
110
112
|
Ask one question at a time, ordered by dependency: settle a parent choice before asking decisions that depend on it. Each question must use the researcher's terminology and state why the answer changes the model or the interpretation. Give a recommended answer when a defensible default exists, show the relevant alternatives, and allow the researcher to say `choose for me`, `use the recommended default`, or `I don't know`. Treat the first two replies as explicit delegation or confirmation and record the resulting choice. Treat `I don't know` as unresolved: do not guess or advance; offer a small exploratory branch only when the researcher authorizes it. If a question can be answered by reading the repository or data, inspect them instead of asking.
|
|
111
113
|
|
|
112
|
-
Draft `NeuroSpecification.md` even when no consequential choice is open. Record each pending decision, question, and proposed default under `Open decisions and handling`, with `Researcher approval: pending`.
|
|
114
|
+
Draft `NeuroSpecification.md` even when no consequential choice is open. Record each pending decision, question, and proposed default under `Open decisions and handling`, with `Researcher approval: pending`. Once required researcher decisions are resolved or delegated, lock the specification under the existing authorization if it covers the proposed scope. Ask for authorization if proceeding would exceed that scope. When locking, set `Status: locked`, record the authorization, update `report.md` with `Report status: draft`, and evaluate the literature gate.
|
|
113
115
|
|
|
114
116
|
Use a compact prompt shape:
|
|
115
117
|
|
|
@@ -127,13 +129,13 @@ While an answer or authorization is pending, append a step-0 checkpoint and set
|
|
|
127
129
|
|
|
128
130
|
| Open decision type | Clarification and design response |
|
|
129
131
|
|---|---|
|
|
130
|
-
|
|
|
132
|
+
| Computational setting missing from a specified model or method | Choose, document, and validate settings that preserve the supplied scientific scope. Ask only when choosing would resolve a researcher-owned scientific uncertainty, reinterpret data, change fixed design, or invent a required reproduction contract. |
|
|
131
133
|
| Experimental fact missing from a phenomena-only request | Ask only about observations and experimental conditions that affect model choice or interpretation: measured readouts, compared samples, intervention strength or timing, and relevant controls. Choose and justify the abstraction, parameters, solver, and checks without asking the researcher to supply computational settings. Experimental measurements with numbers alone do not imply a request for technical design discussion. |
|
|
132
|
-
| Computational and experimental decisions both remain open |
|
|
134
|
+
| Computational and experimental decisions both remain open | Choose implementation settings within the supplied design; clarify unresolved scientific intent and experimental facts before implementation. |
|
|
133
135
|
|
|
134
|
-
Honor explicit collaboration directions
|
|
136
|
+
Honor explicit collaboration directions to choose the remaining settings or discuss the design. For decisions that require the researcher's input under the clarification gate, keep a proposed default pending until they confirm it or delegate the choice.
|
|
135
137
|
|
|
136
|
-
Distinguish experimental measurements, user-specified modeling assumptions, literature context, and agent choices.
|
|
138
|
+
Distinguish experimental measurements, user-specified modeling assumptions, literature context, and agent choices. Mark proposed defaults for pending researcher decisions as provisional. While waiting, perform only read-only inspection that helps resolve the pending question. Label selected implementation settings as agent choices and state what evidence would be needed to claim an exact reproduction.
|
|
137
139
|
|
|
138
140
|
When explaining an experimental phenomenon, comparing mechanisms, or deciding whether modeling can distinguish them, open `references/mechanism-comparison.md` before selecting the implementation. It defines causal chains, measurement mapping, distinguishable predictions, and which unmeasured assumptions to test first.
|
|
139
141
|
|
|
@@ -154,7 +156,7 @@ Use only this core structure:
|
|
|
154
156
|
- Execution mode: forward-simulation | task-training | parameter-fitting | hybrid
|
|
155
157
|
- Required outputs:
|
|
156
158
|
- Constraints:
|
|
157
|
-
- Open decisions and handling: <pending
|
|
159
|
+
- Open decisions and handling: <pending researcher decision, delegated choice, or agent-selected setting>
|
|
158
160
|
|
|
159
161
|
## Inspected data contract
|
|
160
162
|
- Data sources and inspected contents:
|
|
@@ -172,7 +174,7 @@ Use only this core structure:
|
|
|
172
174
|
- Model/comparison rationale and decisive assumption checks: <brief rationale or artifact path>
|
|
173
175
|
```
|
|
174
176
|
|
|
175
|
-
Inspect supplied data before completing its contract. Keep raw data read-only, preserve units and axis meaning, and prevent preprocessing leakage.
|
|
177
|
+
Inspect supplied data before completing its contract. Keep raw data read-only, preserve units and axis meaning, and prevent preprocessing leakage. Once the clarification gate is complete, evaluate the literature gate using the locked specification before proceeding to step 1.
|
|
176
178
|
|
|
177
179
|
### Optional literature gate after the NeuroSpecification
|
|
178
180
|
|
|
@@ -195,8 +197,8 @@ When the gate triggers:
|
|
|
195
197
|
2. Invoke `bio-neuro-lit` and require it to distinguish full-text from abstract-only evidence, publication versions, consensus, disagreement, and non-claims.
|
|
196
198
|
3. Have `bio-neuro-lit` append its essential modeling consequences to `brainmodeling-memory.md` as `## Literature evidence`, without changing the current checkpoint.
|
|
197
199
|
4. Reconcile the evidence with `NeuroSpecification.md`. Preserve supported choices, encode unresolved alternatives and discriminating controls, and narrow claims that the evidence does not justify.
|
|
198
|
-
5.
|
|
199
|
-
6. If the evidence remains inconclusive
|
|
200
|
+
5. When evidence changes the locked specification, mark the revision `draft`, record the reason, and apply the same clarification gate. Ask when a researcher decision remains unresolved or the revision exceeds the existing authorization. Relock once the gate is satisfied and append a corrected step-0 checkpoint that names the earlier checkpoint it supersedes.
|
|
201
|
+
6. If the evidence remains inconclusive, retain the uncertainty as a limitation and specify a discriminating test when the authorized scope supports one. Ask the researcher to choose a direction when the alternatives leave a researcher-owned decision unresolved.
|
|
200
202
|
|
|
201
203
|
When the gate does not trigger, record the skip and its reason as a step-0 milestone. Do not perform a broad background review merely to make the study record look comprehensive.
|
|
202
204
|
|
|
@@ -110,6 +110,8 @@ assert trials["x"].shape == (1000, 8, 1)
|
|
|
110
110
|
|
|
111
111
|
Seed again before a repeated run when exact replay matters.
|
|
112
112
|
|
|
113
|
+
Open `references/braintools/parameter-initializer.md` before sampling initial activity or parameters, including dimensionless initial arrays; it covers distribution choice, explicit RNG ownership and frozen-array replay before State initialization.
|
|
114
|
+
|
|
113
115
|
Do not flatten experimental conditions and stochastic trials into `in_size` unless a required external layout or numerical baseline demands it.
|
|
114
116
|
|
|
115
117
|
Open `references/noiseprocesses.md` when choosing white, OU, Brownian, or colored noise, using a noise process directly, or checking units and State behavior. Open `references/simulator-input-monitor-api.md` when batching stochastic trials or driving multiple conditions. Open `references/batch-transform-acceleration.md` when batching parameters, writing a custom transformed loop that `Simulator` cannot express, or checkpointing a long differentiated rollout.
|
|
@@ -267,7 +269,7 @@ Choose the workflow category first, then open only the smallest reference that o
|
|
|
267
269
|
| `references/datasets-api.md` | Loading, inspecting, generating, or registering BrainMass data containers. |
|
|
268
270
|
| `references/coupling-network-api.md` | Selecting or configuring coupling, delays, connectivity conventions, direct coupling objects, or trainable network parameters. |
|
|
269
271
|
| `references/forward-observation-api.md` | Selecting BOLD, HRF kernels, temporal averaging, EEG/MEG lead fields, or trainable readouts. |
|
|
270
|
-
| `references/visualization-analysis-api.md` | Plotting or computing
|
|
272
|
+
| `references/visualization-analysis-api.md` | Plotting or computing Pearson diagnostics, including lag-aligned signal pairs, time-series, FC, FCD, and spectral summaries. |
|
|
271
273
|
|
|
272
274
|
### Fitting and regime exploration
|
|
273
275
|
|
|
@@ -99,6 +99,16 @@ reduce them.
|
|
|
99
99
|
| `population.functional_connectivity(activities)` | Return the pairwise Pearson correlation matrix for `(num_time, num_signals)` data; NaNs are replaced with zero. |
|
|
100
100
|
| `population.functional_connectivity_dynamics(activities, window_size, step_size)` | Correlate the strict upper triangles of windowed FC matrices. Specify window size and step in samples. |
|
|
101
101
|
|
|
102
|
+
For an unweighted Pearson diagnostic on two aligned signals, stack them as
|
|
103
|
+
columns and read `[0, 1]` from
|
|
104
|
+
`braintools.analysis.population.functional_connectivity(observations)`.
|
|
105
|
+
For lag correlation, align the lagged slices before stacking. Check for finite
|
|
106
|
+
inputs and at least two distinct values per column. The API's
|
|
107
|
+
NaN-to-zero policy must not turn an undefined diagnostic into evidence of no
|
|
108
|
+
association. Keep weighted and matrix-triangle correlation on their dedicated
|
|
109
|
+
APIs. This contract targets BrainTools 0.4.0; see the
|
|
110
|
+
[official Pearson API](https://brainx.chaobrain.com/braintools/apis/generated/braintools.analysis.population.functional_connectivity.html).
|
|
111
|
+
|
|
102
112
|
## Spike-train metrics
|
|
103
113
|
|
|
104
114
|
Pass physical time quantities on BrainTools 0.4. Bare `dt` values are in
|
|
@@ -6,8 +6,8 @@ variance scaling, orthogonal methods, composition, and distance-based weight
|
|
|
6
6
|
modulation.
|
|
7
7
|
|
|
8
8
|
For BrainMass, use these initializers for model State, fitted starting values,
|
|
9
|
-
HORN weights, or distance-modulated network parameters
|
|
10
|
-
accepts
|
|
9
|
+
HORN weights, or distance-modulated network parameters. Resolve the initializer
|
|
10
|
+
explicitly when the consuming API accepts only concrete arrays.
|
|
11
11
|
|
|
12
12
|
## Choose an initializer
|
|
13
13
|
|
|
@@ -36,11 +36,11 @@ accept an initializer, scalar, array, or quantity through one boundary.
|
|
|
36
36
|
```python
|
|
37
37
|
import brainunit as u
|
|
38
38
|
import numpy as np
|
|
39
|
-
|
|
39
|
+
import braintools
|
|
40
40
|
|
|
41
41
|
rng = np.random.default_rng(0)
|
|
42
|
-
initializer = Normal(mean=0.5 * u.nS, std=0.1 * u.nS)
|
|
43
|
-
weights = param(initializer, sizes=100, rng=rng)
|
|
42
|
+
initializer = braintools.init.Normal(mean=0.5 * u.nS, std=0.1 * u.nS)
|
|
43
|
+
weights = braintools.init.param(initializer, sizes=100, rng=rng)
|
|
44
44
|
|
|
45
45
|
assert weights.shape == (100,)
|
|
46
46
|
assert weights.unit == u.nS
|
|
@@ -49,6 +49,33 @@ assert weights.unit == u.nS
|
|
|
49
49
|
**Invariant:** pass an explicit RNG when reproducibility matters. Do not strip a
|
|
50
50
|
quantity's unit to make an initializer accept it.
|
|
51
51
|
|
|
52
|
+
## Resolve bounded initial arrays
|
|
53
|
+
|
|
54
|
+
Use an initializer for newly sampled initial conditions even when the model
|
|
55
|
+
accepts only concrete arrays. Preserve supplied or frozen arrays rather than
|
|
56
|
+
resampling them. A NumPy Generator passed as `rng=` is the documented backend;
|
|
57
|
+
let the BrainTools distribution own the draw.
|
|
58
|
+
|
|
59
|
+
| API | Description |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `braintools.init.Uniform(low, high)(shape, rng=...)` | Sample bounded physical or dimensionless initial values with explicit axes and RNG before constructing State. |
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import braintools
|
|
65
|
+
import numpy as np
|
|
66
|
+
|
|
67
|
+
initial_activity = braintools.init.Uniform(0.05, 0.15)(
|
|
68
|
+
(3, 2), rng=np.random.default_rng(2001),
|
|
69
|
+
)
|
|
70
|
+
assert initial_activity.shape == (3, 2) # observer, population
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Store and reuse the sampled array for a matched initial condition. For a legacy
|
|
74
|
+
per-observer RNG schedule, call the initializer once with each original stream
|
|
75
|
+
and shape; one combined draw is not necessarily the same experiment. Compare
|
|
76
|
+
saved values, axes, dtype and units before claiming exact replay. BrainState's
|
|
77
|
+
operational seed does not seed these host-side Generators.
|
|
78
|
+
|
|
52
79
|
## Basic distributions
|
|
53
80
|
|
|
54
81
|
| API | Description |
|
|
@@ -157,7 +184,9 @@ initializer = DistanceModulated(
|
|
|
157
184
|
distance_profile=profile,
|
|
158
185
|
).clip(min_val=0.01 * u.nS)
|
|
159
186
|
|
|
160
|
-
distances =
|
|
187
|
+
distances = braintools.init.Uniform(0 * u.um, 500 * u.um)(
|
|
188
|
+
1000, rng=np.random.default_rng(1),
|
|
189
|
+
)
|
|
161
190
|
weights = initializer(1000, distances=distances, rng=rng)
|
|
162
191
|
```
|
|
163
192
|
|
|
@@ -184,4 +213,5 @@ composition; `DistanceModulated` does not accept a `min_weight` argument.
|
|
|
184
213
|
|
|
185
214
|
## Official source
|
|
186
215
|
|
|
187
|
-
-
|
|
216
|
+
- [Initializer API](https://brainx.chaobrain.com/braintools/apis/init.html)
|
|
217
|
+
- [Uniform and explicit RNG example](https://brainx.chaobrain.com/braintools/apis/generated/braintools.init.Uniform.html)
|
package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py
CHANGED
|
@@ -3,7 +3,8 @@ https://brainx.chaobrain.com/brainmass/gallery/case_studies/resting_state_meg.ht
|
|
|
3
3
|
|
|
4
4
|
Converted from the official notebook at upstream commit
|
|
5
5
|
293eaeb8948474c645208b68c531b7cb5482d4fb. Notebook outputs are omitted and
|
|
6
|
-
``%matplotlib inline`` remains commented
|
|
6
|
+
``%matplotlib inline`` remains commented. Local adaptations use BrainTools
|
|
7
|
+
initializers and Pearson diagnostics; this is not an exact upstream copy.
|
|
7
8
|
|
|
8
9
|
Requires BrainTools 0.4.0 or newer for functional-connectivity analysis.
|
|
9
10
|
"""
|
|
@@ -13,7 +14,7 @@ Requires BrainTools 0.4.0 or newer for functional-connectivity analysis.
|
|
|
13
14
|
# %matplotlib inline
|
|
14
15
|
import brainmass
|
|
15
16
|
import brainstate
|
|
16
|
-
|
|
17
|
+
import braintools
|
|
17
18
|
import brainunit as u
|
|
18
19
|
import jax
|
|
19
20
|
import jax.numpy as jnp
|
|
@@ -152,7 +153,7 @@ M = 16 # number of MEG sensors
|
|
|
152
153
|
# Synthetic geometric lead field: each region projects to sensors with a smooth,
|
|
153
154
|
# distance-like falloff. A real lead field comes from a head model.
|
|
154
155
|
rng = np.random.default_rng(1)
|
|
155
|
-
L_raw =
|
|
156
|
+
L_raw = u.math.abs(braintools.init.Normal(0.0, 1.0)((N, M), rng=rng)) + 0.1
|
|
156
157
|
L_raw = L_raw / L_raw.sum(axis=0, keepdims=True) # column-normalize
|
|
157
158
|
L = jnp.asarray(L_raw) * (u.tesla / (u.nA * u.meter))
|
|
158
159
|
|
|
@@ -211,12 +212,21 @@ target_res = brainmass.Simulator(target_net, dt=0.1 * u.ms).run(
|
|
|
211
212
|
target_activity = target_res['output']
|
|
212
213
|
|
|
213
214
|
# --- Functional connectivity: simulated vs target ---
|
|
214
|
-
fc_sim = functional_connectivity(u.get_magnitude(activity))
|
|
215
|
-
fc_tar = functional_connectivity(u.get_magnitude(target_activity))
|
|
215
|
+
fc_sim = braintools.analysis.population.functional_connectivity(u.get_magnitude(activity))
|
|
216
|
+
fc_tar = braintools.analysis.population.functional_connectivity(u.get_magnitude(target_activity))
|
|
216
217
|
|
|
217
218
|
# (1) Structure-function coupling: does the simulated FC reflect the connectome?
|
|
218
219
|
triu = np.triu_indices(N, k=1)
|
|
219
|
-
|
|
220
|
+
edge_pairs = u.math.stack([fc_sim[triu], u.math.asarray(W)[triu]], axis=1)
|
|
221
|
+
valid_pairs = (
|
|
222
|
+
edge_pairs.shape[0] >= 2
|
|
223
|
+
and bool(u.math.all(u.math.isfinite(edge_pairs)))
|
|
224
|
+
and bool(u.math.all(u.math.any(edge_pairs != edge_pairs[0], axis=0)))
|
|
225
|
+
)
|
|
226
|
+
sc_fc_corr = (
|
|
227
|
+
float(braintools.analysis.population.functional_connectivity(edge_pairs)[0, 1])
|
|
228
|
+
if valid_pairs else float("nan")
|
|
229
|
+
)
|
|
220
230
|
# (2) Simulated vs target FC.
|
|
221
231
|
fc_match = float(brainmass.objectives.fc_corr()(activity, target_activity))
|
|
222
232
|
print(f"structure-function coupling corr(FC, SC): {sc_fc_corr:.3f}")
|
|
@@ -16,6 +16,8 @@ Use this reference when plotting BrainMass results or computing sample-by-signal
|
|
|
16
16
|
|
|
17
17
|
Every helper accepts `ax=` and returns the `matplotlib.axes.Axes` it drew on. Pass axes explicitly when composing figures.
|
|
18
18
|
|
|
19
|
+
Treat `imshow(..., extent=...)` bounds as cell edges, not sampled centers. For uniform centers `q_i=q_0+iΔ`, use edges `q_0−Δ/2` and `q_{N−1}+Δ/2`; align transpose, `origin`, and decoder overlays to those coordinates, including periodic wrapping. Verify array-index-to-plot-coordinate pairs numerically; successful export does not establish alignment. See the [official image-extent contract](https://matplotlib.org/stable/users/explain/artists/imshow_extent.html).
|
|
20
|
+
|
|
19
21
|
## Compute standard summaries
|
|
20
22
|
|
|
21
23
|
The FC, FCD, and PSD examples require BrainTools 0.4.0 or newer and use
|
|
@@ -31,9 +33,40 @@ Strip units explicitly before a metric that operates on scale-free raw arrays. K
|
|
|
31
33
|
| `brainmass.objectives.fc_corr()` | Score correlation between prediction and target FC without manually recomputing the comparison logic. |
|
|
32
34
|
| `brainmass.objectives.fcd_distribution(fcd_matrix, ...)` | Estimate the off-diagonal FCD value distribution used by distributional FCD objectives. |
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
## Compute a two-signal diagnostic
|
|
37
|
+
|
|
38
|
+
Pearson correlation operates on aligned observation columns. Use the same API
|
|
39
|
+
for a noise-lag check or structure/function edge-pair comparison; name the
|
|
40
|
+
actual statistic rather than implying anatomical or causal connectivity.
|
|
41
|
+
|
|
42
|
+
| API | Description |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `braintools.analysis.population.functional_connectivity(observations)[0, 1]` | Use for two unweighted aligned signals. Stack them as `(observations, 2)` and check that all values are finite and each column contains at least two distinct values. |
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import braintools
|
|
48
|
+
import brainunit as u
|
|
49
|
+
|
|
50
|
+
noise = u.math.asarray([0.2, 0.1, 0.4, 0.3, 0.5, 0.2])
|
|
51
|
+
observations = u.math.stack([noise[:-1], noise[1:]], axis=1)
|
|
52
|
+
valid = (
|
|
53
|
+
observations.shape[0] >= 2
|
|
54
|
+
and bool(u.math.all(u.math.isfinite(observations)))
|
|
55
|
+
and bool(u.math.all(u.math.any(observations != observations[0], axis=0)))
|
|
56
|
+
)
|
|
57
|
+
lag1_correlation = (
|
|
58
|
+
float(braintools.analysis.population.functional_connectivity(observations)[0, 1])
|
|
59
|
+
if valid else float("nan")
|
|
60
|
+
)
|
|
61
|
+
```
|
|
35
62
|
|
|
36
|
-
Check
|
|
63
|
+
Check for constant columns by comparing values directly, since rounding in a
|
|
64
|
+
variance reduction can yield a positive result for identical values. Preserve
|
|
65
|
+
the validity flag because BrainTools 0.4.0 replaces NaNs with zero and sets
|
|
66
|
+
the diagonal to one. Check centering, precision and the observation axis
|
|
67
|
+
on a small witness before replacing a source-defined statistic. For weighted
|
|
68
|
+
or matrix-triangle correlation, open `references/braintools/metric.md` for the
|
|
69
|
+
dedicated APIs. See the [official Pearson contract](https://brainx.chaobrain.com/braintools/apis/generated/braintools.analysis.population.functional_connectivity.html).
|
|
37
70
|
|
|
38
71
|
## Canonical analysis workflow
|
|
39
72
|
|
|
@@ -81,6 +81,7 @@ Connect source to target with a connection rule plus a unitful synapse spec, and
|
|
|
81
81
|
| `sim.connect(pre, post, *, rule=..., weight=..., delay=..., ...)` | Use to build a projection, attach a source device, or register a recorder tap; it returns projection handles for realized projections and `None` for recorder taps or current injectors. |
|
|
82
82
|
| `brainspike.all_to_all` | Use when every source must connect to every target; this is the default generator fan-out rule. |
|
|
83
83
|
| `brainspike.fixed_indegree(k)` | Use when every target must draw exactly `k` presynaptic edges; set `seed` for reproducible BrainSpike wiring and `comm="sparse"` for large event fan-in. |
|
|
84
|
+
| `brainspike.spatial.spatial_pairwise_bernoulli(p, mask=...)` | Use when positions and geometric cutoffs select edges; the Simulator constructs the spatial projection. |
|
|
84
85
|
| `synapse=brainspike.<synapse_model>(...)` | Use when the edge is plastic or needs behavior beyond static weight and delay; keep rule parameters on the synapse spec. |
|
|
85
86
|
| `sim.connect(generator, neuron)` | Use for current and spike sources; generators drive their targets. |
|
|
86
87
|
| `sim.connect(neuron, spike_recorder)` | Use to tap emitted spikes. |
|
|
@@ -110,6 +111,8 @@ Do not interchange default and explicit synapse delay paths; open `references/ne
|
|
|
110
111
|
|
|
111
112
|
Open `references/nest-compatible/synapse-and-connectivity.md` when selecting a static, special, STP, STDP, or voltage-based synapse; choosing a rule; or inspecting realized edges. Open `references/nest-compatible/devices.md` when selecting a generator, recorder, detector, or result-readback method.
|
|
112
113
|
|
|
114
|
+
Open `references/spatial-connectivity.md` before constructing spatial neighborhoods, importing geometric edge lists, or replacing them with a host neighbor-search library; it covers native masks, distance units and topology parity.
|
|
115
|
+
|
|
113
116
|
### Simulate and read results
|
|
114
117
|
|
|
115
118
|
`simulate()` starts from freshly initialized State and returns one in-memory `SimulationResult` whose common time axis indexes spike and analog recordings.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Construct BrainSpike connectivity with Braintools
|
|
2
2
|
|
|
3
|
-
Use a Braintools connector when geometry or topology selects neuron pairs beyond the native Simulator rules. Keep pair selection, edge ordering, physical weights/delays, and event representation as separate decisions.
|
|
3
|
+
Use a Braintools connector when geometry or topology selects neuron pairs beyond the native Simulator rules. For distance kernels and geometric masks, first open `references/spatial-connectivity.md` to check the BrainSpike spatial rule or explicit-distance path. Keep pair selection, edge ordering, physical weights/delays, and event representation as separate decisions.
|
|
4
4
|
|
|
5
5
|
## Choose the connection owner
|
|
6
6
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Build spatial connectivity
|
|
2
|
+
|
|
3
|
+
Use positions and a connection rule to select edges; keep topology separate from physical efficacy and from silencing an already connected neuron. These examples target BrainSpikes 0.2.0 in BrainX 2026.10.25.
|
|
4
|
+
|
|
5
|
+
## Construct a masked Simulator projection
|
|
6
|
+
|
|
7
|
+
The spatial rule owns neighbor selection inside `Simulator.connect`; `p=1` retains every permitted pair within the mask.
|
|
8
|
+
|
|
9
|
+
| API | Description |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `brainspike.spatial.grid(shape, extent=...)` | Create a regular layout; plain extent values use micrometres in this release. |
|
|
12
|
+
| `brainspike.spatial.spatial_pairwise_bernoulli(p, mask=..., allow_autapses=...)` | Select pairs by probability and geometry; use `p=1` for a deterministic neighborhood. |
|
|
13
|
+
| `brainspike.spatial.circular(radius)` | Restrict source-to-target distance; plain radius values use micrometres. |
|
|
14
|
+
| `sim.get_position(population)` | Read physical coordinates to verify the layout. |
|
|
15
|
+
| `sim.get_connections(pre, post)` | Read realized edges to verify direction, source/target indexing and self-edge policy. |
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import brainspike
|
|
19
|
+
import brainstate
|
|
20
|
+
import brainunit as u
|
|
21
|
+
|
|
22
|
+
brainstate.environ.set(precision=64)
|
|
23
|
+
sim = brainspike.Simulator(dt=0.1*u.ms)
|
|
24
|
+
positions = brainspike.spatial.grid([3, 3], extent=[3.0, 3.0])
|
|
25
|
+
neurons = sim.create(brainspike.iaf_psc_alpha, positions=positions)
|
|
26
|
+
sim.connect(
|
|
27
|
+
neurons, neurons,
|
|
28
|
+
rule=brainspike.spatial.spatial_pairwise_bernoulli(
|
|
29
|
+
p=1.0, mask=brainspike.spatial.circular(1.01),
|
|
30
|
+
allow_autapses=False,
|
|
31
|
+
),
|
|
32
|
+
weight=1.0*u.pA, delay=1.0*u.ms, seed=7,
|
|
33
|
+
)
|
|
34
|
+
coordinates = sim.get_position(neurons)
|
|
35
|
+
edges = sim.get_connections(neurons, neurons)
|
|
36
|
+
assert coordinates.shape == (9, 2)
|
|
37
|
+
assert len(edges) == 24
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Convert scientific lengths explicitly at this plain-number boundary, for example `float(radius.to_decimal(u.um))`. Keep weights and delays unit-bearing. Open `references/nest-compatible/scripts/spatial_gaussex.py` for probabilistic Gaussian kernels; their random graphs require distributional checks rather than identical edges from different RNG implementations.
|
|
41
|
+
|
|
42
|
+
## Import a required explicit topology
|
|
43
|
+
|
|
44
|
+
Use `brainspike.spatial.pairwise_distance(pre_positions, post_positions)` when a native graph or a source-defined model requires explicit pairs. It returns a unit-aware `(pre, post)` distance matrix; apply the declared cutoff and self-edge policy, then preserve paired index order through `brainspike.explicit_edges` or a BrainEvent sparse representation. This dense distance path requires quadratic storage; do not scale it blindly to a large sheet.
|
|
45
|
+
|
|
46
|
+
Before using an external spatial index, check the Simulator mask path and the routed BrainTools connector. Record the actual missing capability or scale constraint. Compare a small deterministic witness for coordinate units, cutoff inclusivity, self-edges, direction and exact edge sets; reusing the same external topology builder in both witnesses does not validate the replacement.
|
|
47
|
+
|
|
48
|
+
Open `references/braintools/connectivity.md` for connector-generated pairs, distance-dependent sampling and edge-value ordering. Open `references/nest-compatible/network-building.md` for spatial APIs and connection inspection. Preserve a fixed graph when testing a silent patch unless rewiring is the declared intervention.
|
|
49
|
+
|
|
50
|
+
## Official sources
|
|
51
|
+
|
|
52
|
+
- [Spatial network workflow](https://brainx.chaobrain.com/brainspike/nest-style/spatial.html)
|
|
53
|
+
- [Pairwise distance](https://brainx.chaobrain.com/brainspike/apis/generated/brainspike.spatial.pairwise_distance.html)
|