brainx-skill 1.0.15 → 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.
- package/README.md +17 -1
- package/manifest.json +1 -1
- package/mcp-servers/codex/skills.json +1 -1
- 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
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
# Braintools connectivity
|
|
2
|
-
|
|
3
|
-
Use this reference to choose and construct point-neuron or
|
|
4
|
-
multi-compartment connection patterns. It covers which pairs exist, their
|
|
5
|
-
indices, optional weights and delays, spatial structure, topology, and
|
|
6
|
-
compartment targeting. Use `braintools.init.DistanceModulated` only when an
|
|
7
|
-
existing connection's weight should be scaled by distance.
|
|
8
|
-
|
|
9
|
-
## Choose a connectivity family
|
|
10
|
-
|
|
11
|
-
| Family | Use when | Representative choice |
|
|
12
|
-
|---|---|---|
|
|
13
|
-
| Basic point-neuron | Connection probability or deterministic pairing is enough | `Random`, `AllToAll`, or `OneToOne` |
|
|
14
|
-
| Spatial point-neuron | Positions or spatial neighborhoods determine connection probability | `DistanceDependent`, `Gaussian`, `Ring`, or `Grid2d` |
|
|
15
|
-
| Topological | Degree, clustering, modularity, hierarchy, or core/periphery structure matters | `SmallWorld`, `ScaleFree`, `ModularRandom`, or `HierarchicalRandom` |
|
|
16
|
-
| Biological E/I | Presynaptic sign must follow Dale's principle | `ExcitatoryInhibitory` |
|
|
17
|
-
| Kernel based | Receptive-field geometry should follow an image-like kernel | `GaussianKernel`, `GaborKernel`, or `DoGKernel` |
|
|
18
|
-
| Multi-compartment | Synapses must target soma, axon, or dendritic compartments | `CompartmentSpecific` or an anatomical targeting subclass |
|
|
19
|
-
|
|
20
|
-
## Construction and results
|
|
21
|
-
|
|
22
|
-
Every connectivity object is a reusable pattern. Call it with population sizes
|
|
23
|
-
and any required positions or morphology metadata to obtain a
|
|
24
|
-
`ConnectionResult`.
|
|
25
|
-
|
|
26
|
-
| API | Description |
|
|
27
|
-
|---|---|
|
|
28
|
-
| `Connectivity(pre_size=None, post_size=None, seed=None)` | Subclass for a new general pattern. Implement `generate(...)`; use `weight_scale(factor)` or `delay_scale(factor)` to wrap a pattern. |
|
|
29
|
-
| `PointConnectivity` | Subclass for a new single-compartment pattern. |
|
|
30
|
-
| `MultiCompartmentConnectivity` | Subclass for a new morphology-aware pattern. |
|
|
31
|
-
| `ScaledConnectivity` | Returned when weights or delays are scaled. |
|
|
32
|
-
| `CompositeConnectivity` | Use when combining several connectivity patterns. |
|
|
33
|
-
| `ConnectionResult(pre_indices, post_indices, pre_size, post_size, ..., weights=None, delays=None, model_type='point', metadata=None)` | Inspect the generated edge list and optional annotations. `shape` is `(pre_size, post_size)` and `n_connections` is the number of edges. |
|
|
34
|
-
| `ConnectionResult.weight2dense()` / `weight2csr()` | Convert weights to a dense or CSR connectivity matrix. |
|
|
35
|
-
| `ConnectionResult.delay2matrix()` / `delay2csr()` | Convert delays to a dense or CSR connectivity matrix. |
|
|
36
|
-
| `ConnectionResult.get_distances()` | Compute distances for connected pairs when positions are available. |
|
|
37
|
-
|
|
38
|
-
```python
|
|
39
|
-
import brainunit as u
|
|
40
|
-
from braintools.conn import ExcitatoryInhibitory
|
|
41
|
-
|
|
42
|
-
pattern = ExcitatoryInhibitory(
|
|
43
|
-
exc_ratio=0.8,
|
|
44
|
-
exc_prob=0.1,
|
|
45
|
-
inh_prob=0.2,
|
|
46
|
-
exc_weight=1.0 * u.nS,
|
|
47
|
-
inh_weight=-0.8 * u.nS,
|
|
48
|
-
)
|
|
49
|
-
result = pattern(pre_size=1000, post_size=1000)
|
|
50
|
-
|
|
51
|
-
assert result.shape == (1000, 1000)
|
|
52
|
-
assert result.pre_indices.shape == result.post_indices.shape
|
|
53
|
-
assert result.weights.shape[0] == result.n_connections
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**Invariant:** a `ConnectionResult` edge is identified by matching entries in
|
|
57
|
-
`pre_indices` and `post_indices`. Keep any weights and delays aligned with that
|
|
58
|
-
edge order when converting or filtering.
|
|
59
|
-
|
|
60
|
-
## Basic and spatial point-neuron patterns
|
|
61
|
-
|
|
62
|
-
| API | Description |
|
|
63
|
-
|---|---|
|
|
64
|
-
| `Random(prob, allow_self_connections=False, weight=None, delay=None, **kwargs)` | Use for independent fixed-probability edges. Supply initializer objects or values for optional weights and delays. |
|
|
65
|
-
| `FixedProb(...)` | Use only as the alias for `Random`. |
|
|
66
|
-
| `AllToAll(...)` | Connect every allowed presynaptic/postsynaptic pair. |
|
|
67
|
-
| `OneToOne(...)` | Connect neuron `i` to neuron `i`; use only when the population indexing is aligned. |
|
|
68
|
-
| `DistanceDependent(distance_profile, weight=None, delay=None, allow_self_connections=False, **kwargs)` | Use when a `braintools.init.DistanceProfile` should determine connection probability from positions or precomputed distances. |
|
|
69
|
-
| `Gaussian(...)` | Use for Gaussian distance-dependent connection probability. |
|
|
70
|
-
| `Exponential(...)` | Use for exponentially decaying connection probability. |
|
|
71
|
-
| `Ring(...)` | Use for neurons arranged on a circular topology. |
|
|
72
|
-
| `Grid2d(connectivity='von_neumann', weight=None, delay=None, periodic=False, **kwargs)` | Use for immediate four-neighbor (`'von_neumann'`) or eight-neighbor (`'moore'`) connections on matching two-dimensional pre/post grids. Set `periodic=True` only for wraparound boundaries. |
|
|
73
|
-
| `RadialPatches(...)` | Use for several localized spatial connection patches. |
|
|
74
|
-
| `ClusteredRandom(...)` | Use for random connectivity enhanced within spatial clusters. |
|
|
75
|
-
|
|
76
|
-
```python
|
|
77
|
-
import brainunit as u
|
|
78
|
-
import numpy as np
|
|
79
|
-
from braintools.conn import DistanceDependent
|
|
80
|
-
from braintools.init import GaussianProfile, LogNormal
|
|
81
|
-
|
|
82
|
-
positions = np.random.default_rng(0).uniform(0, 1000, (500, 2)) * u.um
|
|
83
|
-
pattern = DistanceDependent(
|
|
84
|
-
GaussianProfile(sigma=100 * u.um, max_distance=300 * u.um),
|
|
85
|
-
weight=LogNormal(mean=1.0 * u.nS, std=0.5 * u.nS),
|
|
86
|
-
)
|
|
87
|
-
result = pattern(500, 500, positions, positions)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
`DistanceDependent` consumes the profile's connection probability and samples
|
|
91
|
-
which pairs exist. In contrast, `braintools.init.DistanceModulated` multiplies
|
|
92
|
-
every supplied base weight by a profile value and never removes an edge.
|
|
93
|
-
|
|
94
|
-
## Export a `ConnectionResult` to BrainEvent CSR
|
|
95
|
-
|
|
96
|
-
Choose topology with BrainTools before choosing BrainEvent storage. Convert the
|
|
97
|
-
result's coordinate edge list to CSR when binary presynaptic events should drive
|
|
98
|
-
event-based communication.
|
|
99
|
-
|
|
100
|
-
| API | Description |
|
|
101
|
-
|---|---|
|
|
102
|
-
| `brainevent.coo2csr(row_ids, col_ids, *, shape)` | Convert `pre_indices` and `post_indices` to row-compressed structure; it returns `(indptr, indices, order)`, where `order` is the required edge-value permutation. |
|
|
103
|
-
| `brainevent.CSR((data, indices, indptr), shape=...)` | Store the reordered weights with presynaptic rows and postsynaptic columns for `BinaryArray @ CSR`. |
|
|
104
|
-
| `brainevent.BinaryArray(spikes) @ connectivity` | Communicate active presynaptic events and return one accumulated value per postsynaptic index. |
|
|
105
|
-
|
|
106
|
-
```python
|
|
107
|
-
import brainevent
|
|
108
|
-
import brainunit as u
|
|
109
|
-
from braintools.conn import Grid2d
|
|
110
|
-
from braintools.init import Constant
|
|
111
|
-
|
|
112
|
-
pattern = Grid2d(
|
|
113
|
-
connectivity="von_neumann",
|
|
114
|
-
weight=Constant(1.0 * u.nS),
|
|
115
|
-
periodic=False,
|
|
116
|
-
)
|
|
117
|
-
result = pattern(pre_size=(10, 10), post_size=(10, 10))
|
|
118
|
-
|
|
119
|
-
indptr, indices, order = brainevent.coo2csr(
|
|
120
|
-
result.pre_indices,
|
|
121
|
-
result.post_indices,
|
|
122
|
-
shape=result.shape,
|
|
123
|
-
)
|
|
124
|
-
connectivity = brainevent.CSR(
|
|
125
|
-
(result.weights[order], indices, indptr),
|
|
126
|
-
shape=result.shape,
|
|
127
|
-
)
|
|
128
|
-
postsynaptic_input = brainevent.BinaryArray(
|
|
129
|
-
u.math.zeros(result.shape[0], dtype=bool)
|
|
130
|
-
) @ connectivity
|
|
131
|
-
|
|
132
|
-
assert postsynaptic_input.shape == (result.shape[1],)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Keep `result.weights[order]`: `coo2csr()` sorts edges by row and returns the
|
|
136
|
-
matching value permutation separately. If the topology has no generated
|
|
137
|
-
weights, supply an intentional scalar or edge-aligned weight array before
|
|
138
|
-
constructing `CSR`.
|
|
139
|
-
|
|
140
|
-
Open `skills/package-skills/brainevent/references/sparse-formats.md` when choosing among CSR,
|
|
141
|
-
CSC, dense, generated, or fixed-degree event representations after topology is
|
|
142
|
-
defined.
|
|
143
|
-
|
|
144
|
-
## Topological and biological patterns
|
|
145
|
-
|
|
146
|
-
| API | Description |
|
|
147
|
-
|---|---|
|
|
148
|
-
| `SmallWorld(...)` | Use for Watts-Strogatz small-world structure. |
|
|
149
|
-
| `ScaleFree(...)` | Use for Barabasi-Albert preferential attachment. |
|
|
150
|
-
| `Regular(...)` | Use when each neuron should have the same degree. |
|
|
151
|
-
| `ModularRandom(...)` | Use for random within-module and between-module probabilities. |
|
|
152
|
-
| `ModularGeneral(...)` | Use when intra- and inter-module structure each need their own `Connectivity` object. |
|
|
153
|
-
| `HierarchicalRandom(...)` | Use for multilevel modules with asymmetric feedforward and feedback connectivity. |
|
|
154
|
-
| `CorePeripheryRandom(...)` | Use for a dense core and sparse periphery. |
|
|
155
|
-
| `ExcitatoryInhibitory(exc_ratio=0.8, exc_prob=0.1, inh_prob=0.2, exc_weight=None, inh_weight=None, exc_delay=None, inh_delay=None, **kwargs)` | Use for separate excitatory and inhibitory presynaptic populations whose outgoing signs follow Dale's principle. |
|
|
156
|
-
|
|
157
|
-
## Kernel-based patterns
|
|
158
|
-
|
|
159
|
-
Use kernel patterns when source and target neurons occupy image-like spatial
|
|
160
|
-
grids and a local receptive-field operator defines edges.
|
|
161
|
-
|
|
162
|
-
| API | Description |
|
|
163
|
-
|---|---|
|
|
164
|
-
| `Conv2dKernel(...)` | Use a general convolutional kernel. |
|
|
165
|
-
| `GaussianKernel(...)` | Use a Gaussian receptive field. |
|
|
166
|
-
| `GaborKernel(...)` | Use an orientation-selective Gabor field. |
|
|
167
|
-
| `DoGKernel(...)` | Use a difference-of-Gaussians center-surround field. |
|
|
168
|
-
| `MexicanHat(...)` | Use a Laplacian-of-Gaussian field. |
|
|
169
|
-
| `SobelKernel(...)` | Use a Sobel orientation/edge kernel. |
|
|
170
|
-
| `LaplacianKernel(...)` | Use a Laplacian edge kernel. |
|
|
171
|
-
| `CustomKernel(...)` | Supply a user-defined kernel function. |
|
|
172
|
-
|
|
173
|
-
## Multi-compartment patterns
|
|
174
|
-
|
|
175
|
-
Use `SOMA`, `BASAL_DENDRITE`, `APICAL_DENDRITE`, and `AXON` as the documented
|
|
176
|
-
compartment identifiers. Choose the narrowest pattern that expresses the
|
|
177
|
-
anatomical constraint.
|
|
178
|
-
|
|
179
|
-
| Family | API | Description |
|
|
180
|
-
|---|---|---|
|
|
181
|
-
| General | `CompartmentSpecific(...)` | Define source and target compartment rules directly. |
|
|
182
|
-
| General | `AllToAllCompartments(...)` | Connect all allowed compartment pairs. |
|
|
183
|
-
| General | `CustomCompartment(...)` | Supply a custom compartment-selection function. |
|
|
184
|
-
| Anatomical | `SomaToDendrite(...)` | Target dendrites from somatic sources. |
|
|
185
|
-
| Anatomical | `AxonToSoma(...)` | Target soma from axons. |
|
|
186
|
-
| Anatomical | `DendriteToSoma(...)` | Target soma from dendrites. |
|
|
187
|
-
| Anatomical | `AxonToDendrite(target_dendrites=None, **kwargs)` | Target selected dendritic compartments from axons. |
|
|
188
|
-
| Anatomical | `DendriteToDendrite(...)` | Connect dendritic compartments. |
|
|
189
|
-
| Morphology | `ProximalTargeting(...)` | Prefer proximal dendritic compartments. |
|
|
190
|
-
| Morphology | `DistalTargeting(...)` | Prefer distal dendritic compartments. |
|
|
191
|
-
| Morphology | `BranchSpecific(...)` | Restrict targets to specified branches. |
|
|
192
|
-
| Morphology | `MorphologyDistance(...)` | Use morphology-aware distances. |
|
|
193
|
-
| Dendritic | `DendriticTree(...)` | Configure separate basal/apical probabilities. |
|
|
194
|
-
| Dendritic | `BasalDendriteTargeting(...)` | Restrict targets to basal dendrites. |
|
|
195
|
-
| Dendritic | `ApicalDendriteTargeting(...)` | Restrict targets to apical dendrites. |
|
|
196
|
-
| Dendritic | `DendriticIntegration(...)` | Express dendritic integration patterns. |
|
|
197
|
-
| Axonal | `AxonalProjection(...)` | Build topographic axonal projections. |
|
|
198
|
-
| Axonal | `AxonalBranching(...)` | Build branching axonal patterns. |
|
|
199
|
-
| Axonal | `AxonalArborization(...)` | Build axonal arborization patterns. |
|
|
200
|
-
| Axonal | `TopographicProjection(...)` | Preserve source/target topography. |
|
|
201
|
-
| Synaptic | `SynapticPlacement(...)` | Apply synapse-placement rules. |
|
|
202
|
-
| Synaptic | `SynapticClustering(...)` | Cluster synapses on target morphology. |
|
|
203
|
-
|
|
204
|
-
## Official source
|
|
205
|
-
|
|
206
|
-
- `https://brainx.chaobrain.com/braintools/apis/conn.html`
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# Braintools data preprocessing
|
|
2
|
-
|
|
3
|
-
Use this reference to convert continuous values, event streams, or temporal
|
|
4
|
-
features into spike representations and to combine binary spike tensors. Use
|
|
5
|
-
`braintools.cogtask` for phase-structured behavioral trials and
|
|
6
|
-
`braintools.input` for injected-current waveforms.
|
|
7
|
-
|
|
8
|
-
## Choose an encoder
|
|
9
|
-
|
|
10
|
-
Choose the representation from the information the downstream model must
|
|
11
|
-
preserve.
|
|
12
|
-
|
|
13
|
-
| Encoder family | Use when | Important result |
|
|
14
|
-
|---|---|---|
|
|
15
|
-
| Latency | Magnitude should control time to first spike | Larger normalized values spike earlier. |
|
|
16
|
-
| Rate or Poisson | Magnitude should control spike frequency | Returns a time-major spike train whose empirical rate represents the input. |
|
|
17
|
-
| Population | A scalar should activate overlapping receptive fields | Expands each scalar across a neuron population. |
|
|
18
|
-
| Bernoulli | Each time bin should be sampled independently | Converts normalized values into per-bin spike probabilities. |
|
|
19
|
-
| Delta | Only meaningful temporal changes should emit spikes | Detects threshold-crossing differences between successive samples. |
|
|
20
|
-
| Step current | A spiking neuron should receive an analog current level | Returns current values rather than a binary spike code. |
|
|
21
|
-
| Spike count | The window must contain an exact input-dependent count | Places a bounded number of spikes randomly or regularly. |
|
|
22
|
-
| Temporal | A discrete value should select a precise timing pattern | Maps values to synchronized temporal templates. |
|
|
23
|
-
| Rank order | Relative feature ordering matters more than absolute scale | Emits higher-ranked features before lower-ranked features. |
|
|
24
|
-
|
|
25
|
-
## Spike encoders
|
|
26
|
-
|
|
27
|
-
All encoder objects are reusable callables. Pass the input as the first argument
|
|
28
|
-
and the number of encoded timesteps as `n_time=`.
|
|
29
|
-
|
|
30
|
-
| API | Description |
|
|
31
|
-
|---|---|
|
|
32
|
-
| `LatencyEncoder(min_val=None, max_val=None, method='log', threshold=0.01, clip=False, tau=1 * u.ms, normalize=False, first_spk_time=0 * u.ms, epsilon=1e-7)` | Use for time-to-first-spike coding. Normalize inputs when they are not already in `[0, 1]`; larger values produce earlier spikes. |
|
|
33
|
-
| `RateEncoder(gain=100.0, method='linear', min_rate=0.0, max_rate=None, normalize=False, min_val=None, max_val=None)` | Use when firing rate should vary with input intensity. Select the mapping with `method` and constrain rates deliberately. |
|
|
34
|
-
| `PoissonEncoder(time_window=1000.0, normalize=False, max_rate=100.0)` | Use when an input rate should generate Poisson-distributed spikes. Increase the observation window before judging whether empirical counts match the requested rate. |
|
|
35
|
-
| `PopulationEncoder(n_neurons, min_val=0.0, max_val=1.0, sigma=None, max_rate=100.0)` | Use to encode each scalar with overlapping population receptive fields. Set the represented range and population width explicitly. |
|
|
36
|
-
| `BernoulliEncoder(scale=1.0, normalize=True, min_val=None, max_val=None)` | Use for independent Bernoulli sampling at every time step. Ensure the resulting probabilities remain valid after scaling. |
|
|
37
|
-
| `DeltaEncoder(threshold=0.1, positive_only=False, absolute=False, normalize=True)` | Use for change detection in a temporal signal. Configure sign handling so negative changes are either retained, suppressed, or folded by absolute value. |
|
|
38
|
-
| `StepCurrentEncoder(current_scale=10.0, offset=0.0, normalize=True, min_val=None, max_val=None)` | Use to turn features into constant injected-current levels for integrate-and-fire neurons. The result is an analog current code, not a spike tensor. |
|
|
39
|
-
| `SpikeCountEncoder(max_spikes=10, distribution='random', normalize=True)` | Use when input magnitude should determine an exact bounded spike count. Choose random or regular placement with `distribution`. |
|
|
40
|
-
| `TemporalEncoder(n_patterns, pattern_length=10, jitter=0.1)` | Use when values select reusable temporal spike patterns. Set `jitter` according to the timing variability the model should tolerate. |
|
|
41
|
-
| `RankOrderEncoder(use_values=True, normalize=True, invert=False)` | Use when feature rank determines spike order. Use `invert=True` only when low-valued features must spike first. |
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
import jax.numpy as jnp
|
|
45
|
-
from braintools import LatencyEncoder
|
|
46
|
-
|
|
47
|
-
values = jnp.array([0.02, 0.5, 1.0])
|
|
48
|
-
encoder = LatencyEncoder(method="linear", normalize=True)
|
|
49
|
-
spikes = encoder(values, n_time=5)
|
|
50
|
-
|
|
51
|
-
assert spikes.shape == (5, 3)
|
|
52
|
-
assert jnp.argmax(spikes[:, 2]) < jnp.argmax(spikes[:, 1])
|
|
53
|
-
assert jnp.argmax(spikes[:, 1]) < jnp.argmax(spikes[:, 0])
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**Invariant:** treat the leading axis as encoded time. Validate normalization,
|
|
57
|
-
time-window length, and stochastic variability before comparing encoders.
|
|
58
|
-
|
|
59
|
-
## Spike operations
|
|
60
|
-
|
|
61
|
-
Use these element-wise operations only on boolean or binary-compatible spike
|
|
62
|
-
tensors with broadcast-compatible shapes.
|
|
63
|
-
|
|
64
|
-
| API | Description |
|
|
65
|
-
|---|---|
|
|
66
|
-
| `spike_bitwise_or(x, y)` | Return binary OR, implemented as `x + y - x * y`. |
|
|
67
|
-
| `spike_bitwise_and(x, y)` | Return binary AND, implemented as element-wise multiplication. |
|
|
68
|
-
| `spike_bitwise_iand(x, y)` | Return inverse AND, documented as `(NOT x) AND y`. |
|
|
69
|
-
| `spike_bitwise_not(x)` | Invert a binary spike tensor. |
|
|
70
|
-
| `spike_bitwise_xor(x, y)` | Return XOR between two spike tensors. |
|
|
71
|
-
| `spike_bitwise_ixor(x, y)` | Apply the documented inverse-XOR operation. |
|
|
72
|
-
| `spike_bitwise(x, y, op)` | Dispatch by `op` over `'or'`, `'and'`, `'iand'`, `'xor'`, and `'ixor'`. |
|
|
73
|
-
|
|
74
|
-
Do not use these helpers as fuzzy arithmetic on rates or arbitrary continuous
|
|
75
|
-
arrays; their formulas assume binary values.
|
|
76
|
-
|
|
77
|
-
## Official source
|
|
78
|
-
|
|
79
|
-
- `https://brainx.chaobrain.com/braintools/apis/braintools.html`
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
# Braintools input currents
|
|
2
|
-
|
|
3
|
-
Use this reference to generate unit-aware stimulation currents, waveforms,
|
|
4
|
-
pulses, and stochastic processes. Prefer the composable class API when a
|
|
5
|
-
protocol combines, transforms, repeats, or sequences several signals; use the
|
|
6
|
-
functional API for one direct array.
|
|
7
|
-
|
|
8
|
-
## Choose an interface
|
|
9
|
-
|
|
10
|
-
| Interface | Use when | Result |
|
|
11
|
-
|---|---|---|
|
|
12
|
-
| Composable classes | The protocol needs algebra, clipping, smoothing, time shifts, repetition, overlays, or concatenation | Returns an `Input` object; call it to generate the array. |
|
|
13
|
-
| Functional helpers | One signal can be generated in a single call | Returns the generated array immediately. |
|
|
14
|
-
|
|
15
|
-
Names ending in `Input` or `_input` are deprecated aliases. Use the class and
|
|
16
|
-
function names documented below.
|
|
17
|
-
|
|
18
|
-
## Time-step and composition model
|
|
19
|
-
|
|
20
|
-
An `Input` stores a duration and reads its time step from
|
|
21
|
-
`brainstate.environ`. Calling it generates a cached array; pass
|
|
22
|
-
`recompute=True` when the stochastic or environmental inputs must be evaluated
|
|
23
|
-
again.
|
|
24
|
-
|
|
25
|
-
| API | Description |
|
|
26
|
-
|---|---|
|
|
27
|
-
| `Input(duration)` | Base class for composable currents. It exposes `duration`, `dt`, `n_steps`, and `shape`. |
|
|
28
|
-
| `input_obj(recompute=False)` | Generate and return the current array. |
|
|
29
|
-
| `input_obj.scale(factor)` | Multiply all values by a factor. |
|
|
30
|
-
| `input_obj.shift(time_shift)` | Delay or advance the signal in time. |
|
|
31
|
-
| `input_obj.clip(min_val, max_val)` | Bound the signal values. |
|
|
32
|
-
| `input_obj.smooth(tau)` | Apply exponential smoothing. |
|
|
33
|
-
| `input_obj.repeat(n_times)` | Repeat the pattern. |
|
|
34
|
-
| `input_obj.apply(func)` | Apply a custom transformation to the generated values. |
|
|
35
|
-
| `a + b`, `a - b`, `a * b`, `a / b`, `-a` | Combine compatible signals pointwise. |
|
|
36
|
-
| `a & b` | Concatenate signals sequentially in time. |
|
|
37
|
-
| `a \| b` | Overlay signals by taking their pointwise maximum. |
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
import brainstate
|
|
41
|
-
import brainunit as u
|
|
42
|
-
from braintools.input import Constant, Ramp, Sinusoidal
|
|
43
|
-
|
|
44
|
-
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
45
|
-
baseline = Constant([(0.2 * u.nA, 500 * u.ms)])
|
|
46
|
-
ramp = Ramp(0 * u.nA, 1 * u.nA, 500 * u.ms)
|
|
47
|
-
oscillation = Sinusoidal(
|
|
48
|
-
amplitude=0.5 * u.nA,
|
|
49
|
-
frequency=10 * u.Hz,
|
|
50
|
-
duration=500 * u.ms,
|
|
51
|
-
)
|
|
52
|
-
protocol = (baseline + ramp + 0.5 * oscillation).clip(
|
|
53
|
-
0 * u.nA,
|
|
54
|
-
2 * u.nA,
|
|
55
|
-
)
|
|
56
|
-
current = protocol()
|
|
57
|
-
assert current.shape[0] == protocol.n_steps
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
**Invariant:** set or scope `brainstate.environ.dt` before constructing and
|
|
61
|
-
generating the protocol. A different `dt` changes the number of samples.
|
|
62
|
-
|
|
63
|
-
## Feed a protocol into a BrainPy-State rollout
|
|
64
|
-
|
|
65
|
-
A generated protocol is time-major data: construct it under the rollout `dt`,
|
|
66
|
-
then give it to `for_loop` so one current sample reaches each model step.
|
|
67
|
-
|
|
68
|
-
| API | Description |
|
|
69
|
-
|---|---|
|
|
70
|
-
| `Constant([(value, duration), ...])` | Use for a baseline-pulse-baseline protocol; calling it under the active `dt` returns one unit-aware sample per step. |
|
|
71
|
-
| `brainstate.transform.for_loop(step, times, current)` | Slice `times` and `current` together along their leading axes and stack the step outputs. |
|
|
72
|
-
|
|
73
|
-
```python
|
|
74
|
-
import brainpy
|
|
75
|
-
import brainstate
|
|
76
|
-
import braintools
|
|
77
|
-
import brainunit as u
|
|
78
|
-
from braintools.input import Constant
|
|
79
|
-
|
|
80
|
-
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
81
|
-
neuron = brainpy.state.LIFRef(
|
|
82
|
-
3,
|
|
83
|
-
R=100.0 * u.Mohm,
|
|
84
|
-
tau=20.0 * u.ms,
|
|
85
|
-
V_rest=-65.0 * u.mV,
|
|
86
|
-
V_th=-50.0 * u.mV,
|
|
87
|
-
V_reset=-60.0 * u.mV,
|
|
88
|
-
tau_ref=2.0 * u.ms,
|
|
89
|
-
V_initializer=braintools.init.Constant(-65.0 * u.mV),
|
|
90
|
-
)
|
|
91
|
-
brainstate.nn.init_all_states(neuron)
|
|
92
|
-
protocol = Constant([
|
|
93
|
-
(0.0 * u.nA, 15.0 * u.ms),
|
|
94
|
-
(0.65 * u.nA, 4.0 * u.ms),
|
|
95
|
-
(0.0 * u.nA, 81.0 * u.ms),
|
|
96
|
-
])
|
|
97
|
-
spark = protocol()
|
|
98
|
-
times = u.math.arange(
|
|
99
|
-
0.0 * u.ms,
|
|
100
|
-
protocol.duration,
|
|
101
|
-
brainstate.environ.get_dt(),
|
|
102
|
-
)
|
|
103
|
-
edge_mask = u.math.asarray([True, False, False])
|
|
104
|
-
|
|
105
|
-
def step(t, spark_current):
|
|
106
|
-
with brainstate.environ.context(t=t):
|
|
107
|
-
return neuron(0.13 * u.nA + edge_mask * spark_current)
|
|
108
|
-
|
|
109
|
-
spikes = brainstate.transform.for_loop(step, times, spark)
|
|
110
|
-
|
|
111
|
-
assert spikes.shape == (1000, 3)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Do not reconstruct the same sections with comparisons against `t` inside
|
|
115
|
-
`step`. For a mapped parameter sweep that shares this protocol, keep the
|
|
116
|
-
per-step current sample unmapped (`in_axes=None`) while mapping the independent
|
|
117
|
-
condition parameters and dynamical State. Open
|
|
118
|
-
`skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for
|
|
119
|
-
the mapped-State contract.
|
|
120
|
-
|
|
121
|
-
## Basic currents
|
|
122
|
-
|
|
123
|
-
| Composable API | Functional API | Use |
|
|
124
|
-
|---|---|---|
|
|
125
|
-
| `Section(values, durations)` | `section(values, durations, return_length=False)` | Build consecutive constant sections from parallel value and duration sequences. |
|
|
126
|
-
| `Constant(I_and_duration)` | `constant(I_and_duration)` | Build piecewise-constant sections from `(value, duration)` pairs. |
|
|
127
|
-
| `Step(amplitudes, step_times, duration=None)` | `step(amplitudes, step_times, duration=None)` | Change among discrete levels at specified times. |
|
|
128
|
-
| `Ramp(c_start, c_end, duration, t_start=None, t_end=None)` | `ramp(c_start, c_end, duration, t_start=None, t_end=None)` | Interpolate linearly, optionally only within a subinterval. |
|
|
129
|
-
|
|
130
|
-
`Constant` takes a sequence of pairs:
|
|
131
|
-
|
|
132
|
-
```python
|
|
133
|
-
from braintools.input import Constant
|
|
134
|
-
|
|
135
|
-
protocol = Constant([
|
|
136
|
-
(0.0 * u.nA, 100 * u.ms),
|
|
137
|
-
(1.0 * u.nA, 200 * u.ms),
|
|
138
|
-
(0.0 * u.nA, 100 * u.ms),
|
|
139
|
-
])
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Use `Section(values=[...], durations=[...])` when separate arrays are more
|
|
143
|
-
convenient.
|
|
144
|
-
|
|
145
|
-
## Pulse generators
|
|
146
|
-
|
|
147
|
-
| Composable API | Functional API | Use |
|
|
148
|
-
|---|---|---|
|
|
149
|
-
| `Spike(sp_times, duration, sp_lens=..., sp_sizes=...)` | `spike(sp_times, sp_lens, sp_sizes, duration)` | Place short current spikes at explicit times. |
|
|
150
|
-
| `GaussianPulse(amplitude, center, sigma, duration)` | `gaussian_pulse(amplitude, center, sigma, duration, ...)` | Generate a Gaussian-shaped pulse. |
|
|
151
|
-
| `ExponentialDecay(amplitude, tau, duration, ...)` | `exponential_decay(amplitude, tau, duration, ...)` | Generate a one-sided exponential decay. |
|
|
152
|
-
| `DoubleExponential(amplitude, tau_rise, tau_decay, ...)` | `double_exponential(amplitude, tau_rise, tau_decay, ...)` | Generate a rise-and-decay synaptic-current shape. |
|
|
153
|
-
| `Burst(...)` | `burst(...)` | Generate repeated pulses within one or more bursts. |
|
|
154
|
-
|
|
155
|
-
## Waveforms
|
|
156
|
-
|
|
157
|
-
| Composable API | Functional API | Use |
|
|
158
|
-
|---|---|---|
|
|
159
|
-
| `Sinusoidal(amplitude, frequency, duration, ...)` | `sinusoidal(amplitude, frequency, duration, ...)` | Generate a fixed-frequency sine wave. |
|
|
160
|
-
| `Square(amplitude, frequency, duration, ...)` | `square(amplitude, frequency, duration, ...)` | Generate a square wave; configure its duty cycle deliberately. |
|
|
161
|
-
| `Triangular(amplitude, frequency, duration, ...)` | `triangular(amplitude, frequency, duration, ...)` | Generate a triangular periodic wave. |
|
|
162
|
-
| `Sawtooth(amplitude, frequency, duration, ...)` | `sawtooth(amplitude, frequency, duration, ...)` | Generate a sawtooth periodic wave. |
|
|
163
|
-
| `Chirp(amplitude, f_start, f_end, duration, ...)` | `chirp(amplitude, f_start, f_end, duration, ...)` | Sweep frequency over time. |
|
|
164
|
-
| `NoisySinusoidal(amplitude, frequency, ..., noise_amplitude=...)` | `noisy_sinusoidal(amplitude, frequency, ..., noise_amplitude=...)` | Add stochastic noise to a sinusoid. |
|
|
165
|
-
|
|
166
|
-
## Stochastic processes
|
|
167
|
-
|
|
168
|
-
| Composable API | Functional API | Use |
|
|
169
|
-
|---|---|---|
|
|
170
|
-
| `WienerProcess(duration, n=1, t_start=None, t_end=None, sigma=1.0, seed=None)` | `wiener_process(duration, sigma=1.0, n=1, ...)` | Model Brownian fluctuations with independent Gaussian increments. |
|
|
171
|
-
| `OUProcess(mean, sigma, tau, duration, n=1, t_start=None, t_end=None, seed=None)` | `ou_process(mean, sigma, tau, duration, n=1, ...)` | Model mean-reverting fluctuations around `mean`. |
|
|
172
|
-
| `Poisson(rate, duration, n=1, t_start=None, t_end=None, amplitude=1.0, seed=None)` | `poisson(rate, duration, amplitude=1.0, n=1, ...)` | Generate independent Poisson spike-current trains. |
|
|
173
|
-
|
|
174
|
-
Use `seed=` for reproducibility and `n=` for multiple independent processes.
|
|
175
|
-
For Poisson input, ensure `rate * dt` is a valid per-bin spike probability.
|
|
176
|
-
Call with `recompute=True` only when a new stochastic realization is intended.
|
|
177
|
-
|
|
178
|
-
## Composition wrappers
|
|
179
|
-
|
|
180
|
-
These classes are normally created through operators or methods rather than
|
|
181
|
-
instantiated directly.
|
|
182
|
-
|
|
183
|
-
| API | Description |
|
|
184
|
-
|---|---|
|
|
185
|
-
| `Composite(input1, input2, operator)` | Pointwise combination of two inputs. |
|
|
186
|
-
| `ConstantValue(value, duration)` | Promote a scalar to a duration-matched input. |
|
|
187
|
-
| `Sequential(*inputs)` | Time concatenation corresponding to `&`. |
|
|
188
|
-
| `TimeShifted(input_obj, time_shift)` | Result of `.shift()`. |
|
|
189
|
-
| `Clipped(input_obj, min_val=None, max_val=None)` | Result of `.clip()`. |
|
|
190
|
-
| `Smoothed(input_obj, tau)` | Result of `.smooth()`. |
|
|
191
|
-
| `Repeated(input_obj, n_times)` | Result of `.repeat()`. |
|
|
192
|
-
| `Transformed(input_obj, func)` | Result of `.apply()`. |
|
|
193
|
-
|
|
194
|
-
Pointwise operands must have compatible duration, shape, and units. Use `&`
|
|
195
|
-
when durations differ and should occur one after another.
|
|
196
|
-
|
|
197
|
-
## Official source
|
|
198
|
-
|
|
199
|
-
- `https://brainx.chaobrain.com/braintools/apis/input.html`
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# Braintools metrics
|
|
2
|
-
|
|
3
|
-
Use this reference to select supervised losses and neuroscience metrics for
|
|
4
|
-
classification, regression, spike trains, local field potentials, correlation,
|
|
5
|
-
connectivity, and pairwise comparison. Verify input orientation, units, and
|
|
6
|
-
reduction before treating any returned array as a scalar objective.
|
|
7
|
-
|
|
8
|
-
## Choose a metric family
|
|
9
|
-
|
|
10
|
-
| Task | Use | Important constraint |
|
|
11
|
-
|---|---|---|
|
|
12
|
-
| Independent binary or multilabel classification | Sigmoid binary cross entropy or focal loss | Logits and labels must have broadcast-compatible class structure. |
|
|
13
|
-
| Mutually exclusive classes | Softmax cross entropy | Choose one-hot/probability labels or the integer-label variant explicitly. |
|
|
14
|
-
| Continuous fitting | Squared, absolute, Huber, log-cosh, or cosine losses | Set `reduction` rather than assuming a scalar result. |
|
|
15
|
-
| Spike timing | Victor-Purpura or van Rossum distance | Inputs are spike-time trains, not dense spike matrices. |
|
|
16
|
-
| Population spiking | Firing-rate and synchrony metrics | Dense spike matrices are time-major unless the API says otherwise. |
|
|
17
|
-
| LFP spectrum or coupling | PSD, coherence, PAC, CSD, entropy, or phase coherence | Pass the sample interval as `dt`, not sampling frequency as `fs`. |
|
|
18
|
-
| Functional connectivity | Correlation and connectivity functions | Time series use `(num_time, num_signals)`. |
|
|
19
|
-
|
|
20
|
-
## Classification losses
|
|
21
|
-
|
|
22
|
-
| API | Description |
|
|
23
|
-
|---|---|
|
|
24
|
-
| `sigmoid_binary_cross_entropy(logits, labels)` | Use for independent binary classes; returns element-wise sigmoid cross entropy. |
|
|
25
|
-
| `softmax_cross_entropy(logits, labels)` | Use for mutually exclusive classes represented by one-hot or probability labels. |
|
|
26
|
-
| `softmax_cross_entropy_with_integer_labels(logits, labels)` | Use the more direct integer-index form for mutually exclusive classes. Validate every label yourself. |
|
|
27
|
-
| `hinge_loss(...)` | Use for binary margin classification. |
|
|
28
|
-
| `perceptron_loss(...)` | Use for the binary perceptron objective. |
|
|
29
|
-
| `multiclass_hinge_loss(...)` | Use for a multiclass margin objective. |
|
|
30
|
-
| `multiclass_perceptron_loss(...)` | Use for a multiclass perceptron objective. |
|
|
31
|
-
| `poly_loss_cross_entropy(...)` | Use when the specified method requires PolyLoss cross entropy. |
|
|
32
|
-
| `kl_divergence(...)` | Compare probability distributions. |
|
|
33
|
-
| `kl_divergence_with_log_targets(...)` | Use when predictions and targets are already in log space. |
|
|
34
|
-
| `convex_kl_divergence(...)` | Use when the convex KL variant is required. |
|
|
35
|
-
| `ctc_loss(...)` | Use for sequence alignment without frame-level labels. |
|
|
36
|
-
| `ctc_loss_with_forward_probs(...)` | Use when the CTC forward probabilities are also needed. |
|
|
37
|
-
| `sigmoid_focal_loss(...)` | Use for class imbalance among independent binary targets. |
|
|
38
|
-
| `nll_loss(...)` | Use with log-probability classification outputs. |
|
|
39
|
-
|
|
40
|
-
```python
|
|
41
|
-
import jax.numpy as jnp
|
|
42
|
-
from braintools.metric import (
|
|
43
|
-
softmax_cross_entropy_with_integer_labels,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
logits = jnp.array([
|
|
47
|
-
[2.0, 1.0, 0.1],
|
|
48
|
-
[0.5, 2.5, 0.3],
|
|
49
|
-
])
|
|
50
|
-
labels = jnp.array([0, 1])
|
|
51
|
-
|
|
52
|
-
per_example = softmax_cross_entropy_with_integer_labels(logits, labels)
|
|
53
|
-
loss = jnp.mean(per_example)
|
|
54
|
-
assert loss.ndim == 0
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Critical exception:** JAX gather silently clamps out-of-range integer labels
|
|
58
|
-
in `softmax_cross_entropy_with_integer_labels`. Validate
|
|
59
|
-
`0 <= labels < logits.shape[-1]`; the function does not raise for invalid
|
|
60
|
-
labels.
|
|
61
|
-
|
|
62
|
-
## Regression and pairwise metrics
|
|
63
|
-
|
|
64
|
-
| API | Description |
|
|
65
|
-
|---|---|
|
|
66
|
-
| `squared_error(predictions, targets=None, axis=None, reduction='none')` | Use for element-wise squared error; choose `mean` or another supported reduction explicitly when a scalar is required. |
|
|
67
|
-
| `absolute_error(...)` | Use for element-wise absolute error. |
|
|
68
|
-
| `l1_loss(...)` | Use for mean absolute-error behavior according to its axis/reduction options. |
|
|
69
|
-
| `l2_loss(...)` | Use for squared L2 loss. |
|
|
70
|
-
| `l2_norm(...)` | Return the L2 norm of prediction error. |
|
|
71
|
-
| `safe_norm(...)` | Use when a differentiable lower bound must prevent an unstable zero norm. |
|
|
72
|
-
| `huber_loss(predictions, targets=None, delta=1.0, axis=None, reduction='none')` | Use for quadratic small residuals and linear large residuals; tune `delta` in target units. |
|
|
73
|
-
| `log_cosh(...)` | Use for a smooth robust regression loss. |
|
|
74
|
-
| `cosine_similarity(...)` | Compare vector direction. |
|
|
75
|
-
| `cosine_distance(...)` | Return the corresponding cosine distance. |
|
|
76
|
-
| `pairwise_cosine_similarity(X, Y, ...)` | Return all pairwise cosine similarities between sample sets. |
|
|
77
|
-
| `pairwise_cosine_distance(X, Y, ...)` | Return all pairwise cosine distances between sample sets. |
|
|
78
|
-
|
|
79
|
-
Do not conflate element-wise loss with final optimization reduction. Preserve
|
|
80
|
-
batch and time axes until the scientific loss definition determines how to
|
|
81
|
-
reduce them.
|
|
82
|
-
|
|
83
|
-
## Correlation and functional connectivity
|
|
84
|
-
|
|
85
|
-
| API | Description |
|
|
86
|
-
|---|---|
|
|
87
|
-
| `cross_correlation(spikes, bin, dt)` | Calculate a cross-correlation synchrony index from a time-major spike matrix. |
|
|
88
|
-
| `voltage_fluctuation(voltages)` | Estimate synchrony from population voltage variance. |
|
|
89
|
-
| `matrix_correlation(a, b)` | Correlate upper-triangular entries of two square matrices. |
|
|
90
|
-
| `weighted_correlation(x, y, weights)` | Compute weighted Pearson correlation for two one-dimensional series. |
|
|
91
|
-
| `functional_connectivity(activities)` | Return the pairwise Pearson correlation matrix for `(num_time, num_signals)` data; NaNs are replaced with zero. |
|
|
92
|
-
| `functional_connectivity_dynamics(activities, window_size, step_size)` | Compare sliding-window connectivity matrices to produce functional-connectivity dynamics. |
|
|
93
|
-
|
|
94
|
-
## Spike-train metrics
|
|
95
|
-
|
|
96
|
-
| API | Description |
|
|
97
|
-
|---|---|
|
|
98
|
-
| `raster_plot(spikes, times)` | Extract neuron indices and spike times from a dense spike matrix; this is a metric/data helper, not the visualization API. |
|
|
99
|
-
| `firing_rate(spikes, width, dt=None)` | Average across neurons and smooth population rate with a rectangular window of physical width. |
|
|
100
|
-
| `victor_purpura_distance(spike_times_1, spike_times_2, cost_factor=1.0)` | Measure edit cost from insertions, deletions, and temporal shifts. |
|
|
101
|
-
| `van_rossum_distance(spike_times_1, spike_times_2, tau=...)` | Compare exponentially filtered spike trains. |
|
|
102
|
-
| `spike_train_synchrony(spikes, window_size, dt=None)` | Compute SPIKE-style synchronization on a population matrix. |
|
|
103
|
-
| `burst_synchrony_index(spikes, dt=None, ...)` | Measure co-occurring burst events. |
|
|
104
|
-
| `phase_locking_value(spikes, reference_freq, dt=None, ...)` | Measure spike phase locking to a reference oscillation. |
|
|
105
|
-
| `spike_time_tiling_coefficient(spikes, dt=None, tau=...)` | Compute STTC within a temporal tolerance. |
|
|
106
|
-
| `correlation_index(spikes, window_size, dt=None)` | Compute a windowed spike-train correlation index. |
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
import brainunit as u
|
|
110
|
-
from braintools.metric import firing_rate, spike_train_synchrony
|
|
111
|
-
|
|
112
|
-
# Shape: (num_time, num_neurons)
|
|
113
|
-
rate = firing_rate(spikes, width=10 * u.ms, dt=1 * u.ms)
|
|
114
|
-
synchrony = spike_train_synchrony(
|
|
115
|
-
spikes,
|
|
116
|
-
window_size=5 * u.ms,
|
|
117
|
-
dt=1 * u.ms,
|
|
118
|
-
)
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Keep dense spike matrices and lists of spike times distinct. Distance metrics
|
|
122
|
-
consume event times; population rate and synchrony metrics consume matrices.
|
|
123
|
-
|
|
124
|
-
## Local field potential analysis
|
|
125
|
-
|
|
126
|
-
| API | Description |
|
|
127
|
-
|---|---|
|
|
128
|
-
| `unitary_LFP(times, spikes, neuron_type, seed=None, ...)` | Construct unitary LFP contributions from spikes; use the documented `'exc'` or `'inh'` neuron type. |
|
|
129
|
-
| `power_spectral_density(lfp, dt, nperseg=None, noverlap=None, freq_range=None)` | Return one-sided Welch frequencies and PSD. |
|
|
130
|
-
| `coherence_analysis(signal1, signal2, dt, ...)` | Return frequency-resolved magnitude-squared coherence. |
|
|
131
|
-
| `phase_amplitude_coupling(lfp, dt, phase_freq_range, amplitude_freq_range, ...)` | Return Tort modulation index plus phase-bin details. |
|
|
132
|
-
| `theta_gamma_coupling(lfp, dt, ...)` | Return theta-gamma coupling using standard bands. |
|
|
133
|
-
| `current_source_density(lfp, electrode_spacing, axis=0, ...)` | Estimate laminar CSD along the electrode axis. |
|
|
134
|
-
| `spectral_entropy(lfp, dt, ...)` | Return normalized spectral entropy. |
|
|
135
|
-
| `lfp_phase_coherence(lfp, dt, freq_band, ...)` | Compute pairwise phase coherence across channels. |
|
|
136
|
-
|
|
137
|
-
`power_spectral_density(..., freq_range=...)` uses boolean-mask indexing and
|
|
138
|
-
therefore has a data-dependent output length; that path is not JIT-compatible.
|
|
139
|
-
Compute the full spectrum inside JIT and filter outside when compilation is
|
|
140
|
-
required.
|
|
141
|
-
|
|
142
|
-
## Structured, ranking, and smoothing losses
|
|
143
|
-
|
|
144
|
-
| API | Description |
|
|
145
|
-
|---|---|
|
|
146
|
-
| `make_fenchel_young_loss(max_fun)` | Build a Fenchel-Young loss. `max_fun` must map one score vector to a scalar because it is vectorized with signature `(n)->()`. |
|
|
147
|
-
| `ranking_softmax_loss(scores, labels, ...)` | Use for list-wise learning-to-rank objectives. |
|
|
148
|
-
| `smooth_labels(labels, alpha=...)` | Apply label smoothing to one-hot targets. |
|
|
149
|
-
|
|
150
|
-
## Official source
|
|
151
|
-
|
|
152
|
-
- `https://brainx.chaobrain.com/braintools/apis/metric.html`
|