brainx-skill 1.0.15 → 1.0.17
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 +17 -1
- package/installation/lib/literature-mcp.js +7 -1
- package/manifest.json +1 -1
- package/mcp-servers/codex/README.md +46 -20
- package/mcp-servers/codex/UPSTREAM.md +20 -16
- package/mcp-servers/codex/app-server.mjs +177 -0
- package/mcp-servers/codex/cli-invocation.cjs +50 -0
- package/mcp-servers/codex/server.mjs +136 -69
- package/mcp-servers/codex/skills.json +1 -1
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
- package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
- package/mcp-servers/codex/test/server.test.mjs +188 -84
- package/package.json +1 -1
- package/skills/bio-neuro-lit/SKILL.md +4 -2
- package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
- package/skills/brainx-acceleration/SKILL.md +30 -437
- package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
- package/skills/brainx-general-guard/SKILL.md +24 -8
- package/skills/brainx-install/SKILL.md +3 -3
- package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
- package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
- package/skills/brainx-modeling-loop/SKILL.md +117 -36
- package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
- package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
- package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
- package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
- package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
- package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
- package/skills/brainx-visualization/SKILL.md +6 -2
- package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
- package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
- package/skills/package-skills/braincell/SKILL.md +23 -14
- package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
- package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
- package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
- package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
- package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
- package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
- package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
- package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
- package/skills/package-skills/brainevent/SKILL.md +0 -3
- package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
- package/skills/package-skills/brainmass/SKILL.md +5 -3
- package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
- package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
- package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
- package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
- package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
- package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
- package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
- package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
- package/skills/package-skills/brainspike/SKILL.md +201 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
- package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
- package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
- package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
- package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
- package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
- package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
- package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
- package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
- package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
- package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
- package/skills/package-skills/brainspike/references/native-composition.md +52 -0
- package/skills/package-skills/brainspike/references/native-delays.md +34 -0
- package/skills/package-skills/brainspike/references/native-projections.md +43 -0
- package/skills/package-skills/brainspike/references/native-training.md +36 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
- package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
- package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
- package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
- package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
- package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
- package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
- package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
- package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
- package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
- package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
- package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
- package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
- package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
- package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
- package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
- package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
- package/skills/package-skills/brainstate/SKILL.md +16 -21
- package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
- package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
- package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
- package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
- package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
- package/skills/package-skills/braintrace/SKILL.md +17 -38
- package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
- package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
- package/skills/package-skills/braintrace/references/batching.md +15 -35
- package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
- package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
- package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
- package/skills/package-skills/brainunit/SKILL.md +7 -2
- package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
- package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
- package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
- package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
- package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
- package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
- package/skills/package-skills/brainpy-state/SKILL.md +0 -247
- package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
- package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
- package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
- package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
- package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
- package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
- package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
- package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
- package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
- package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
- package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
- package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
- package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
- package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
- package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
- package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
- package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
- package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
- package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
- package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
- package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
- package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
- package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
|
@@ -154,27 +154,38 @@ assert not fast_path.applicable(
|
|
|
154
154
|
|
|
155
155
|
## Exactness validation
|
|
156
156
|
|
|
157
|
-
Validate both the forward transform and its online gradient.
|
|
157
|
+
Validate both the forward transform and its online gradient. Compute the reference gradient with BrainState BPTT on a fresh model from the same factory: initialize State, sum one loss per step, and differentiate the sequence total once with `brainstate.transform.grad`. Compare it with `learner.etrace_grad(..., reduction="sum")` from an identically initialized model and input.
|
|
158
158
|
|
|
159
159
|
```python
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
)
|
|
160
|
+
import jax
|
|
161
|
+
import jax.numpy as jnp
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def bptt_grads(model_factory, inputs, targets, batch_size=1):
|
|
165
|
+
model = model_factory()
|
|
166
|
+
weights = model.states(brainstate.ParamState)
|
|
167
|
+
brainstate.nn.init_all_states(model, batch_size=batch_size)
|
|
165
168
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
)
|
|
169
|
+
def total_loss():
|
|
170
|
+
return sum(
|
|
171
|
+
jnp.mean((model(x) - target) ** 2)
|
|
172
|
+
for x, target in zip(inputs, targets)
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
return brainstate.transform.grad(total_loss, weights)()
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
bptt = bptt_grads(Model, inputs, targets)
|
|
179
|
+
online = learner.etrace_grad(
|
|
180
|
+
inputs, targets, step_fn=step_loss, reduction="sum"
|
|
181
|
+
)
|
|
182
|
+
gap = max(
|
|
183
|
+
float(jnp.max(jnp.abs(a - b) / (jnp.abs(b) + 1e-8)))
|
|
184
|
+
for a, b in zip(jax.tree.leaves(online), jax.tree.leaves(bptt))
|
|
173
185
|
)
|
|
174
|
-
assert_param_gradients_close(online, bptt, atol=1e-4)
|
|
175
186
|
```
|
|
176
187
|
|
|
177
|
-
Use
|
|
188
|
+
Use this comparison only in development tests, not as an application API. Choose a reduced model whose recurrent Jacobian lies in the estimator's documented exactness regime; a general D-RTRL model is not automatically BPTT-equivalent. A nonzero `gap` on an approximate estimator indicates regime mismatch, not a failed forward transform; validate the forward transform separately before attributing the difference to the gradient rule.
|
|
178
189
|
|
|
179
190
|
Check these failures explicitly:
|
|
180
191
|
|
|
@@ -15,142 +15,9 @@ Use this reference when input/output-factorized `pp_prop` is preferable to D-RTR
|
|
|
15
15
|
|
|
16
16
|
Factorization discards correlations present in an unfactorized trace. Report `decay_or_rank` with results and validate the estimator against BPTT on a reduced matched model when gradient fidelity matters.
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Check the model integration before training
|
|
19
19
|
|
|
20
|
-
Use ETP-aware projections for
|
|
21
|
-
|
|
22
|
-
| API | Description |
|
|
23
|
-
|---|---|
|
|
24
|
-
| `braintrace.nn.Linear(...)` | Use for an input-plus-recurrent projection whose weights participate through ETP primitives. |
|
|
25
|
-
| `braintrace.sparse_matmul(x, weight_data, sparse_mat=...)` | Use for fixed sparse recurrent structure; pass raw numeric/bool spikes as `x` and a BrainEvent `DataRepresentation` as `sparse_mat`. |
|
|
26
|
-
| `brainpy.state.LIF(...)` | Use for leaky integrate-and-fire dynamics with a differentiable surrogate spike function. |
|
|
27
|
-
| `braintrace.nn.LeakyRateReadout(...)` | Use to integrate recurrent spikes into a continuous task output. |
|
|
28
|
-
| `brainstate.environ.context(dt=...)` | Use to scope the physical simulation step around construction and execution. |
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
import brainpy.state
|
|
32
|
-
import brainstate
|
|
33
|
-
import braintrace
|
|
34
|
-
import braintools
|
|
35
|
-
import brainunit as u
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class LIF_SNN(brainstate.nn.Module):
|
|
39
|
-
def __init__(self, n_in, n_rec, n_out):
|
|
40
|
-
super().__init__()
|
|
41
|
-
self.linear = braintrace.nn.Linear(
|
|
42
|
-
n_in + n_rec,
|
|
43
|
-
n_rec,
|
|
44
|
-
w_init=braintools.init.KaimingNormal(scale=50., unit=u.mA),
|
|
45
|
-
b_init=braintools.init.ZeroInit(unit=u.mA),
|
|
46
|
-
)
|
|
47
|
-
self.neuron = brainpy.state.LIF(
|
|
48
|
-
n_rec,
|
|
49
|
-
tau=20. * u.ms,
|
|
50
|
-
R=1. * u.ohm,
|
|
51
|
-
V_th=0.1 * u.mV,
|
|
52
|
-
V_reset=0. * u.mV,
|
|
53
|
-
V_rest=0. * u.mV,
|
|
54
|
-
spk_fun=braintools.surrogate.ReluGrad(),
|
|
55
|
-
spk_reset='soft',
|
|
56
|
-
)
|
|
57
|
-
self.readout = braintrace.nn.LeakyRateReadout(
|
|
58
|
-
n_rec,
|
|
59
|
-
n_out,
|
|
60
|
-
tau=20. * u.ms,
|
|
61
|
-
w_init=braintools.init.KaimingNormal(),
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
def update(self, x):
|
|
65
|
-
previous = self.neuron.get_spike()
|
|
66
|
-
current = self.linear(u.math.concatenate([x, previous], axis=-1))
|
|
67
|
-
return self.readout(self.neuron(current))
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The projection uses current units so `I * R` is voltage-compatible with membrane State and threshold.
|
|
71
|
-
|
|
72
|
-
## Train a batched spike sequence
|
|
73
|
-
|
|
74
|
-
Compile one-step behavior with per-sample mapped State, reset both State domains, accumulate masked step gradients through a scan, and update once per sequence.
|
|
75
|
-
|
|
76
|
-
| API | Description |
|
|
77
|
-
|---|---|
|
|
78
|
-
| `braintrace.compile(..., braintrace.pp_prop, batch_size=B, vmap=True, decay_or_rank=...)` | Use to create independent recurrent and trace State for each batch lane. |
|
|
79
|
-
| `brainstate.transform.grad(step_loss, weights, has_aux=True, return_value=True)` | Use around one learner call to return the online gradient, masked loss, and output. |
|
|
80
|
-
| `brainstate.transform.scan(...)` | Use to advance every time step and carry the summed gradient. |
|
|
81
|
-
| `brainstate.nn.clip_grad_norm(...)` | Use after accumulation when gradient clipping is required. |
|
|
82
|
-
|
|
83
|
-
```python
|
|
84
|
-
import jax
|
|
85
|
-
import jax.numpy as jnp
|
|
86
|
-
|
|
87
|
-
n_steps, batch_size = 60, 16
|
|
88
|
-
n_in, n_rec, n_out = 2, 48, 2
|
|
89
|
-
inputs = jnp.zeros((n_steps, batch_size, n_in))
|
|
90
|
-
labels = jnp.arange(batch_size, dtype=jnp.int32) % n_out
|
|
91
|
-
loss_mask = jnp.concatenate([jnp.zeros(50), jnp.ones(10)])
|
|
92
|
-
|
|
93
|
-
with brainstate.environ.context(dt=1. * u.ms):
|
|
94
|
-
model = LIF_SNN(n_in, n_rec, n_out)
|
|
95
|
-
learner = braintrace.compile(
|
|
96
|
-
model,
|
|
97
|
-
braintrace.pp_prop,
|
|
98
|
-
inputs[0],
|
|
99
|
-
batch_size=batch_size,
|
|
100
|
-
vmap=True,
|
|
101
|
-
decay_or_rank=0.9,
|
|
102
|
-
)
|
|
103
|
-
algorithm = learner.module
|
|
104
|
-
algorithm.report.show(2)
|
|
105
|
-
assert algorithm.report.counts['errors'] == 0
|
|
106
|
-
|
|
107
|
-
weights = model.states(brainstate.ParamState)
|
|
108
|
-
optimizer = braintools.optim.Adam(lr=2e-3)
|
|
109
|
-
optimizer.register_trainable_weights(weights)
|
|
110
|
-
|
|
111
|
-
mapped_states = learner.states('new')
|
|
112
|
-
|
|
113
|
-
@brainstate.transform.vmap(in_states=mapped_states)
|
|
114
|
-
def reset_sequence():
|
|
115
|
-
brainstate.nn.reset_all_states(learner)
|
|
116
|
-
|
|
117
|
-
def step_loss(cue, mask):
|
|
118
|
-
output = learner(cue)
|
|
119
|
-
loss = braintools.metric.softmax_cross_entropy_with_integer_labels(
|
|
120
|
-
output,
|
|
121
|
-
labels,
|
|
122
|
-
).mean()
|
|
123
|
-
return loss * mask, output
|
|
124
|
-
|
|
125
|
-
step_grad = brainstate.transform.grad(
|
|
126
|
-
step_loss,
|
|
127
|
-
weights,
|
|
128
|
-
has_aux=True,
|
|
129
|
-
return_value=True,
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
def train_sequence():
|
|
133
|
-
reset_sequence()
|
|
134
|
-
initial_grads = jax.tree.map(
|
|
135
|
-
jnp.zeros_like,
|
|
136
|
-
{key: state.value for key, state in weights.items()},
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
def accumulate(grads, sample):
|
|
140
|
-
current, loss, output = step_grad(*sample)
|
|
141
|
-
grads = jax.tree.map(lambda x, y: x + y, grads, current)
|
|
142
|
-
return grads, (loss, output)
|
|
143
|
-
|
|
144
|
-
grads, (losses, outputs) = brainstate.transform.scan(
|
|
145
|
-
accumulate,
|
|
146
|
-
initial_grads,
|
|
147
|
-
(inputs, loss_mask),
|
|
148
|
-
)
|
|
149
|
-
optimizer.update(brainstate.nn.clip_grad_norm(grads, 1.0))
|
|
150
|
-
return losses.sum() / loss_mask.sum(), outputs
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
`step_loss` calls the learner on every cue, delay, and report step. The zero mask removes the loss signal before the report window without freezing hidden or eligibility State. Do not put `optimizer.update()` inside the scan unless the intended experiment explicitly uses per-timestep parameter changes and reports that schedule.
|
|
20
|
+
Use ETP-aware native projections with a public `brainspike.Neuron` subclass. Open `brainspike` → `references/native-training.md` and `brainspike` → `scripts/train_native_snn.py` for the verified recurrent SNN, compiled pp-prop learner, State resets, and sequence update. The reduced Docker check verifies compiler participation, finite nonzero recurrent/readout gradients, decreasing loss, and a matched BPTT gradient direction. Do not transfer that result to an arbitrary NEST Simulator graph or assume estimator equality.
|
|
154
21
|
|
|
155
22
|
## Validate silent-delay memory
|
|
156
23
|
|
|
@@ -162,7 +29,7 @@ A lower training loss does not prove that the first cue survived the delay; use
|
|
|
162
29
|
| Frozen evaluation | Fix evaluation trials, seeds, masks, and metrics before viewing the trained result. |
|
|
163
30
|
| First-cue ablation | Replace or permute only the first cue and rerun the same mapped rollout; accuracy should fall materially relative to intact trials. |
|
|
164
31
|
| Robustness | Prefer held-out stochastic cue realizations or a nearby longer delay when the task permits them. |
|
|
165
|
-
| Schedule | Report sequences and optimizer updates separately; one
|
|
32
|
+
| Schedule | Report sequences and optimizer updates separately; one sequence-driver call followed by one update means one optimizer update per sequence. |
|
|
166
33
|
|
|
167
34
|
For a deterministic two-cue task with only four combinations, first-cue ablation is the minimum discriminating control. Perfect accuracy on the same four training combinations is insufficient by itself.
|
|
168
35
|
|
|
@@ -174,6 +41,5 @@ Open `compiler_internal.md` only when structured report records cannot explain t
|
|
|
174
41
|
|
|
175
42
|
## Sources
|
|
176
43
|
|
|
177
|
-
- [
|
|
178
|
-
- [
|
|
179
|
-
- [BrainTrace `v0.2.4` working-memory example](https://github.com/chaobrain/braintrace/blob/v0.2.4/examples/pp_prop/03-neurons-gif-working-memory.py)
|
|
44
|
+
- [pp-prop tutorial](https://brainx.chaobrain.com/braintrace/tutorials/pp_prop.html)
|
|
45
|
+
- [SNN online learning](https://brainx.chaobrain.com/braintrace/tutorials/snn_online_learning.html)
|
|
@@ -186,7 +186,7 @@ elementary_charge = u.constants.elementary_charge
|
|
|
186
186
|
|
|
187
187
|
## Normalize inputs and create ranges
|
|
188
188
|
|
|
189
|
-
Use `u.math.asarray()` to normalize plain data and quantities. Without `unit`, it returns
|
|
189
|
+
Use `u.math.asarray()` to normalize plain data and quantities. Without `unit`, it returns a plain array for plain data or preserves the input unit. With `unit=target`, it converts an existing quantity to `target`; a plain or dimensionless input raises `UnitMismatchError`, because `unit` selects a conversion rather than attaching a unit. `u.math.array` is an alias.
|
|
190
190
|
|
|
191
191
|
Use `u.math.arange()` to create half-open intervals `[start, stop)`, returning an array for plain arguments or a `Quantity` for unit-bearing arguments. Unit-bearing `start`, `stop`, and `step` must share one unit. At least one of `start` or `stop` is required.
|
|
192
192
|
|
|
@@ -204,6 +204,8 @@ times = u.math.arange(0.0 * u.ms, 10.0 * u.ms, 0.1 * u.ms)
|
|
|
204
204
|
# Expected: 100 values from 0.0 through 9.9 ms; array precision follows JAX.
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
+
Attach a unit to plain data by multiplication (`u.math.asarray(values) * u.mm`) or with a constructor that accepts `unit=` for new values (`u.math.ones`, `u.math.zeros`, `u.math.from_numpy`).
|
|
208
|
+
|
|
207
209
|
Do not strip units before normalization or attach a unit to an unchecked plain range afterward.
|
|
208
210
|
|
|
209
211
|
## Type and validate quantity boundaries
|
|
@@ -214,7 +216,10 @@ Annotations alone describe the contract. Apply `@u.typing.validate_units` when c
|
|
|
214
216
|
|
|
215
217
|
```python
|
|
216
218
|
def normalize(values: u.typing.QuantityLike, unit: u.typing.UnitLike = None):
|
|
217
|
-
|
|
219
|
+
data = u.math.asarray(values)
|
|
220
|
+
if unit is not None and isinstance(data, u.Quantity):
|
|
221
|
+
data = u.math.asarray(data, unit=unit)
|
|
222
|
+
return data
|
|
218
223
|
|
|
219
224
|
|
|
220
225
|
@u.typing.validate_units
|
package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md
CHANGED
|
@@ -87,4 +87,4 @@ Examples use concise `Quantity(..., "unit")` results; the exact displayed repres
|
|
|
87
87
|
## Sources mirrored
|
|
88
88
|
|
|
89
89
|
- https://brainunit.readthedocs.io/apis/brainunit.math.html
|
|
90
|
-
-
|
|
90
|
+
- Use the module index above to open the generated page for a specific function.
|
|
@@ -332,7 +332,7 @@ The original worked example, extended to cover all eight choices:
|
|
|
332
332
|
```python
|
|
333
333
|
import brainunit as u
|
|
334
334
|
|
|
335
|
-
x = u.math.asarray([1.0, 2.0, 3.0]
|
|
335
|
+
x = u.math.asarray([1.0, 2.0, 3.0]) * u.meter
|
|
336
336
|
|
|
337
337
|
total = u.math.sum(x)
|
|
338
338
|
# Expected: 6 m.
|
|
@@ -428,6 +428,6 @@ Use `einrearrange()` and `einrepeat()` through `array-mechanics.md` when element
|
|
|
428
428
|
|
|
429
429
|
- https://brainunit.readthedocs.io/apis/brainunit.math.html
|
|
430
430
|
- https://brainunit.readthedocs.io/unit_operations/einstein_operations.html
|
|
431
|
-
-
|
|
431
|
+
- Use the module index above to open the generated page for a specific function.
|
|
432
432
|
- https://brainunit.readthedocs.io/apis/generated/brainunit.math.einreduce.html
|
|
433
433
|
- https://brainunit.readthedocs.io/apis/generated/brainunit.math.einsum.html
|
|
@@ -14,7 +14,7 @@ Use this reference when a BrainUnit interface needs precise annotations, reusabl
|
|
|
14
14
|
| `HAS_UNIT` | Any `Quantity`, regardless of dimension | Only the presence of a unit-aware value matters |
|
|
15
15
|
| `LENGTH`, `TIME`, `SPEED`, and other pre-built aliases | A reusable named physical dimension | Repeated signatures should share a short domain term |
|
|
16
16
|
|
|
17
|
-
`QuantityLike` is intentionally broad and does not require a unit. Normalize it with `u.math.asarray()` before relying on array or unit properties.
|
|
17
|
+
`QuantityLike` is intentionally broad and does not require a unit. Normalize it with `u.math.asarray()` before relying on array or unit properties. Passing `unit=target` converts an existing quantity and raises `UnitMismatchError` for plain data, so attach a unit to plain values first when one is required.
|
|
18
18
|
|
|
19
19
|
```python
|
|
20
20
|
import brainunit as u
|
|
@@ -22,7 +22,10 @@ from brainunit.typing import QuantityLike, UnitLike
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def normalize(values: QuantityLike, unit: UnitLike = None):
|
|
25
|
-
|
|
25
|
+
data = u.math.asarray(values)
|
|
26
|
+
if unit is not None and isinstance(data, u.Quantity):
|
|
27
|
+
data = u.math.asarray(data, unit=unit)
|
|
28
|
+
return data
|
|
26
29
|
```
|
|
27
30
|
|
|
28
31
|
## Array and structural aliases
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ==============================================================================
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
# Implementation of the EI network from Brunel (1996) with the brainstate package.
|
|
18
|
-
#
|
|
19
|
-
# - Van Vreeswijk, Carl, and Haim Sompolinsky. “Chaos in neuronal networks with balanced
|
|
20
|
-
# excitatory and inhibitory activity.” Science 274.5293 (1996): 1724-1726.
|
|
21
|
-
#
|
|
22
|
-
# Dynamic of membrane potential is given as:
|
|
23
|
-
#
|
|
24
|
-
# $$ \tau \frac {dV_i}{dt} = -(V_i - V_{rest}) + I_i^{ext} + I_i^{net} (t) $$
|
|
25
|
-
#
|
|
26
|
-
# where $I_i^{net}(t)$ represents the synaptic current, which describes the sum of excitatory and inhibitory neurons.
|
|
27
|
-
#
|
|
28
|
-
# $$ I_i^{net} (t) = J_E \sum_{j=1}^{pN_e} \sum_{t_j^\alpha < t} f(t-t_j^\alpha ) - J_I \sum_{j=1}^{pN_i} \sum_{t_j^\alpha < t} f(t-t_j^\alpha )$$
|
|
29
|
-
#
|
|
30
|
-
# where
|
|
31
|
-
#
|
|
32
|
-
# $$ f(t) = \begin{cases} {\rm exp} (-\frac t {\tau_s} ), \quad t \geq 0 \\
|
|
33
|
-
# 0, \quad t < 0 \end{cases} $$
|
|
34
|
-
#
|
|
35
|
-
# Parameters: $J_E = \frac 1 {\sqrt {pN_e}}, J_I = \frac 1 {\sqrt {pN_i}}$
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import brainunit as u
|
|
40
|
-
import matplotlib.pyplot as plt
|
|
41
|
-
|
|
42
|
-
import brainpy
|
|
43
|
-
import brainstate
|
|
44
|
-
import braintools
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class EINet(brainstate.nn.Module):
|
|
48
|
-
def __init__(self, n_exc, n_inh, prob, JE, JI):
|
|
49
|
-
super().__init__()
|
|
50
|
-
self.n_exc = n_exc
|
|
51
|
-
self.n_inh = n_inh
|
|
52
|
-
self.num = n_exc + n_inh
|
|
53
|
-
|
|
54
|
-
# neurons
|
|
55
|
-
self.N = brainpy.state.LIF(
|
|
56
|
-
n_exc + n_inh,
|
|
57
|
-
V_rest=-52. * u.mV, V_th=-50. * u.mV, V_reset=-60. * u.mV, tau=10. * u.ms,
|
|
58
|
-
V_initializer=braintools.init.Normal(-60., 10., unit=u.mV), spk_reset='soft'
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
# synapses
|
|
62
|
-
self.E = brainpy.state.AlignPostProj(
|
|
63
|
-
comm=brainstate.nn.EventFixedProb(n_exc, self.num, prob, JE),
|
|
64
|
-
syn=brainpy.state.Expon.desc(self.num, tau=2. * u.ms),
|
|
65
|
-
out=brainpy.state.CUBA.desc(),
|
|
66
|
-
post=self.N,
|
|
67
|
-
)
|
|
68
|
-
self.I = brainpy.state.AlignPostProj(
|
|
69
|
-
comm=brainstate.nn.EventFixedProb(n_inh, self.num, prob, JI),
|
|
70
|
-
syn=brainpy.state.Expon.desc(self.num, tau=2. * u.ms),
|
|
71
|
-
out=brainpy.state.CUBA.desc(),
|
|
72
|
-
post=self.N,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
def update(self, inp):
|
|
76
|
-
spks = self.N.get_spike() != 0.
|
|
77
|
-
self.E(spks[:self.n_exc])
|
|
78
|
-
self.I(spks[self.n_exc:])
|
|
79
|
-
self.N(inp)
|
|
80
|
-
return self.N.get_spike()
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# connectivity
|
|
84
|
-
num_exc = 500
|
|
85
|
-
num_inh = 500
|
|
86
|
-
prob = 0.1
|
|
87
|
-
# external current
|
|
88
|
-
Ib = 3. * u.mA
|
|
89
|
-
# excitatory and inhibitory synaptic weights
|
|
90
|
-
JE = 1 / u.math.sqrt(prob * num_exc) * u.mS
|
|
91
|
-
JI = -1 / u.math.sqrt(prob * num_inh) * u.mS
|
|
92
|
-
|
|
93
|
-
# network
|
|
94
|
-
brainstate.environ.set(dt=0.1 * u.ms)
|
|
95
|
-
net = EINet(num_exc, num_inh, prob=prob, JE=JE, JI=JI)
|
|
96
|
-
brainstate.nn.init_all_states(net)
|
|
97
|
-
|
|
98
|
-
# simulation
|
|
99
|
-
times = u.math.arange(0. * u.ms, 1000. * u.ms, brainstate.environ.get_dt())
|
|
100
|
-
spikes = brainstate.transform.for_loop(lambda t: net.update(Ib), times, pbar=brainstate.transform.ProgressBar(10))
|
|
101
|
-
|
|
102
|
-
# visualization
|
|
103
|
-
t_indices, n_indices = u.math.where(spikes)
|
|
104
|
-
plt.scatter(times[t_indices], n_indices, s=1)
|
|
105
|
-
plt.xlabel('Time (ms)')
|
|
106
|
-
plt.ylabel('Neuron index')
|
|
107
|
-
plt.show()
|
package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 BrainX Ecosystem Limited. All Rights Reserved.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ==============================================================================
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import brainevent
|
|
18
|
-
import matplotlib.pyplot as plt
|
|
19
|
-
import numpy as np
|
|
20
|
-
from jax import vmap
|
|
21
|
-
from scipy.io import loadmat
|
|
22
|
-
|
|
23
|
-
import brainpy as bp
|
|
24
|
-
import brainpy.math as bm
|
|
25
|
-
from brainpy import neurons
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class MultiAreaNet(bp.Network):
|
|
29
|
-
def __init__(
|
|
30
|
-
self, hier, conn, delay_mat, muIE=0.0475, muEE=.0375, wII=.075,
|
|
31
|
-
wEE=.01, wIE=.075, wEI=.0375, extE=15.4, extI=14.0, alpha=4., seed=None,
|
|
32
|
-
):
|
|
33
|
-
super(MultiAreaNet, self).__init__()
|
|
34
|
-
|
|
35
|
-
# data
|
|
36
|
-
self.hier = hier
|
|
37
|
-
self.conn = conn
|
|
38
|
-
self.delay_mat = delay_mat
|
|
39
|
-
|
|
40
|
-
# parameters
|
|
41
|
-
self.muIE = muIE
|
|
42
|
-
self.muEE = muEE
|
|
43
|
-
self.wII = wII
|
|
44
|
-
self.wEE = wEE
|
|
45
|
-
self.wIE = wIE
|
|
46
|
-
self.wEI = wEI
|
|
47
|
-
self.extE = extE
|
|
48
|
-
self.extI = extI
|
|
49
|
-
self.alpha = alpha
|
|
50
|
-
num_area = hier.size
|
|
51
|
-
self.num_area = num_area
|
|
52
|
-
|
|
53
|
-
# neuron models
|
|
54
|
-
self.E = neurons.LIF((num_area, 1600),
|
|
55
|
-
V_th=-50., V_reset=-60.,
|
|
56
|
-
V_rest=-70., tau=20., tau_ref=2.,
|
|
57
|
-
noise=3. / bm.sqrt(20.),
|
|
58
|
-
V_initializer=bp.init.Uniform(-70., -50.),
|
|
59
|
-
method='exp_auto',
|
|
60
|
-
keep_size=True,
|
|
61
|
-
ref_var=True)
|
|
62
|
-
self.I = neurons.LIF((num_area, 400), V_th=-50., V_reset=-60.,
|
|
63
|
-
V_rest=-70., tau=10., tau_ref=2., noise=3. / bm.sqrt(10.),
|
|
64
|
-
V_initializer=bp.init.Uniform(-70., -50.),
|
|
65
|
-
method='exp_auto',
|
|
66
|
-
keep_size=True,
|
|
67
|
-
ref_var=True)
|
|
68
|
-
|
|
69
|
-
# delays
|
|
70
|
-
self.intra_delay_step = int(2. / bm.get_dt())
|
|
71
|
-
self.E_delay_steps = bm.asarray(delay_mat.T / bm.get_dt(), dtype=int)
|
|
72
|
-
bm.fill_diagonal(self.E_delay_steps, self.intra_delay_step)
|
|
73
|
-
self.Edelay = bm.LengthDelay(self.E.spike, delay_len=int(self.E_delay_steps.max()))
|
|
74
|
-
self.Idelay = bm.LengthDelay(self.I.spike, delay_len=self.intra_delay_step)
|
|
75
|
-
|
|
76
|
-
# synapses from I
|
|
77
|
-
self.intra_I2E_w = -wEI
|
|
78
|
-
self.intra_I2I_w = -wII
|
|
79
|
-
self.intra_I2I_seed = np.random.randint(0, 10000, num_area)
|
|
80
|
-
self.intra_I2E_seed = np.random.randint(0, 10000, num_area)
|
|
81
|
-
|
|
82
|
-
# synapses from E
|
|
83
|
-
self.E2E_seed = np.random.randint(0, 10000, (num_area, num_area))
|
|
84
|
-
self.E2I_seed = np.random.randint(0, 10000, (num_area, num_area))
|
|
85
|
-
self.E2E_weights = (1 + alpha * hier) * muEE * conn.T # inter-area connections
|
|
86
|
-
# intra-area connections
|
|
87
|
-
self.E2E_weights = bm.fill_diagonal(self.E2E_weights, (1 + alpha * hier) * wEE, inplace=False)
|
|
88
|
-
self.E2I_weights = (1 + alpha * hier) * muIE * conn.T # inter-area connections
|
|
89
|
-
# intra-area connections
|
|
90
|
-
self.E2I_weights = bm.fill_diagonal(self.E2I_weights, (1 + alpha * hier) * wIE, inplace=False)
|
|
91
|
-
|
|
92
|
-
def update(self, v1_input):
|
|
93
|
-
self.E.input[0] += v1_input
|
|
94
|
-
self.E.input += self.extE
|
|
95
|
-
self.I.input += self.extI
|
|
96
|
-
E_not_ref = bm.logical_not(self.E.refractory)
|
|
97
|
-
I_not_ref = bm.logical_not(self.I.refractory)
|
|
98
|
-
|
|
99
|
-
# synapses from E
|
|
100
|
-
f_E2E = vmap(lambda spk, weight, seed: brainevent.BinaryArray(spk) @ brainevent.JITCScalarC((weight, 0.1, seed), shape=(1600, 1600)))
|
|
101
|
-
f_E2I = vmap(lambda spk, weight, seed: brainevent.BinaryArray(spk) @ brainevent.JITCScalarC((weight, 0.1, seed), shape=(1600, 400)))
|
|
102
|
-
for i in range(self.num_area):
|
|
103
|
-
delayed_E_spikes = self.Edelay(self.E_delay_steps[i], i)
|
|
104
|
-
self.E.V += f_E2E(delayed_E_spikes, self.E2E_weights[i], self.E2E_seed[i]) * E_not_ref # E2E
|
|
105
|
-
self.I.V += f_E2I(delayed_E_spikes, self.E2I_weights[i], self.E2I_seed[i]) * I_not_ref # E2I
|
|
106
|
-
|
|
107
|
-
# synapses from I
|
|
108
|
-
delayed_I_spikes = self.Idelay(self.intra_delay_step)
|
|
109
|
-
f_I2E = vmap(lambda spk, seed: brainevent.BinaryArray(spk) @ brainevent.JITCScalarC((self.intra_I2E_w, 0.1, seed), shape=(400, 1600)))
|
|
110
|
-
self.E.V += f_I2E(delayed_I_spikes, self.intra_I2E_seed) * E_not_ref # I2E
|
|
111
|
-
f_I2I = vmap(lambda spk, seed: brainevent.BinaryArray(spk) @ brainevent.JITCScalarC((self.intra_I2I_w, 0.1, seed), shape=(400, 400)))
|
|
112
|
-
self.I.V += f_I2I(delayed_I_spikes, self.intra_I2I_seed) * I_not_ref # I2I
|
|
113
|
-
|
|
114
|
-
# updates
|
|
115
|
-
self.Edelay.update(self.E.spike)
|
|
116
|
-
self.Idelay.update(self.I.spike)
|
|
117
|
-
self.E.update()
|
|
118
|
-
self.I.update()
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def raster_plot(xValues, yValues, duration):
|
|
122
|
-
ticks = np.round(np.arange(0, 29) + 0.5, 2)
|
|
123
|
-
areas = ['V1', 'V2', 'V4', 'DP', 'MT', '8m', '5', '8l', 'TEO', '2', 'F1',
|
|
124
|
-
'STPc', '7A', '46d', '10', '9/46v', '9/46d', 'F5', 'TEpd', 'PBr',
|
|
125
|
-
'7m', '7B', 'F2', 'STPi', 'PROm', 'F7', '8B', 'STPr', '24c']
|
|
126
|
-
N = len(ticks)
|
|
127
|
-
plt.figure(figsize=(8, 6))
|
|
128
|
-
plt.plot(xValues, yValues / (4 * 400), '.', markersize=1)
|
|
129
|
-
plt.plot([0, duration], np.arange(N + 1).repeat(2).reshape(-1, 2).T, 'k-')
|
|
130
|
-
plt.ylabel('Area')
|
|
131
|
-
plt.yticks(np.arange(N))
|
|
132
|
-
plt.xlabel('Time [ms]')
|
|
133
|
-
plt.ylim(0, N)
|
|
134
|
-
plt.yticks(ticks, areas)
|
|
135
|
-
plt.xlim(0, duration)
|
|
136
|
-
plt.tight_layout()
|
|
137
|
-
plt.show()
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# hierarchy values
|
|
141
|
-
hierVals = loadmat('../Joglekar_2018_data/hierValspython.mat')
|
|
142
|
-
hierValsnew = hierVals['hierVals'].flatten()
|
|
143
|
-
hier = bm.asarray(hierValsnew / max(hierValsnew)) # hierarchy normalized.
|
|
144
|
-
|
|
145
|
-
# fraction of labeled neurons
|
|
146
|
-
flnMatp = loadmat('../Joglekar_2018_data/efelenMatpython.mat')
|
|
147
|
-
conn = bm.asarray(flnMatp['flnMatpython'].squeeze()) # fln values..Cij is strength from j to i
|
|
148
|
-
|
|
149
|
-
# Distance
|
|
150
|
-
speed = 3.5 # axonal conduction velocity
|
|
151
|
-
distMatp = loadmat('../Joglekar_2018_data/subgraphWiring29.mat')
|
|
152
|
-
distMat = distMatp['wiring'].squeeze() # distances between areas values..
|
|
153
|
-
delayMat = bm.asarray(distMat / speed)
|
|
154
|
-
|
|
155
|
-
pars = dict(extE=14.2, extI=14.7, wII=.075, wEE=.01, wIE=.075, wEI=.0375, muEE=.0375, muIE=0.0475)
|
|
156
|
-
inps = dict(value=15, duration=150)
|
|
157
|
-
|
|
158
|
-
inputs, length = bp.inputs.section_input(values=[0, inps['value'], 0.],
|
|
159
|
-
durations=[300., inps['duration'], 500],
|
|
160
|
-
return_length=True)
|
|
161
|
-
|
|
162
|
-
net = MultiAreaNet(hier, conn, delayMat, **pars)
|
|
163
|
-
runner = bp.DSRunner(net, monitors={'E.spike': lambda: net.E.spike.flatten()})
|
|
164
|
-
runner.run(inputs=inputs)
|
|
165
|
-
|
|
166
|
-
times, indices = np.where(runner.mon['E.spike'])
|
|
167
|
-
times = runner.mon.ts[times]
|
|
168
|
-
raster_plot(times, indices, length)
|