brainx-skill 1.0.14 → 1.0.16

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.
Files changed (171) hide show
  1. package/README.md +17 -1
  2. package/manifest.json +1 -1
  3. package/mcp-servers/codex/skills.json +1 -1
  4. package/package.json +1 -1
  5. package/skills/bio-neuro-lit/SKILL.md +4 -2
  6. package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
  7. package/skills/brainx-acceleration/SKILL.md +30 -437
  8. package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
  9. package/skills/brainx-general-guard/SKILL.md +24 -8
  10. package/skills/brainx-install/SKILL.md +3 -3
  11. package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
  12. package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
  13. package/skills/brainx-modeling-loop/SKILL.md +143 -36
  14. package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
  15. package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
  16. package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
  17. package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
  18. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
  19. package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
  20. package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
  21. package/skills/brainx-visualization/SKILL.md +6 -2
  22. package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
  23. package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
  24. package/skills/package-skills/braincell/SKILL.md +23 -14
  25. package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
  26. package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
  27. package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
  28. package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
  29. package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
  30. package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
  31. package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
  32. package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
  33. package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
  34. package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
  35. package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
  36. package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
  37. package/skills/package-skills/brainevent/SKILL.md +0 -3
  38. package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
  39. package/skills/package-skills/brainmass/SKILL.md +5 -3
  40. package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
  41. package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  42. package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
  43. package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
  44. package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
  45. package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
  46. package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
  47. package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
  48. package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
  49. package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
  50. package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
  51. package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
  52. package/skills/package-skills/brainspike/SKILL.md +201 -0
  53. package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
  54. package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
  55. package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
  56. package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
  57. package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
  58. package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
  59. package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
  60. package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
  61. package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
  62. package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
  63. package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
  64. package/skills/package-skills/brainspike/references/native-composition.md +52 -0
  65. package/skills/package-skills/brainspike/references/native-delays.md +34 -0
  66. package/skills/package-skills/brainspike/references/native-projections.md +43 -0
  67. package/skills/package-skills/brainspike/references/native-training.md +36 -0
  68. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
  69. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
  70. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
  71. package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
  72. package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
  73. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
  74. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
  75. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
  76. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
  77. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
  78. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
  79. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
  80. package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
  81. package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
  82. package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
  83. package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
  84. package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
  85. package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
  86. package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
  87. package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
  88. package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
  89. package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
  90. package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
  91. package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
  92. package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
  93. package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
  94. package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
  95. package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
  96. package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
  97. package/skills/package-skills/brainstate/SKILL.md +16 -21
  98. package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
  99. package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  100. package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
  101. package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
  102. package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  103. package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
  104. package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
  105. package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
  106. package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
  107. package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
  108. package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
  109. package/skills/package-skills/braintrace/SKILL.md +17 -38
  110. package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
  111. package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
  112. package/skills/package-skills/braintrace/references/batching.md +15 -35
  113. package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
  114. package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
  115. package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
  116. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
  117. package/skills/package-skills/brainunit/SKILL.md +7 -2
  118. package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
  119. package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
  120. package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
  121. package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
  122. package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
  123. package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
  124. package/skills/package-skills/brainpy-state/SKILL.md +0 -247
  125. package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
  126. package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
  127. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
  128. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
  129. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
  130. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
  131. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
  132. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
  133. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
  134. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
  135. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
  136. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
  137. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
  138. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
  139. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
  140. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
  141. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
  142. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
  143. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
  144. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
  145. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
  146. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
  147. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
  148. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
  149. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
  150. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
  151. package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
  152. package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
  153. package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
  154. package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
  155. package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
  156. package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
  157. package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
  158. package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
  159. package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
  160. package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
  161. package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
  162. package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
  163. package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
  164. package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
  165. package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
  166. package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
  167. package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
  168. package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
  169. package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
  170. package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
  171. package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
@@ -1,102 +0,0 @@
1
- # Route activity through connectivity
2
-
3
- Use this reference when legacy `brainpy.math` code must expand presynaptic values to synapses or reduce edge values onto postsynaptic neurons. These operators execute activity routing over known indices; use `brainpy.connect` to construct the connectivity itself.
4
-
5
- ## Selection map
6
-
7
- | Available data | Required result | Use |
8
- |---|---|---|
9
- | One scalar or one value per presynaptic neuron plus edge endpoint indices | One reduced value per postsynaptic neuron | A `pre2post_*` operator. |
10
- | One value per presynaptic neuron plus `pre_ids` | One value per edge | `pre2syn(...)`. |
11
- | One value per edge plus `post_ids` | Reduced values per postsynaptic neuron | A `syn2post_*` operator. |
12
- | Boolean presynaptic events plus CSR pre-to-post structure | Event-driven weighted sums per postsynaptic neuron | `pre2post_event_sum(...)`. |
13
-
14
- ## Route presynaptic values directly to postsynaptic neurons
15
-
16
- These operators gather values through `pre_ids` and reduce all incoming edges addressed by `post_ids`.
17
-
18
- | API | Description |
19
- |---|---|
20
- | `pre2post_sum(pre_values, post_num, post_ids, pre_ids=None)` | Sum incoming presynaptic values for each postsynaptic neuron and return length `post_num`. |
21
- | `pre2post_prod(pre_values, post_num, post_ids, pre_ids=None)` | Multiply incoming values into a zero-initialized postsynaptic array; see the warning below before using it for a true product reduction. |
22
- | `pre2post_max(pre_values, post_num, post_ids, pre_ids=None)` | Reduce incoming values by maximum against a zero-initialized postsynaptic array. |
23
- | `pre2post_min(pre_values, post_num, post_ids, pre_ids=None)` | Reduce incoming values by minimum against a zero-initialized postsynaptic array. |
24
- | `pre2post_mean(pre_values, post_num, post_ids, pre_ids=None)` | Average incoming presynaptic values for each postsynaptic neuron. |
25
-
26
- **Invariant:** pass `pre_ids` whenever `pre_values` is not scalar. Without it, BrainPy cannot determine which presynaptic value belongs to each edge.
27
-
28
- **Zero-baseline warning:** the documented `pre2post_prod`, `pre2post_max`, and `pre2post_min` implementations start from zeros. Consequently, `pre2post_prod` keeps targeted outputs at zero, `pre2post_max` returns zero for an all-negative incoming group, and `pre2post_min` returns zero for an all-positive incoming group. Use `pre2syn(...)` followed by the corresponding `syn2post_*` segment reduction when those zero-baseline semantics are not intended.
29
-
30
- For scalar `pre_values`, `pre2post_mean(...)` assigns that constant to targeted postsynaptic neurons and leaves untargeted neurons at zero; duplicate targets do not change the mean of identical values.
31
-
32
- ## Expand presynaptic values to edge values
33
-
34
- Use `pre2syn(...)` when a synaptic rule must operate once per connection before postsynaptic reduction.
35
-
36
- | API | Description |
37
- |---|---|
38
- | `pre2syn(pre_values, pre_ids)` | Gather `pre_values[pre_ids]` and return one value per synapse; a scalar input is repeated for every edge. |
39
-
40
- The returned edge order is exactly the order of `pre_ids`. Preserve that order through any edge-local kinetics or weight computation so it still aligns with `post_ids`.
41
-
42
- ## Reduce edge values onto postsynaptic neurons
43
-
44
- Use these after edge-local state, delays, kinetics, or weights have produced one value per synapse.
45
-
46
- | API | Description |
47
- |---|---|
48
- | `syn2post_sum(syn_values, post_ids, post_num, indices_are_sorted=False)` | Sum edge values for each postsynaptic neuron. |
49
- | `syn2post(syn_values, post_ids, post_num, indices_are_sorted=False)` | Alias of `syn2post_sum(...)`. |
50
- | `syn2post_prod(syn_values, post_ids, post_num, indices_are_sorted=False)` | Multiply edge values within each postsynaptic segment. |
51
- | `syn2post_max(syn_values, post_ids, post_num, indices_are_sorted=False)` | Take the maximum edge value within each postsynaptic segment. |
52
- | `syn2post_min(syn_values, post_ids, post_num, indices_are_sorted=False)` | Take the minimum edge value within each postsynaptic segment. |
53
- | `syn2post_mean(syn_values, post_ids, post_num, indices_are_sorted=False)` | Average edge values within each postsynaptic segment. |
54
- | `syn2post_softmax(syn_values, post_ids, post_num, indices_are_sorted=False)` | Normalize edge values with a separate softmax over the edges entering each postsynaptic neuron. |
55
-
56
- Set `indices_are_sorted=True` only when `post_ids` is known to be sorted, such as indices supplied in that order by the relevant BrainPy connector. Leave it `False` for arbitrary edge lists.
57
-
58
- ## Route boolean events through CSR connectivity
59
-
60
- Use the event operator when presynaptic activity is boolean and connectivity is already in CSR pre-to-post form.
61
-
62
- | API | Description |
63
- |---|---|
64
- | `pre2post_event_sum(events, pre2post, post_num, values=1.0)` | Sum weights from active presynaptic events; `pre2post` is `(post_ids, indptr)`, and `values` is either scalar or one value per stored edge. |
65
- | `pre2post_csr_event_sum(events, pre2post, post_num, values=1.0)` | Alias of `pre2post_event_sum(...)`. |
66
-
67
- **Invariant:** `events` must be boolean, and `indptr` must partition `post_ids` by presynaptic neuron. A coordinate edge list is not a valid replacement for this CSR tuple.
68
-
69
- ## Canonical workflow
70
-
71
- Keep `pre_ids` and `post_ids` aligned as one edge list, expand only when edge-local computation is required, and reduce with the matching postsynaptic IDs:
72
-
73
- ```python
74
- import brainpy.math as bm
75
-
76
- pre_values = bm.asarray([2.0, 3.0, 5.0])
77
- pre_ids = bm.asarray([0, 0, 1, 2])
78
- post_ids = bm.asarray([0, 1, 1, 0])
79
-
80
- syn_values = bm.pre2syn(pre_values, pre_ids)
81
- post_values = bm.syn2post_sum(
82
- syn_values,
83
- post_ids,
84
- post_num=2,
85
- )
86
- direct_values = bm.pre2post_sum(
87
- pre_values,
88
- post_num=2,
89
- post_ids=post_ids,
90
- pre_ids=pre_ids,
91
- )
92
-
93
- assert syn_values.shape == (4,)
94
- assert bm.allclose(post_values, bm.asarray([7.0, 5.0]))
95
- assert bm.allclose(direct_values, post_values)
96
- ```
97
-
98
- Use the direct route when no per-synapse computation is needed. Use `pre2syn(...)` followed by a `syn2post_*` reduction when the edge values must be transformed independently.
99
-
100
- ## Sources
101
-
102
- - https://brainpy.readthedocs.io/apis/brainpy.math.pre_syn_post.html
@@ -1,147 +0,0 @@
1
- # Synaptic projections
2
-
3
- Use this reference when a legacy BrainPy model needs a composed `brainpy.dyn`
4
- projection. Select the projection from who supplies presynaptic activity, where
5
- synaptic state is stored, whether compatible state should be merged, and whether
6
- the response is instantaneous. Open `synpase properties.md` after making these
7
- structural decisions to select the synaptic dynamics and output.
8
-
9
- ## Selection map
10
-
11
- | Need | Use | Critical invariant |
12
- |---|---|---|
13
- | The projection owns `pre`, delay, communication, synapse, output, and `post` | A `FullProj...` class | Call it with no spike argument; it reads the registered presynaptic system. |
14
- | The caller already has the presynaptic value | A `HalfProj...` class | Pass the value to the projection on every update. |
15
- | Synaptic state should have postsynaptic size | An align-post class | Internal order is `spikes -> comm -> syn -> out`; prefer event-driven communication. |
16
- | Synaptic state should have presynaptic size | An align-pre class | Internal order places `syn` before `comm`; choose whether delay occurs before or after `syn`. |
17
- | Compatible delay and synapse state should be shared | A class ending in `Mg` | `Mg` means automatic merging here; it does not mean magnesium block. |
18
- | Spikes should produce instantaneous target increments | `HalfProjDelta` or `FullProjDelta` | Input must be spiking data; these projections omit rise and decay state. |
19
-
20
- ## Projection anatomy
21
-
22
- A chemical projection composes distinct roles; keep them separate so changing
23
- connectivity does not silently change the synaptic waveform or current law.
24
-
25
- | Role | Decision |
26
- |---|---|
27
- | `pre` | Supplies presynaptic state to a full-chain projection. |
28
- | `delay` | Delays presynaptic spikes or synaptic state, depending on the align-pre class. |
29
- | `comm` | Maps values from presynaptic to postsynaptic dimensions and applies connection weights. |
30
- | `syn` | Evolves the conductance or other synaptic state over time. |
31
- | `out` | Converts synaptic state into the input accumulated on `post`. |
32
- | `post` | Receives the projected input before its own state update. |
33
-
34
- Use full-chain projections when the projection belongs inside a network graph.
35
- Use half-chain projections for external inputs, trainable layers, or another
36
- workflow that already owns presynaptic extraction.
37
-
38
- ## Align-post projections
39
-
40
- Use align-post when synaptic variables should scale with the postsynaptic
41
- population. These projections compute communication from spikes before updating
42
- the synapse, so use event-driven `comm` implementations for sparse spike input.
43
-
44
- | API | Description |
45
- |---|---|
46
- | `HalfProjAlignPostMg(comm, syn, out, post, out_label=None, ...)` | Use with caller-supplied spikes when compatible postsynaptic synapse state should be merged; it implements `comm -> syn -> out -> post`. |
47
- | `FullProjAlignPostMg(pre, delay, comm, syn, out, post, out_label=None, ...)` | Use for the complete registered chain with automatic delay and synapse merging; pass mergeable `syn` and `out` descriptors. |
48
- | `HalfProjAlignPost(comm, syn, out, post, out_label=None, ...)` | Use with caller-supplied spikes when the projection must own independent postsynaptic synapse state. |
49
- | `FullProjAlignPost(pre, delay, comm, syn, out, post, out_label=None, ...)` | Use for a complete registered chain with independent postsynaptic synapse state. |
50
-
51
- The current legacy API uses `FullProjAlignPostMg`; do not copy the older
52
- `ProjAlignPostMg2` spelling from historical tutorial cells.
53
-
54
- ```python
55
- import brainpy as bp
56
-
57
-
58
- class EINet(bp.DynSysGroup):
59
- def __init__(self, n_exc=3200, n_inh=800):
60
- super().__init__()
61
- self.exc = bp.dyn.LifRef(n_exc)
62
- self.inh = bp.dyn.LifRef(n_inh)
63
- self.e2i = bp.dyn.FullProjAlignPostMg(
64
- pre=self.exc,
65
- delay=0.1,
66
- comm=bp.dnn.EventJitFPHomoLinear(
67
- n_exc,
68
- n_inh,
69
- prob=0.02,
70
- weight=0.6,
71
- ),
72
- syn=bp.dyn.Expon.desc(size=n_inh, tau=5.0),
73
- out=bp.dyn.COBA.desc(E=0.0),
74
- post=self.inh,
75
- )
76
-
77
- def update(self, drive):
78
- self.e2i()
79
- self.exc(drive)
80
- self.inh(drive)
81
- return self.exc.spike, self.inh.spike
82
- ```
83
-
84
- Preserve the grouped-network update order shown by the generated API example:
85
- apply the full projection before updating the receiving population so its input
86
- is available to that update.
87
-
88
- ## Align-pre projections
89
-
90
- Use align-pre when synaptic variables should scale with the presynaptic
91
- population. Communication receives floating-point synaptic state rather than
92
- spikes, so these classes do not provide the event-driven communication advantage
93
- of align-post projections.
94
-
95
- | API | Description |
96
- |---|---|
97
- | `VanillaProj(comm, out, post, name=None, mode=None)` | Use when the caller supplies an already prepared presynaptic value and no delay or dynamic synapse belongs in the projection; it applies communication and output conversion. |
98
- | `FullProjAlignPreSDMg(pre, syn, delay, comm, out, post, ...)` | Use when synaptic state must update before it is delayed; it implements `pre -> syn -> delay -> comm -> out -> post` and merges compatible state. |
99
- | `FullProjAlignPreDSMg(pre, delay, syn, comm, out, post, ...)` | Use when presynaptic output must be delayed before synaptic state updates; it implements `pre -> delay -> syn -> comm -> out -> post` and merges compatible state. |
100
- | `FullProjAlignPreSD(pre, syn, delay, comm, out, post, ...)` | Use the synapse-then-delay order when every projection must own independent state. |
101
- | `FullProjAlignPreDS(pre, delay, syn, comm, out, post, ...)` | Use the delay-then-synapse order when every projection must own independent state. |
102
-
103
- Choose `DS` when delay represents axonal transmission before receptor dynamics.
104
- Choose `SD` only when the modeled delay applies to the evolved synaptic state.
105
-
106
- ## Delta projections
107
-
108
- Delta projections transmit an instantaneous weighted jump and do not construct a
109
- temporal synapse or synaptic output object.
110
-
111
- | API | Description |
112
- |---|---|
113
- | `HalfProjDelta(comm, post, name=None, mode=None)` | Use for caller-supplied spikes and an instantaneous target increment. |
114
- | `FullProjDelta(pre, delay, comm, post, name=None, mode=None)` | Use when the registered presynaptic group and delay belong to the instantaneous projection. |
115
-
116
- Do not pass continuous rates or currents to a delta projection. Use `VanillaProj`
117
- or an align-post projection with explicit dynamics for those signals.
118
-
119
- ## Projection-adjacent inputs
120
-
121
- The projection API also exposes input helpers. Use them when an input should
122
- target a variable directly rather than arrive through a neuron-to-neuron
123
- chemical projection.
124
-
125
- | API | Description |
126
- |---|---|
127
- | `PoissonInput(target_var, num_input, freq, weight, mode=None, name=None)` | Use for many independent homogeneous Poisson inputs to one target variable; it generates events during simulation without storing spike trains. |
128
- | `InputVar(size, keep_size=False, ..., name=None, mode=None)` | Use to represent an explicit input variable inside a dynamical-system graph. |
129
- | `SynConn(pre, post, conn=None, name=None, mode=None)` | Subclass only when implementing a new two-end connection abstraction; it binds the pre/post systems and optional connector. |
130
-
131
- ## Common failures
132
-
133
- - Do not interpret an `Mg` projection suffix as `MgBlock`; merging and
134
- magnesium-dependent output are independent choices.
135
- - Do not use an align-pre class merely because the source is presynaptic. Choose
136
- alignment from synaptic-state dimension and internal execution order.
137
- - Do not use non-event communication in an align-post spike path without a
138
- concrete reason; the API explicitly prefers event-driven communication.
139
- - Do not update `post` before the projection has deposited the current step's
140
- input.
141
- - Do not copy `brainpy.dyn` projection names or construction patterns from a
142
- different BrainPy implementation. This reference covers the legacy API only.
143
-
144
- ## Sources
145
-
146
- - Phenomenological Synaptic Models: https://brainpy.readthedocs.io/tutorial_building/phenon_synapse_models.html
147
- - Synaptic Projections API: https://brainpy.readthedocs.io/apis/brainpy.dyn.projections.html
@@ -1,159 +0,0 @@
1
- # Synapse properties
2
-
3
- Use this reference when a legacy BrainPy projection needs synaptic dynamics,
4
- short-term filtering, output-current semantics, coupling, or long-term
5
- plasticity. Open `synaptic projections.md` first when alignment, merging, delay
6
- order, or half-chain versus full-chain ownership is still undecided.
7
-
8
- ## Selection map
9
-
10
- | Modeled property | Use | Key constraint |
11
- |---|---|---|
12
- | One exponential decay after each spike | `Expon` | Use as the canonical low-state phenomenological filter. |
13
- | An alpha-shaped response | `Alpha` | Rise and decay are represented by the alpha limit. |
14
- | Separate rise and decay constants | `DualExpon` or `DualExponV2` | `DualExpon` is align-pre-only; `DualExponV2` supports align-pre and align-post. |
15
- | Saturating slow NMDA gating | `NMDA` | Pair with `MgBlock` when voltage-dependent magnesium block must affect current. |
16
- | Receptor binding and unbinding | `AMPA`, `GABAa`, or `BioNMDA` | Use align-pre for these kinetic state models. |
17
- | Recent spikes change release efficacy | `STD` or `STP` | These filter transmission state; they do not persistently rewrite connection weights. |
18
- | Voltage-dependent versus independent current | `COBA`, `MgBlock`, or `CUBA` | Select output semantics separately from synaptic dynamics. |
19
- | Spike timing persistently changes weights | `STDP_Song2000` | The projection updates the communication weight during simulation. |
20
-
21
- ## Phenomenological dynamics
22
-
23
- Phenomenological models prescribe a conductance waveform from spike events; use
24
- the least complex waveform that preserves the timing required by the experiment.
25
-
26
- | API | Description |
27
- |---|---|
28
- | `Expon(size, tau=8.0, ...)` | Use for instantaneous activation followed by a single exponential decay; `tau` is the decay time constant in milliseconds. |
29
- | `Alpha(size, tau_decay=10.0, ...)` | Use for an alpha-shaped response when a distinct rise constant is unnecessary. |
30
- | `DualExpon(size, tau_decay=10.0, tau_rise=1.0, A=None, ...)` | Use for separate rise and decay phases in align-pre projections; it implements the waveform through two coupled linear equations. |
31
- | `DualExponV2(size, tau_decay=10.0, tau_rise=1.0, A=None, ...)` | Use for the same dual-exponential choice when align-post compatibility is required; it also works with align-pre. |
32
- | `NMDA(size, a=0.5, tau_decay=100.0, tau_rise=2.0, ...)` | Use for phenomenological NMDA gating with a slow decay and saturating rise; use `MgBlock` to add postsynaptic-voltage dependence to the output. |
33
-
34
- The alpha response is the limiting dual-exponential case when rise and decay
35
- constants become equal. Do not substitute `DualExpon` into an align-post
36
- projection; use `DualExponV2` there.
37
-
38
- ## Receptor-kinetic dynamics
39
-
40
- Kinetic models track fractions of receptors in closed and open states; choose
41
- them when receptor saturation under spike trains is part of the modeled result.
42
-
43
- | API | Description |
44
- |---|---|
45
- | `AMPA(size, alpha=0.98, beta=0.18, T=0.5, T_dur=0.5, ...)` | Use for AMPA binding and unbinding with transmitter concentration `T` applied for `T_dur`. |
46
- | `GABAa(size, alpha=0.53, beta=0.18, T=1.0, T_dur=1.0, ...)` | Use for GABA-A kinetics; select inhibitory current through the output reversal potential rather than by changing this state equation. |
47
- | `BioNMDA(size, alpha1=2.0, beta1=0.01, alpha2=1.0, beta2=0.5, T=1.0, T_dur=0.5, ...)` | Use for second-order biological NMDA kinetics with separate conversion rates for the `g` and `x` variables. |
48
-
49
- ```python
50
- import brainpy as bp
51
-
52
-
53
- class AMPAProjection(bp.Projection):
54
- def __init__(self, pre, post, delay, probability, g_max, E=0.0):
55
- super().__init__()
56
- self.proj = bp.dyn.FullProjAlignPreDSMg(
57
- pre=pre,
58
- delay=delay,
59
- syn=bp.dyn.AMPA.desc(
60
- pre.num,
61
- alpha=0.98,
62
- beta=0.18,
63
- T=0.5,
64
- T_dur=0.5,
65
- ),
66
- comm=bp.dnn.CSRLinear(
67
- bp.conn.FixedProb(
68
- probability,
69
- pre=pre.num,
70
- post=post.num,
71
- ),
72
- g_max,
73
- ),
74
- out=bp.dyn.COBA(E=E),
75
- post=post,
76
- )
77
-
78
- def update(self):
79
- return self.proj()
80
- ```
81
-
82
- This uses delay-before-synapse align-pre composition: presynaptic spikes are
83
- delayed, receptor state is updated, communication maps that state, and `COBA`
84
- converts it to postsynaptic input.
85
-
86
- ## Short-term efficacy
87
-
88
- Short-term models filter current according to recent activity without changing
89
- the stored long-term connection weight.
90
-
91
- | API | Description |
92
- |---|---|
93
- | `STD(size, tau=200.0, U=0.07, ...)` | Use for depression only; it tracks the available-resource fraction `x`. |
94
- | `STP(size, U=0.15, tau_f=1500.0, tau_d=200.0, ...)` | Use for facilitation and depression; it tracks release utilization `u` and available resources `x`. |
95
-
96
- Keep `STD` and `STP` aligned to the dimension at which presynaptic release
97
- history is represented. Do not describe their changing effective transmission
98
- as long-term weight learning.
99
-
100
- ## Synaptic outputs
101
-
102
- Synaptic dynamics produce a conductance-like state; a `SynOut` converts it into
103
- the signal accumulated by the receiving model.
104
-
105
- | API | Description |
106
- |---|---|
107
- | `SynOut(name=None, scaling=None)` | Subclass only when the built-in current laws cannot express the required output; it is the base output descriptor. |
108
- | `COBA(E, sharding=None, name=None, scaling=None)` | Use for conductance-based current whose magnitude and direction depend on postsynaptic voltage and reversal potential `E`. |
109
- | `CUBA(name=None, scaling=None)` | Use for current-based transmission; it passes the communicated synaptic value through an identity output. |
110
- | `MgBlock(E=0.0, cc_Mg=1.2, alpha=0.062, beta=3.57, V_offset=0.0, ...)` | Use for NMDA-like conductance with postsynaptic-voltage-dependent magnesium block. |
111
-
112
- Changing `COBA` to `CUBA` is a modeling change, not a syntax change. Recheck
113
- weight sign, magnitude, and network operating point after changing output law.
114
-
115
- ## Coupling models
116
-
117
- Use coupling models for direct state-to-state coupling rather than a chemical
118
- spike-to-conductance projection.
119
-
120
- | API | Description |
121
- |---|---|
122
- | `DiffusiveCoupling(coupling_var1, coupling_var2, var_to_output, conn_mat, delay_steps=None, ...)` | Use when output depends on a connected difference between two coupling variables; the first variable owns optional delay. |
123
- | `AdditiveCoupling(coupling_var, var_to_output, conn_mat, delay_steps=None, ...)` | Use when connected source values should be added directly to one or more target variables. |
124
-
125
- ## Long-term spike-timing plasticity
126
-
127
- `STDP_Song2000` is a complete full-chain plastic projection, not a standalone
128
- synaptic filter.
129
-
130
- | API | Description |
131
- |---|---|
132
- | `STDP_Song2000(pre, delay, syn, comm, out, post, tau_s=16.8, tau_t=33.7, A1=0.96, A2=0.53, W_max=None, W_min=None, ...)` | Use for Song et al. pair-based STDP; it tracks pre/post traces and updates `comm.weight`, optionally clipping it with `W_min` and `W_max`. |
133
-
134
- Use an event-driven communication object with mutable weights, pass the temporal
135
- filter and output as descriptors, and inspect `projection.comm.weight` to verify
136
- learning. Call the STDP projection before updating its registered pre- and
137
- postsynaptic groups, matching the generated API example.
138
-
139
- ## Common failures
140
-
141
- - Do not choose a kinetic receptor model when a single exponential waveform is
142
- sufficient; kinetic state is justified only when saturation or binding
143
- dynamics affect the result.
144
- - Do not pair `DualExpon` with align-post; use `DualExponV2`.
145
- - Do not expect `NMDA` alone to apply postsynaptic-voltage-dependent magnesium
146
- block; select `MgBlock` as the output.
147
- - Do not treat reversal potential as a cosmetic parameter; it controls the
148
- direction and voltage dependence of conductance-based current.
149
- - Do not conflate `STP` or `STD` with `STDP_Song2000`; only the latter rewrites
150
- long-term communication weights.
151
- - Do not copy these `brainpy.dyn` APIs into a different BrainPy implementation.
152
- This reference covers the legacy API only.
153
-
154
- ## Sources
155
-
156
- - Synaptic Dynamics API: https://brainpy.readthedocs.io/apis/brainpy.dyn.synapses.html
157
- - Synaptic Outputs API: https://brainpy.readthedocs.io/apis/brainpy.dyn.outs.html
158
- - Synaptic Plasticity API: https://brainpy.readthedocs.io/apis/brainpy.dyn.plasticity.html
159
- - Kinetic Synaptic Models: https://brainpy.readthedocs.io/tutorial_building/kinetic_synapse_models.html
@@ -1,127 +0,0 @@
1
- # Legacy BrainPy loss library
2
-
3
- Use this reference to select a `brainpy.losses` objective or regularizer for a
4
- legacy BrainPy training workflow. Choose from the prediction representation,
5
- target representation, and required reduction before connecting the loss to
6
- `bm.grad`, a legacy trainer, or `bp.optim`.
7
-
8
- ## Choose a classification representation
9
-
10
- The main decision is whether targets are class indices, mutually exclusive
11
- probability vectors, or independent binary labels.
12
-
13
- | API | Description |
14
- |---|---|
15
- | `bp.losses.cross_entropy_loss(predicts, targets, weight=None, reduction='mean', ignore_index=-100, label_smoothing=0.0)` | Use raw class logits with class-index or supported probability targets; use this full interface for class weights, ignored indices, reduction, or label smoothing. |
16
- | `bp.losses.cross_entropy_sparse(predicts, targets)` | Use logits shaped `(..., n_class)` with sparse integer class indices shaped without the class axis. |
17
- | `bp.losses.cross_entropy_sigmoid(predicts, targets)` | Use logits and same-shaped class-probability targets. |
18
- | `bp.losses.nll_loss(input, target, reduction='mean')` | Use only when `input` already contains log-probabilities and `target` contains class indices. |
19
- | `bp.losses.softmax_cross_entropy(logits, labels)` | Use mutually exclusive classes represented by a same-shaped probability distribution or one-hot labels. |
20
- | `bp.losses.sigmoid_binary_cross_entropy(logits, labels)` | Use independent binary labels for multilabel classification; classes are not mutually exclusive. |
21
- | `bp.losses.binary_logistic_loss(predicts, targets)` | Use a scalar binary score with an integer target of 0 or 1. |
22
- | `bp.losses.multiclass_logistic_loss(label, logits)` | Use one class index with one vector of class logits. Note the legacy argument order: label first. |
23
- | `bp.losses.multi_margin_loss(predicts, targets, margin=1.0, p=1, reduction='mean')` | Use the multiclass hinge objective when the correct class score must exceed other scores by a margin. |
24
-
25
- ```python
26
- import brainpy as bp
27
- import brainpy.math as bm
28
-
29
- logits = bm.array([
30
- [2.0, -1.0, 0.5],
31
- [-0.5, 0.2, 1.8],
32
- ])
33
- class_ids = bm.array([0, 2])
34
-
35
- loss = bp.losses.cross_entropy_loss(logits, class_ids)
36
- assert loss.ndim == 0
37
- ```
38
-
39
- Pass raw, unnormalized scores to cross-entropy functions. Do not apply softmax
40
- before `cross_entropy_loss`; use `nll_loss` only after producing
41
- log-probabilities. A sparse target removes the final class axis; probability or
42
- multilabel targets retain it.
43
-
44
- ## Choose a regression loss
45
-
46
- Choose the reduction and outlier behavior deliberately; similarly named losses
47
- do not have identical scaling.
48
-
49
- | API | Description |
50
- |---|---|
51
- | `bp.losses.l1_loss(logits, targets, reduction='mean')` | Use absolute elementwise error with `'none'`, `'mean'`, or `'sum'` reduction. |
52
- | `bp.losses.mean_absolute_error(x, y, axis=None, reduction='mean')` | Use mean absolute error with an explicit reduction axis when needed. |
53
- | `bp.losses.l2_loss(predicts, targets)` | Use the legacy L2 objective containing the documented `0.5` factor. |
54
- | `bp.losses.mean_squared_error(predicts, targets, axis=None, reduction='mean')` | Use squared error with explicit axes and reduction control. |
55
- | `bp.losses.mean_squared_log_error(predicts, targets, axis=None, reduction='mean')` | Use squared error in the logarithmic value domain. |
56
- | `bp.losses.huber_loss(predicts, targets, delta=1.0)` | Use quadratic behavior near zero and L1-like behavior outside radius `delta`. |
57
- | `bp.losses.log_cosh_loss(predicts, targets)` | Use the smooth log-cosh prediction error. |
58
-
59
- Do not interchange `l2_loss` and `mean_squared_error` without checking scale:
60
- one encodes the legacy half-squared L2 convention while the other exposes mean,
61
- sum, or unreduced squared error semantics.
62
-
63
- ## Use CTC for padded sequence alignment
64
-
65
- | API | Description |
66
- |---|---|
67
- | `bp.losses.ctc_loss(logits, logit_paddings, labels, label_paddings, blank_id=0, log_epsilon=-100000.0)` | Use when input and target sequences require Connectionist Temporal Classification; supply padding masks and the blank token explicitly. |
68
- | `bp.losses.ctc_loss_with_forward_probs(logits, logit_paddings, labels, label_paddings, blank_id=0, log_epsilon=-100000.0)` | Use when the CTC objective and its forward probabilities are both required. |
69
-
70
- Keep `blank_id` outside the semantic label set and make the padding arrays match
71
- their respective time axes. Use the forward-probability variant only when those
72
- intermediates are consumed or inspected.
73
-
74
- ## Use callable loss objects
75
-
76
- Use the class forms when a trainer or model should retain loss configuration as
77
- a reusable callable.
78
-
79
- | API | Description |
80
- |---|---|
81
- | `bp.losses.CrossEntropyLoss(weight=None, ignore_index=-100, reduction='mean', label_smoothing=0.0)` | Store the full cross-entropy configuration for repeated calls. |
82
- | `bp.losses.NLLLoss(reduction='mean')` | Store negative-log-likelihood reduction for repeated calls. |
83
- | `bp.losses.L1Loss(reduction='mean')` | Store L1 reduction for repeated calls. |
84
- | `bp.losses.MAELoss(axis=None, reduction='mean')` | Store mean-absolute-error axis and reduction. |
85
- | `bp.losses.MSELoss(reduction='mean')` | Store mean-squared-error reduction. |
86
-
87
- Use either the functional or object form for one objective; do not apply both
88
- to the same predictions.
89
-
90
- ## Add regularization explicitly
91
-
92
- Regularizers receive predictions, errors, labels, or parameter PyTrees rather
93
- than owning the optimizer update.
94
-
95
- | API | Description |
96
- |---|---|
97
- | `bp.losses.l2_norm(x, axis=None)` | Compute an L2 norm over an array or supported parameter structure. |
98
- | `bp.losses.mean_absolute(outputs, axis=None)` | Compute mean absolute magnitude for a regularization term. |
99
- | `bp.losses.mean_square(predicts, axis=None)` | Compute mean squared magnitude for a regularization term. |
100
- | `bp.losses.log_cosh(errors)` | Compute log-cosh directly from an error array. |
101
- | `bp.losses.smooth_labels(labels, alpha)` | Apply label smoothing to an existing label representation. |
102
-
103
- ```python
104
- data_loss = bp.losses.mean_squared_error(predictions, targets)
105
- weight_penalty = 2e-4 * bp.losses.l2_norm(model.train_vars().unique().dict()) ** 2
106
- loss = data_loss + weight_penalty
107
- ```
108
-
109
- Keep the coefficient visible at the call site. Verify that the selected
110
- parameter collection contains trainable parameters and excludes neuronal State
111
- such as voltage, spikes, and delay buffers.
112
-
113
- ## Source-backed failures
114
-
115
- - Produce a scalar before calling `bm.grad`; use an explicit reduction when a
116
- loss returns per-sample or per-element values.
117
- - Keep the class axis and target encoding consistent. Do not send one-hot labels
118
- to a sparse-index API or integer indices to a same-shaped multilabel API.
119
- - Preserve the documented `multiclass_logistic_loss(label, logits)` argument
120
- order even though most other functions place predictions first.
121
- - Do not use `brainpy.state` metric or Braintools metric APIs in this legacy
122
- reference; their calling and State contracts differ.
123
-
124
- ## Official sources
125
-
126
- - `https://brainpy.readthedocs.io/apis/losses.html`
127
- - Generated function and loss-class pages linked from that API index.