brainx-skill 1.0.6 → 1.0.9

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 (120) hide show
  1. package/README.md +10 -8
  2. package/adapters/gemini.js +7 -0
  3. package/adapters/opencode.js +7 -0
  4. package/adapters/windsurf.js +7 -0
  5. package/installation/lib/installer.js +4 -1
  6. package/manifest.json +6 -1
  7. package/package.json +8 -2
  8. package/skills/braincell/SKILL.md +182 -0
  9. package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
  10. package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +273 -0
  11. package/skills/braincell/references/channel-library.md +85 -0
  12. package/skills/braincell/references/ion-library.md +87 -0
  13. package/skills/braincell/references/mixions-for-adaptation.md +81 -0
  14. package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
  15. package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
  16. package/skills/braincell/references/multicompartment/filter-function-library.md +154 -0
  17. package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
  18. package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
  19. package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
  20. package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +260 -0
  21. package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
  22. package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
  23. package/skills/braincell/references/scripts/channel_ablation.py +61 -0
  24. package/skills/braincell/references/scripts/fi_curve.py +68 -0
  25. package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
  26. package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
  27. package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
  28. package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
  29. package/skills/braincell/references/solver-library-with-effects.md +188 -0
  30. package/skills/brainevent/SKILL.md +268 -0
  31. package/skills/brainevent/references/connectivity-variants.md +312 -0
  32. package/skills/brainevent/references/custom-operators-cpu.md +304 -0
  33. package/skills/brainevent/references/custom-operators-gpu.md +468 -0
  34. package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
  35. package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
  36. package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
  37. package/skills/brainevent/references/sparse-formats.md +182 -0
  38. package/skills/brainevent/references/synaptic-plasticity.md +285 -0
  39. package/skills/brainmass/SKILL.md +290 -0
  40. package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
  41. package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
  42. package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
  43. package/skills/brainmass/references/braintools/cogtask.md +190 -0
  44. package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
  45. package/skills/brainmass/references/braintools/metric.md +157 -0
  46. package/skills/brainmass/references/braintools/optimizer.md +187 -0
  47. package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
  48. package/skills/brainmass/references/braintools/surrogate.md +151 -0
  49. package/skills/brainmass/references/coupling-network-api.md +148 -0
  50. package/skills/brainmass/references/datasets-api.md +72 -0
  51. package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
  52. package/skills/brainmass/references/forward-observation-api.md +131 -0
  53. package/skills/brainmass/references/horn-task-training.md +199 -0
  54. package/skills/brainmass/references/modellibrary.md +104 -0
  55. package/skills/brainmass/references/noiseprocesses.md +121 -0
  56. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
  57. package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
  58. package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
  59. package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
  60. package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
  61. package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
  62. package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
  63. package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
  64. package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
  65. package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
  66. package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
  67. package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
  68. package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
  69. package/skills/brainmass/references/visualization-analysis-api.md +130 -0
  70. package/skills/brainpy-state/SKILL.md +232 -0
  71. package/skills/brainpy-state/references/array-creation.md +158 -0
  72. package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
  73. package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
  74. package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
  75. package/skills/brainpy-state/references/braintools/metric.md +152 -0
  76. package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
  77. package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
  78. package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
  79. package/skills/brainpy-state/references/component-selection.md +273 -0
  80. package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
  81. package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
  82. package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
  83. package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
  84. package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
  85. package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
  86. package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
  87. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
  88. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
  89. package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
  90. package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
  91. package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
  92. package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
  93. package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
  94. package/skills/brainpy-state/references/projection-patterns.md +125 -0
  95. package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
  96. package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
  97. package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
  98. package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
  99. package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
  100. package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
  101. package/skills/brainstate/SKILL.md +1 -1
  102. package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +250 -399
  103. package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +6 -2
  104. package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +16 -2
  105. package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +8 -3
  106. package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +64 -143
  107. package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +13 -1
  108. package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +11 -1
  109. package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +35 -7
  110. package/skills/brainstate/references/collective_model_operations.md +9 -9
  111. package/skills/brainstate/references/extension_mechanisms.md +12 -1
  112. package/skills/brainstate/references/libraries/prebuilt-activation-library.md +106 -97
  113. package/skills/brainstate/references/libraries/prebuilt-layer-library.md +102 -176
  114. package/skills/brainstate/references/model-interop-and-migration.md +11 -1
  115. package/skills/brainstate/references/size-inference-variations.md +11 -0
  116. package/skills/brainstate/references/state-graph-operations.md +13 -15
  117. package/skills/brainstate/references/state_collections_and_utilities.md +12 -1
  118. package/skills/brainx-general-guard/SKILL.md +68 -0
  119. package/skills/brainstate/references/braintools-optimizer-reference.md +0 -133
  120. package/skills/brainstate/references/libraries/solver-library-with-effects.md +0 -85
@@ -1,106 +1,115 @@
1
1
  # Prebuilt activation library
2
2
 
3
- Use this reference to select an exact `brainstate.nn` activation symbol. The routed catalog provides symbol names and descriptions, but not constructor or callable signatures; do not invent argument lists from similarly named APIs in another library. It distinguishes stateful layer modules from pure functions, but leaves basic activation use and `Module` composition to `SKILL.md`.
4
-
5
- Normalization layers are not present on this page. Select `BatchNorm*`, `LayerNorm`, `RMSNorm`, or `GroupNorm` from `prebuilt-layer-library.md`. The functional `standardize` entry below remains here because it is part of the activation catalog and is described as standardizing an array; it is not a normalization-layer API.
6
-
7
- ## Element-wise layers
8
-
9
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/activation.html
10
-
11
- The official page describes these as non-linear activation layers that operate element-wise on input tensors. Its catalog includes rectified linear units and variants, sigmoid functions, hyperbolic tangent, softmax for probability distributions, and specialized activations for specific architectures such as SELU, GELU, SiLU, and Mish.
12
-
13
- | Exact symbol | Official catalog description |
14
- |---|---|
15
- | `Threshold` | Thresholds each element of the input Tensor. |
16
- | `ReLU` | Applies the rectified linear unit function element-wise. |
17
- | `RReLU` | Applies the randomized leaky rectified liner unit function, element-wise. |
18
- | `Hardtanh` | Applies the HardTanh function element-wise. |
19
- | `ReLU6` | Applies the element-wise function. |
20
- | `Sigmoid` | Applies the element-wise function. |
21
- | `Hardsigmoid` | Applies the Hardsigmoid function element-wise. |
22
- | `Tanh` | Applies the Hyperbolic Tangent (Tanh) function element-wise. |
23
- | `SiLU` | Applies the Sigmoid Linear Unit (SiLU) function, element-wise. |
24
- | `Mish` | Applies the Mish function, element-wise. |
25
- | `Hardswish` | Applies the Hardswish function, element-wise. |
26
- | `ELU` | Applies the Exponential Linear Unit (ELU) function, element-wise. |
27
- | `CELU` | Applies the element-wise function. |
28
- | `SELU` | Applied element-wise. |
29
- | `GLU` | Applies the gated linear unit function. |
30
- | `GELU` | Applies the Gaussian Error Linear Units function. |
31
- | `Hardshrink` | Applies the Hard Shrinkage (Hardshrink) function element-wise. |
32
- | `LeakyReLU` | Applies the element-wise function. |
33
- | `LogSigmoid` | Applies the element-wise function. |
34
- | `Softplus` | Applies the Softplus function element-wise. |
35
- | `Softshrink` | Applies the soft shrinkage function elementwise. |
36
- | `PReLU` | Applies the element-wise function. |
37
- | `Softsign` | Applies the element-wise function. |
38
- | `Tanhshrink` | Applies the element-wise function. |
39
- | `Softmin` | Applies the Softmin function to an n-dimensional input Tensor. |
40
- | `Softmax` | Applies the Softmax function to an n-dimensional input Tensor. |
41
- | `Softmax2d` | Applies SoftMax over features to each spatial location. |
42
- | `LogSoftmax` | Applies the `log(Softmax(x))` function to an n-dimensional input Tensor. |
43
- | `Identity` | A placeholder identity operator that is argument-insensitive. |
44
- | `SpikeBitwise` | Bitwise addition for the spiking inputs. |
45
-
46
- Selection cues supplied by the catalog:
47
-
48
- - Use `Softmin`, `Softmax`, or `LogSoftmax` when the requested operation names that distribution transform; use `Softmax2d` when the request specifically calls for SoftMax over features at each spatial location.
49
- - Use `Identity` when an argument-insensitive placeholder identity operator is required.
50
- - Use `SpikeBitwise` only for the page's stated spiking-input bitwise addition role.
51
- - Treat the remaining entries according to their exact named activation. The catalog does not expose parameters here, even for parameterized, thresholded, randomized, gated, or shrinkage variants.
3
+ Use this reference to choose an exact `brainstate.nn` activation symbol and decide
4
+ between a Module and a functional form. Open
5
+ `prebuilt-layer-library.md` for normalization layers; `standardize` remains here
6
+ because the activation API exports it as a pure array operation.
7
+
8
+ ## Selection map
9
+
10
+ | Choice | Use when | Key constraint |
11
+ |---|---|---|
12
+ | Module class, such as `nn.ReLU()` | The activation must be stored in a Module graph, `Sequential`, or descriptor-based composition. | Instantiate the class; parameterized classes keep their configuration in the graph. |
13
+ | Functional form, such as `nn.relu(x)` | The activation is a stateless operation inside `update()` or another function. | Pass the array directly; do not instantiate the function. |
14
+ | `Softmax`, `LogSoftmax`, `Softmin`, or lowercase equivalents | The output must be normalized across a specified dimension. | Set the dimension or axis deliberately; the default may not match the feature dimension. |
15
+ | `standardize`, `one_hot`, or `logsumexp` | The task is array standardization, encoding, or stable log reduction rather than nonlinear activation. | These are utilities, not activation Modules. |
16
+ | `SpikeBitwise` | The input is a spiking representation requiring the catalog's bitwise-addition behavior. | Do not use it as a general numeric activation. |
17
+
18
+ ## Module activations
19
+
20
+ Use a Module class when graph composition or constructor-held configuration
21
+ matters. The exact class names are case-sensitive.
22
+
23
+ | API | Choose it when | Decision-changing control |
24
+ |---|---|---|
25
+ | `Threshold` | Values on one side of a threshold must be replaced. | `Threshold(threshold, value)` |
26
+ | `ReLU` | Use the standard rectified linear unit. | `ReLU(name=None)` |
27
+ | `RReLU` | Use randomized negative slopes. | `RReLU(lower=0.125, upper=1 / 3)` |
28
+ | `Hardtanh` | Clamp with a hard-tanh response. | `Hardtanh(min_val=-1.0, max_val=1.0)` |
29
+ | `ReLU6` | Clamp ReLU output at six. | No selection-specific constructor control is documented. |
30
+ | `Sigmoid` | Map values through the logistic sigmoid. | No selection-specific constructor control is documented. |
31
+ | `Hardsigmoid` | Use the piecewise-linear sigmoid approximation. | No selection-specific constructor control is documented. |
32
+ | `Tanh` | Map values through hyperbolic tangent. | No selection-specific constructor control is documented. |
33
+ | `SiLU` | Use SiLU, also called swish. | No selection-specific constructor control is documented. |
34
+ | `Mish` | Use the Mish activation. | No selection-specific constructor control is documented. |
35
+ | `Hardswish` | Use the piecewise-linear hard-swish variant. | No selection-specific constructor control is documented. |
36
+ | `ELU` | Use exponential linear units. | `ELU(alpha=1.0)` |
37
+ | `CELU` | Use continuously differentiable ELU. | `CELU(alpha=1.0)` |
38
+ | `SELU` | Use scaled ELU in an architecture designed for self-normalization. | Pair with architecture-appropriate initialization and dropout rather than substituting it blindly. |
39
+ | `GLU` | Split and gate the input along a dimension. | `GLU(dim=-1)` requires a compatible size on the split dimension. |
40
+ | `GELU` | Use Gaussian error linear units. | Check the generated page when an approximation variant matters. |
41
+ | `Hardshrink` | Apply hard shrinkage. | Check the generated page for the threshold control. |
42
+ | `LeakyReLU` | Preserve a fixed negative slope. | `LeakyReLU(negative_slope=0.01)` |
43
+ | `LogSigmoid` | Return the log of sigmoid stably. | No selection-specific constructor control is documented. |
44
+ | `Softplus` | Use a smooth positive rectifier. | The current generated constructor is `Softplus(name=None)`; do not assume PyTorch's `beta` or `threshold` arguments. |
45
+ | `Softshrink` | Apply soft shrinkage. | Check the generated page for the threshold control. |
46
+ | `PReLU` | Learn the negative slope. | `PReLU(num_parameters=1, init=0.25, dtype=None)` creates trainable slope parameters. |
47
+ | `Softsign` | Use the soft-sign response. | No selection-specific constructor control is documented. |
48
+ | `Tanhshrink` | Return the tanh-shrink response. | No selection-specific constructor control is documented. |
49
+ | `Softmin` | Normalize with larger probability on smaller inputs. | Set the normalization dimension explicitly. |
50
+ | `Softmax` | Convert logits to normalized probabilities. | `Softmax(dim=None)`; pass the intended feature dimension. |
51
+ | `Softmax2d` | Normalize features independently at each spatial location. | Use only for the documented 2D spatial layout. |
52
+ | `LogSoftmax` | Return normalized log-probabilities. | Set the normalization dimension explicitly. |
53
+ | `Identity` | Keep a configurable graph slot without changing the input. | It is a placeholder, not an activation. |
54
+ | `SpikeBitwise` | Apply bitwise addition to spiking inputs. | Keep it within spiking-data workflows. |
52
55
 
53
56
  ## Functional activations
54
57
 
55
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/activation.html
56
-
57
- The official page describes these as functional, non-module activation functions for flexible composition. They are pure functions that may be used directly in `update()` methods or combined with JAX transformations, and provide activation behavior without state or module overhead.
58
+ Use the lowercase form for stateless composition. Prefer the function whose name
59
+ matches the requested operation; aliases are shown explicitly.
58
60
 
59
- | Exact symbol | Official catalog description |
61
+ | API | Distinguishing behavior |
60
62
  |---|---|
61
- | `tanh` | Hyperbolic tangent activation function. |
62
- | `relu` | Rectified Linear Unit activation function. |
63
- | `squareplus` | Squareplus activation function. |
64
- | `softplus` | Softplus activation function. |
65
- | `soft_sign` | Soft-sign activation function. |
66
- | `sigmoid` | Sigmoid activation function. |
67
- | `silu` | SiLU (Sigmoid Linear Unit) activation function. |
68
- | `swish` | SiLU (Sigmoid Linear Unit) activation function. |
69
- | `log_sigmoid` | Log-sigmoid activation function. |
70
- | `elu` | Exponential Linear Unit activation function. |
71
- | `leaky_relu` | Leaky Rectified Linear Unit activation function. |
72
- | `hard_tanh` | Hard hyperbolic tangent activation function. |
73
- | `celu` | Continuously-differentiable Exponential Linear Unit activation. |
74
- | `selu` | Scaled Exponential Linear Unit activation. |
75
- | `gelu` | Gaussian Error Linear Unit activation function. |
76
- | `glu` | Gated Linear Unit activation function. |
77
- | `logsumexp` | No description is supplied in the routed catalog. |
78
- | `log_softmax` | Log-Softmax function. |
79
- | `softmax` | Softmax activation function. |
80
- | `standardize` | Standardize (normalize) an array. |
81
- | `one_hot` | One-hot encode the given indices. |
82
- | `relu6` | Rectified Linear Unit 6 activation function. |
83
- | `hard_sigmoid` | Hard Sigmoid activation function. |
84
- | `hard_silu` | Hard SiLU (Swish) activation function. |
85
- | `hard_swish` | Hard SiLU (Swish) activation function. |
86
- | `hard_shrink` | Hard shrinkage activation function. |
87
- | `rrelu` | Randomized Leaky Rectified Linear Unit activation function. |
88
- | `mish` | Mish activation function. |
89
- | `soft_shrink` | Soft shrinkage activation function. |
90
- | `prelu` | Parametric Rectified Linear Unit activation function. |
91
- | `tanh_shrink` | Tanh shrink activation function. |
92
- | `softmin` | Softmin activation function. |
93
- | `sparse_plus` | Sparse plus activation function. |
94
- | `sparse_sigmoid` | Sparse sigmoid activation function. |
95
-
96
- Selection cues supplied by the catalog:
97
-
98
- - Choose the lowercase functional form when the operation should remain a pure function inside `update()` or a JAX transformation rather than a layer module.
99
- - `silu` and `swish` share the same catalog description; likewise, `hard_silu` and `hard_swish` share the same description.
100
- - `standardize` is the page's functional array-standardization choice. Route stateful or configurable normalization-layer selection to `prebuilt-layer-library.md`.
101
- - `one_hot` is an encoding utility listed in this catalog, not a nonlinear layer.
102
- - The routed page gives no description or signature for `logsumexp`; use the exact symbol only when that operation is explicitly requested, and consult a version-matched generated API page before supplying arguments.
103
-
104
- ## Source
63
+ | `tanh` | Hyperbolic tangent. |
64
+ | `relu` | Rectified linear unit. |
65
+ | `squareplus` | Smooth squareplus rectifier. |
66
+ | `softplus` | Smooth positive rectifier. |
67
+ | `soft_sign` | Soft-sign response. |
68
+ | `sigmoid` | Logistic sigmoid. |
69
+ | `silu`, `swish` | Equivalent SiLU/swish names. |
70
+ | `log_sigmoid` | Stable log-sigmoid. |
71
+ | `elu`, `celu`, `selu` | ELU-family functions; select by the requested activation contract. |
72
+ | `leaky_relu`, `rrelu`, `prelu` | Fixed, randomized, or supplied negative-slope behavior. |
73
+ | `hard_tanh`, `relu6`, `hard_sigmoid` | Piecewise-linear or clamped responses. |
74
+ | `hard_silu`, `hard_swish` | Equivalent hard-SiLU/hard-swish names. |
75
+ | `gelu`, `mish` | GELU or Mish response. |
76
+ | `glu` | Split-and-gate operation; preserve a compatible split-axis size. |
77
+ | `hard_shrink`, `soft_shrink`, `tanh_shrink` | Shrinkage-family functions. |
78
+ | `softmin`, `softmax`, `log_softmax` | Normalize across `axis`; choose probability, inverse-probability, or log-probability output. |
79
+ | `sparse_plus`, `sparse_sigmoid` | Sparse probability transformations. |
80
+ | `logsumexp` | Stable log of summed exponentials. |
81
+ | `standardize` | Standardize an array, optionally using supplied variance. |
82
+ | `one_hot` | Encode integer indices along a new class axis. |
83
+
84
+ ## Canonical selection workflow
85
+
86
+ Use a Module in a registered layer pipeline and a function for an inline output
87
+ transformation:
88
+
89
+ ```python
90
+ import brainstate
91
+ import brainstate.nn as nn
92
+
93
+ brainstate.random.seed(0)
94
+ feature_block = nn.Sequential(
95
+ nn.Linear(in_size=(8,), out_size=(4,)),
96
+ nn.ReLU(),
97
+ )
98
+
99
+ x = brainstate.random.randn(2, 8)
100
+ logits = feature_block(x)
101
+ probabilities = nn.softmax(logits, axis=-1)
102
+
103
+ assert probabilities.shape == logits.shape
104
+ ```
105
+
106
+ **Invariant:** choose the normalization axis from the tensor layout. A valid
107
+ call on the wrong axis can silently produce the wrong probability semantics.
108
+
109
+ For any parameter not shown above, open the version-matched generated page
110
+ linked from the activation catalog instead of borrowing a signature from JAX,
111
+ PyTorch, or another library.
112
+
113
+ ## Official source
105
114
 
106
115
  - https://brainx.chaobrain.com/brainstate/apis/nn/activation.html
@@ -1,213 +1,139 @@
1
- # Brainstate prebuilt layer library
2
-
3
- Use this reference only to select a prebuilt `brainstate.nn` layer and recover its constructor form. The canonical layer example, `Module` composition, and `.desc()` workflow stay in `SKILL.md`. Route convolution, pooling, padding, and flatten output formulas to `../size-inference-variations.md`; route activation functions to `prebuilt-activation-library.md`; route dropout randomness, reproducibility, and fitting-mode work to `../brainstate/randomness-and-reproducibility.md`.
4
-
5
- The constructor forms below preserve the documented public parameter order and defaults. To keep the catalog readable, these aliases compress only verbose initializer and State-type representations:
6
-
7
- ```text
8
- P = brainstate.ParamState
9
- NP = brainstate.nn._normalizations.NormalizationParamState
10
- MS = brainstate.BatchState
11
- WK = KaimingNormal(scale=2.0, mode='fan_in', in_axis=-2,
12
- out_axis=-1, distribution='truncated_normal', ...)
13
- WX = XavierNormal(scale=1.0, mode='fan_avg', in_axis=-2,
14
- out_axis=-1, distribution='truncated_normal', ...)
15
- WL = LecunNormal(scale=1.0, mode='fan_in', in_axis=-2,
16
- out_axis=-1, distribution='truncated_normal', ...)
17
- WN = Normal(scale=1.0, mean=0.0, ...)
18
- Z = ZeroInit(unit=Unit("1"))
19
- C0 = Constant(value=0.0)
20
- C1 = Constant(value=1.0)
21
- ```
22
-
23
- The `...` inside an initializer alias stands only for its rendered RNG and unit representation, not for omitted layer arguments.
24
-
25
- ## Linear and connectivity layers
1
+ # Prebuilt layer library
26
2
 
27
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/linear.html
3
+ Use this reference to choose a prebuilt `brainstate.nn` layer family and identify
4
+ the constructor controls that change model behavior. Keep ordinary composition
5
+ in `SKILL.md`; open `../size-inference-variations.md` for output-size formulas,
6
+ `prebuilt-activation-library.md` for activations, and
7
+ `../brainstate/randomness-and-reproducibility.md` for stochastic replay.
28
8
 
29
- The official catalog includes standard dense, weight-standardized, signed-absolute-weight, sparse, low-rank-adaptation, all-to-all, and one-to-one forms.
9
+ ## Selection map
30
10
 
31
- | API | Constructor | Select when |
11
+ | Family | Use when | Key constraint |
32
12
  |---|---|---|
33
- | `Linear` | `Linear(in_size, out_size, w_init=WK, b_init=Z, w_mask=None, name=None, param_type=P)` | A standard linear transformation is required. |
34
- | `ScaledWSLinear` | `ScaledWSLinear(in_size, out_size, w_init=WK, b_init=Z, w_mask=None, ws_gain=True, eps=0.0001, name=None, param_type=P)` | The linear weights should use scaled weight standardization. |
35
- | `SignedWLinear` | `SignedWLinear(in_size, out_size, w_init=WK, w_sign=None, name=None, param_type=P)` | The transformation should use signed absolute weights. |
36
- | `SparseLinear` | `SparseLinear(spar_mat, b_init=None, in_size=None, name=None, param_type=P)` | The weight matrix is sparse. Supply the sparse matrix as `spar_mat`. |
37
- | `LoRA` | `LoRA(in_features, lora_rank, out_features, *, base_module=None, kernel_init=WL, param_type=P, in_size=None)` | Low-rank adaptation is needed for parameter-efficient fine-tuning, optionally around `base_module`. |
38
- | `AllToAll` | `AllToAll(in_size, out_size, w_init=WK, b_init=None, include_self=True, name=None, param_type=P)` | An all-to-all connection layer is required; use `include_self` to retain or exclude self-connections. |
39
- | `OneToOne` | `OneToOne(in_size, w_init=WN, b_init=None, name=None, param_type=P)` | A one-to-one connection layer is required. |
40
-
41
- Do not replace `SparseLinear`, `LoRA`, `AllToAll`, or `OneToOne` with a hand-written dense layer when the corresponding connection structure is the requirement.
42
-
43
- ## Convolutional layers
44
-
45
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/conv.html
46
-
47
- Choose the suffix by spatial rank: `1d` for one spatial dimension, `2d` for two, and `3d` for three. The catalog provides the same three ranks for standard convolution, scaled weight-standardized convolution, and transposed convolution.
48
-
49
- ### Standard convolution
50
-
51
- Exact classes: `Conv1d`, `Conv2d`, `Conv3d`.
52
-
53
- ```text
54
- ConvNd(
55
- in_size, out_channels, kernel_size,
56
- stride=1, padding='SAME', lhs_dilation=1, rhs_dilation=1, groups=1,
57
- w_init=WX, b_init=None, w_mask=None, channel_first=False,
58
- name=None, param_type=P,
59
- )
60
- ```
61
-
62
- Use the matching concrete class name in place of `ConvNd`. `channel_first=False` is the documented default; make layout choice explicit when selecting the non-default layout. Size outcomes for `stride`, `padding`, dilation, and groups belong in the size-inference reference.
13
+ | Linear and connectivity | Features must be mixed densely, sparsely, by sign, one-to-one, all-to-all, or through low-rank adaptation. | Preserve the requested connectivity structure instead of replacing it with a dense matrix. |
14
+ | Convolution | Local kernels operate over one, two, or three spatial dimensions. | Match the class suffix and `channel_first` setting to the input layout. |
15
+ | Normalization | Activations or weights must be normalized by batch, layer, RMS, group, or weight statistics. | Choose reduction and feature axes from the actual tensor layout. |
16
+ | Pooling and reshaping | Spatial values must be reduced, restored from max indices, or rearranged. | Local pooling and adaptive pooling solve different output-size requirements. |
17
+ | Padding | A boundary condition must be explicit before another spatial operation. | Reflection, replication, circular, constant, and zero padding have different boundary semantics. |
18
+ | Dropout | Training requires elementwise, channelwise, alpha, or time-fixed stochastic masking. | Fitting mode and RNG state determine whether and how the mask is applied. |
63
19
 
64
- ### Scaled weight-standardized convolution
20
+ The forms below show public arguments that affect selection. Open the generated
21
+ class page from the linked family catalog for version-specific initializer
22
+ objects, State subclasses, dtypes, names, and full defaults.
65
23
 
66
- Exact classes: `ScaledWSConv1d`, `ScaledWSConv2d`, `ScaledWSConv3d`.
67
-
68
- ```text
69
- ScaledWSConvNd(
70
- in_size, out_channels, kernel_size,
71
- stride=1, padding='SAME', lhs_dilation=1, rhs_dilation=1, groups=1,
72
- ws_gain=True, eps=0.0001,
73
- w_init=WX, b_init=None, w_mask=None, channel_first=False,
74
- name=None, param_type=P,
75
- )
76
- ```
24
+ ## Linear and connectivity layers
77
25
 
78
- Select this family when convolution with weight standardization is required. `ws_gain` and `eps` are the family-specific constructor controls.
26
+ | API | Constructor core | Choose it when |
27
+ |---|---|---|
28
+ | `Linear` | `Linear(in_size, out_size, ...)` | Apply a standard dense linear transformation. |
29
+ | `ScaledWSLinear` | `ScaledWSLinear(in_size, out_size, ..., ws_gain=True, eps=1e-4)` | Standardize linear weights during the forward computation. |
30
+ | `SignedWLinear` | `SignedWLinear(in_size, out_size, ..., w_sign=None)` | Enforce a supplied sign pattern over absolute weights. |
31
+ | `SparseLinear` | `SparseLinear(spar_mat, ..., in_size=None)` | Use an existing sparse weight matrix. |
32
+ | `LoRA` | `LoRA(in_features, lora_rank, out_features, *, base_module=None, ...)` | Add a low-rank trainable update, optionally around a base Module. |
33
+ | `AllToAll` | `AllToAll(in_size, out_size, ..., include_self=True)` | Connect every input and output, optionally excluding self-connections. |
34
+ | `OneToOne` | `OneToOne(in_size, ...)` | Give each feature or unit its own scalar connection. |
35
+
36
+ **Invariant:** `SparseLinear`, `LoRA`, `AllToAll`, and `OneToOne` encode model
37
+ structure. Replacing them with `Linear` changes parameterization and often the
38
+ scientific meaning.
79
39
 
80
- ### Transposed convolution
40
+ ## Convolutional layers
81
41
 
82
- Exact classes: `ConvTranspose1d`, `ConvTranspose2d`, `ConvTranspose3d`.
42
+ Choose `1d`, `2d`, or `3d` from the number of spatial axes, excluding batch and
43
+ channel axes.
83
44
 
84
- ```text
85
- ConvTransposeNd(
86
- in_size, out_channels, kernel_size,
87
- stride=1, padding='SAME', rhs_dilation=1, groups=1,
88
- w_init=WX, b_init=None, w_mask=None, channel_first=False,
89
- name=None, param_type=P,
90
- )
91
- ```
45
+ | Exact classes | Constructor family | Choose it when |
46
+ |---|---|---|
47
+ | `Conv1d`, `Conv2d`, `Conv3d` | `ConvNd(in_size, out_channels, kernel_size, stride=1, padding='SAME', lhs_dilation=1, rhs_dilation=1, groups=1, ..., channel_first=False)` | Apply a standard convolution. |
48
+ | `ScaledWSConv1d`, `ScaledWSConv2d`, `ScaledWSConv3d` | `ScaledWSConvNd(..., ws_gain=True, eps=1e-4, channel_first=False)` | Apply convolution with scaled weight standardization. |
49
+ | `ConvTranspose1d`, `ConvTranspose2d`, `ConvTranspose3d` | `ConvTransposeNd(in_size, out_channels, kernel_size, stride=1, padding='SAME', rhs_dilation=1, groups=1, ..., channel_first=False)` | Apply learned transposed-convolution upsampling. |
92
50
 
93
- Select this family for the catalog's transposed-convolution, or deconvolution, upsampling operation. Unlike the standard and scaled-WS forms, its documented constructor has no `lhs_dilation` argument.
51
+ Do not pass `lhs_dilation` to the transposed-convolution family; it is not part
52
+ of its documented constructor. Open `../size-inference-variations.md` before
53
+ predicting shapes affected by stride, padding, dilation, or groups.
94
54
 
95
55
  ## Normalization layers
96
56
 
97
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/normalization.html
98
-
99
- This section inventories normalization APIs only. Activation-function selection remains in `prebuilt-activation-library.md`.
100
-
101
- ### Batch normalization ranks
102
-
103
- Exact classes: `BatchNorm0d`, `BatchNorm1d`, `BatchNorm2d`, `BatchNorm3d`.
104
-
105
- ```text
106
- BatchNormNd(
107
- in_size, feature_axis=-1, *,
108
- track_running_stats=True, epsilon=1e-05, momentum=0.99, affine=True,
109
- bias_initializer=C0, scale_initializer=C1,
110
- axis_name=None, axis_index_groups=None, use_fast_variance=True,
111
- name=None, dtype=None, param_type=NP, mean_type=MS,
112
- )
113
- ```
114
-
115
- Choose `0d`, `1d`, `2d`, or `3d` to match the required batch-normalization rank. Running-statistics and affine behavior are constructor choices through `track_running_stats` and `affine`; do not silently change their documented defaults.
116
-
117
- ### Axis- and group-based normalization
118
-
119
- | API | Constructor | Selection distinction |
57
+ | API | Constructor core | Choose it when |
120
58
  |---|---|---|
121
- | `LayerNorm` | `LayerNorm(in_size, reduction_axes=-1, feature_axes=-1, *, epsilon=1e-06, use_bias=True, use_scale=True, bias_init=Z, scale_init=C1, axis_name=None, axis_index_groups=None, use_fast_variance=True, dtype=None, param_type=NP)` | Layer normalization with explicit reduction and feature axes. |
122
- | `RMSNorm` | `RMSNorm(in_size, *, epsilon=1e-06, dtype=None, use_scale=True, scale_init=C1, reduction_axes=-1, feature_axes=-1, axis_name=None, axis_index_groups=None, use_fast_variance=True, param_type=NP)` | Root Mean Square Layer Normalization; it exposes scale but no bias argument. |
123
- | `GroupNorm` | `GroupNorm(in_size, feature_axis=-1, num_groups=32, group_size=None, *, epsilon=1e-06, dtype=None, use_bias=True, use_scale=True, bias_init=Z, scale_init=C1, reduction_axes=None, axis_name=None, axis_index_groups=None, use_fast_variance=True, param_type=NP)` | Group Normalization; choose the grouping with `num_groups` or `group_size`. |
124
-
125
- The catalog also exposes the functional primitive:
126
-
127
- ```python
128
- brainstate.nn.weight_standardization(w, eps=0.0001, gain=None, out_axis=-1)
129
- ```
59
+ | `BatchNorm0d`, `BatchNorm1d`, `BatchNorm2d`, `BatchNorm3d` | `BatchNormNd(in_size, feature_axis=-1, *, track_running_stats=True, epsilon=1e-5, momentum=0.99, affine=True, ...)` | Normalize with batch statistics and optionally maintain running statistics. |
60
+ | `LayerNorm` | `LayerNorm(in_size, reduction_axes=-1, feature_axes=-1, *, epsilon=1e-6, use_bias=True, use_scale=True, ...)` | Normalize selected axes independently for each example. |
61
+ | `RMSNorm` | `RMSNorm(in_size, *, epsilon=1e-6, use_scale=True, reduction_axes=-1, feature_axes=-1, ...)` | Normalize by root mean square without a bias control. |
62
+ | `GroupNorm` | `GroupNorm(in_size, feature_axis=-1, num_groups=32, group_size=None, *, epsilon=1e-6, ...)` | Partition channels into groups; specify `num_groups` or `group_size` coherently. |
63
+ | `weight_standardization` | `weight_standardization(w, eps=1e-4, gain=None, out_axis=-1)` | Standardize a weight array directly rather than selecting a complete layer. |
130
64
 
131
- Use it when standardizing a weight value directly; prefer the prebuilt `ScaledWSLinear` or `ScaledWSConv*` families when the whole layer already matches the task.
65
+ Batch normalization has separate ranks because accepted layouts differ. Do not
66
+ choose a suffix from the total array rank without accounting for batch and
67
+ feature axes.
132
68
 
133
69
  ## Pooling and reshaping
134
70
 
135
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/pooling.html
71
+ | Exact APIs | Constructor family | Choose it when |
72
+ |---|---|---|
73
+ | `Flatten` | `Flatten(start_axis=0, end_axis=-1, in_size=None)` | Collapse a contiguous range of runtime axes. |
74
+ | `Unflatten` | `Unflatten(axis, sizes, name=None, in_size=None)` | Expand one axis into the supplied sizes. |
75
+ | `AvgPool1d`, `AvgPool2d`, `AvgPool3d` | `AvgPoolNd(kernel_size, stride=1, padding='VALID', channel_axis=-1, ...)` | Reduce local windows by their mean. |
76
+ | `MaxPool1d`, `MaxPool2d`, `MaxPool3d` | `MaxPoolNd(kernel_size, stride=None, padding='VALID', channel_axis=-1, return_indices=False, ...)` | Reduce local windows by their maximum; request indices when unpooling follows. |
77
+ | `LPPool1d`, `LPPool2d`, `LPPool3d` | `LPPoolNd(norm_type, kernel_size, stride=None, padding='VALID', channel_axis=-1, ...)` | Apply local Lp pooling with an explicit norm order. |
78
+ | `MaxUnpool1d`, `MaxUnpool2d`, `MaxUnpool3d` | `MaxUnpoolNd(kernel_size, stride=None, padding=0, channel_axis=-1, ...)` | Place pooled maxima back using compatible max-pool indices. |
79
+ | `AdaptiveAvgPool1d`, `AdaptiveAvgPool2d`, `AdaptiveAvgPool3d` | `AdaptiveAvgPoolNd(target_size, channel_axis=-1, ...)` | Produce a fixed target size with average pooling. |
80
+ | `AdaptiveMaxPool1d`, `AdaptiveMaxPool2d`, `AdaptiveMaxPool3d` | `AdaptiveMaxPoolNd(target_size, channel_axis=-1, ...)` | Produce a fixed target size with max pooling. |
81
+
82
+ **Invariant:** `MaxUnpool*` is only a partial inverse. Preserve indices from a
83
+ compatible `MaxPool*` call and do not expect non-maximal values to be recovered.
136
84
 
137
- The catalog covers shape conversion, local average/max/Lp pooling, max unpooling, and adaptive pooling. It does not own output-size formulas.
85
+ ## Padding layers
138
86
 
139
- ### Shape conversion
87
+ Choose the boundary behavior first, then the `1d`, `2d`, or `3d` suffix.
140
88
 
141
- | API | Constructor | Select when |
89
+ | Exact class families | Constructor family | Boundary behavior |
142
90
  |---|---|---|
143
- | `Flatten` | `Flatten(start_axis=0, end_axis=-1, in_size=None)` | A contiguous range of axes should be flattened. |
144
- | `Unflatten` | `Unflatten(axis, sizes, name=None, in_size=None)` | One axis should be expanded to `sizes`. |
91
+ | `ReflectionPad1d`, `ReflectionPad2d`, `ReflectionPad3d` | `ReflectionPadNd(padding, in_size=None, name=None)` | Mirror values at the boundary. |
92
+ | `ReplicationPad1d`, `ReplicationPad2d`, `ReplicationPad3d` | `ReplicationPadNd(padding, in_size=None, name=None)` | Repeat edge values. |
93
+ | `ZeroPad1d`, `ZeroPad2d`, `ZeroPad3d` | `ZeroPadNd(padding, in_size=None, name=None)` | Insert zeros. |
94
+ | `ConstantPad1d`, `ConstantPad2d`, `ConstantPad3d` | `ConstantPadNd(padding, value=0, in_size=None, name=None)` | Insert an explicit constant. |
95
+ | `CircularPad1d`, `CircularPad2d`, `CircularPad3d` | `CircularPadNd(padding, in_size=None, name=None)` | Wrap values from the opposite boundary. |
145
96
 
146
- ### Local pooling
97
+ ## Dropout layers
147
98
 
148
- | Exact classes | Constructor family | Selection distinction |
99
+ | API | Constructor core | Choose it when |
149
100
  |---|---|---|
150
- | `AvgPool1d`, `AvgPool2d`, `AvgPool3d` | `AvgPoolNd(kernel_size, stride=1, padding='VALID', channel_axis=-1, name=None, in_size=None)` | Average pooling for the matching spatial rank. |
151
- | `MaxPool1d`, `MaxPool2d`, `MaxPool3d` | `MaxPoolNd(kernel_size, stride=None, padding='VALID', channel_axis=-1, return_indices=False, name=None, in_size=None)` | Max pooling; request indices only through `return_indices`. |
152
- | `LPPool1d`, `LPPool2d`, `LPPool3d` | `LPPoolNd(norm_type, kernel_size, stride=None, padding='VALID', channel_axis=-1, name=None, in_size=None)` | Power-average pooling with the required `norm_type`. |
101
+ | `Dropout` | `Dropout(prob=0.5, broadcast_dims=(), name=None)` | Mask individual values, optionally sharing the mask across selected dimensions. |
102
+ | `Dropout1d`, `Dropout2d`, `Dropout3d` | `DropoutNd(prob=0.5, channel_axis=-1, name=None)` | Mask complete feature channels for the matching spatial rank. |
103
+ | `AlphaDropout` | `AlphaDropout(prob=0.5, name=None)` | Preserve self-normalizing-network statistics with elementwise alpha dropout. |
104
+ | `FeatureAlphaDropout` | `FeatureAlphaDropout(prob=0.5, channel_axis=-1, name=None)` | Apply alpha dropout to complete channels. |
105
+ | `DropoutFixed` | `DropoutFixed(in_size, prob=0.5, name=None)` | Reuse a mask along the time axis. |
153
106
 
154
- Keep the default distinction exact: average pooling defaults to `stride=1`; max and Lp pooling default to `stride=None`.
107
+ Open `../brainstate/randomness-and-reproducibility.md` when dropout must use an
108
+ independent stream, replay exactly, map across an ensemble, or survive a
109
+ checkpoint.
155
110
 
156
- ### Max unpooling
111
+ ## Representative composition
157
112
 
158
- Exact classes: `MaxUnpool1d`, `MaxUnpool2d`, `MaxUnpool3d`.
113
+ This example makes layout, spatial rank, normalization axis, and fixed output
114
+ size explicit:
159
115
 
160
- ```text
161
- MaxUnpoolNd(
162
- kernel_size, stride=None, padding=0,
163
- channel_axis=-1, name=None, in_size=None,
116
+ ```python
117
+ import brainstate.nn as nn
118
+
119
+ feature_extractor = nn.Sequential(
120
+ nn.Conv2d(
121
+ in_size=(28, 28, 1),
122
+ out_channels=16,
123
+ kernel_size=3,
124
+ padding="SAME",
125
+ channel_first=False,
126
+ ),
127
+ nn.GroupNorm(in_size=(28, 28, 16), feature_axis=-1, num_groups=4),
128
+ nn.ReLU(),
129
+ nn.AdaptiveAvgPool2d(target_size=(1, 1), channel_axis=-1),
164
130
  )
165
131
  ```
166
132
 
167
- Select the matching rank when the partial inverse of the corresponding `MaxPoolNd` operation is required.
168
-
169
- ### Adaptive pooling
170
-
171
- | Exact classes | Constructor family | Selection distinction |
172
- |---|---|---|
173
- | `AdaptiveAvgPool1d`, `AdaptiveAvgPool2d`, `AdaptiveAvgPool3d` | `AdaptiveAvgPoolNd(target_size, channel_axis=-1, name=None, in_size=None)` | Adaptive average pooling to a fixed target size. |
174
- | `AdaptiveMaxPool1d`, `AdaptiveMaxPool2d`, `AdaptiveMaxPool3d` | `AdaptiveMaxPoolNd(target_size, channel_axis=-1, name=None, in_size=None)` | Adaptive max pooling to a fixed target size. |
175
-
176
- ## Padding layers
177
-
178
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/padding.html
179
-
180
- All five boundary-condition families are available in 1D, 2D, and 3D. Choose the family first, then the suffix matching the spatial rank.
181
-
182
- | Exact classes | Constructor family | Boundary behavior |
183
- |---|---|---|
184
- | `ReflectionPad1d`, `ReflectionPad2d`, `ReflectionPad3d` | `ReflectionPadNd(padding, in_size=None, name=None)` | Reflect the input boundary. |
185
- | `ReplicationPad1d`, `ReplicationPad2d`, `ReplicationPad3d` | `ReplicationPadNd(padding, in_size=None, name=None)` | Replicate the input boundary. |
186
- | `ZeroPad1d`, `ZeroPad2d`, `ZeroPad3d` | `ZeroPadNd(padding, in_size=None, name=None)` | Pad with zeros. |
187
- | `ConstantPad1d`, `ConstantPad2d`, `ConstantPad3d` | `ConstantPadNd(padding, value=0, in_size=None, name=None)` | Pad with `value`; the documented default is zero. |
188
- | `CircularPad1d`, `CircularPad2d`, `CircularPad3d` | `CircularPadNd(padding, in_size=None, name=None)` | Wrap around with circular padding. |
189
-
190
- Do not derive output dimensions here. Open `../size-inference-variations.md` when `padding` interacts with convolution, pooling, stride, dilation, or flattening.
191
-
192
- ## Dropout layers
193
-
194
- Source URL: https://brainx.chaobrain.com/brainstate/apis/nn/dropout.html
195
-
196
- The official catalog distinguishes elementwise dropout, channelwise spatial dropout, alpha-dropout variants, and a fixed mask along the time axis.
197
-
198
- | API | Constructor | Select when |
199
- |---|---|---|
200
- | `Dropout` | `Dropout(prob=0.5, broadcast_dims=(), name=None)` | A subset of inputs should be ignored stochastically each training step; `broadcast_dims` controls mask broadcasting. |
201
- | `Dropout1d` | `Dropout1d(prob=0.5, channel_axis=-1, name=None)` | Entire channels of 1D feature maps should be zeroed. |
202
- | `Dropout2d` | `Dropout2d(prob=0.5, channel_axis=-1, name=None)` | Entire channels of 2D feature maps should be zeroed. |
203
- | `Dropout3d` | `Dropout3d(prob=0.5, channel_axis=-1, name=None)` | Entire channels of 3D feature maps should be zeroed. |
204
- | `AlphaDropout` | `AlphaDropout(prob=0.5, name=None)` | Alpha Dropout is required. |
205
- | `FeatureAlphaDropout` | `FeatureAlphaDropout(prob=0.5, channel_axis=-1, name=None)` | Entire channels should be masked with Alpha Dropout properties. |
206
- | `DropoutFixed` | `DropoutFixed(in_size, prob=0.5, name=None)` | A dropout mask fixed along the time axis is required. |
207
-
208
- After selecting the class, route RNG streams, deterministic replay, mapped randomness, checkpoint behavior, or training/evaluation mode to `../brainstate/randomness-and-reproducibility.md`; those concerns are deliberately not duplicated here.
133
+ Open `skills/brainstate/scripts/modern_cnn.py` for the full convolution,
134
+ normalization, pooling, dropout, and dense workflow.
209
135
 
210
- ## Exact official sources
136
+ ## Official sources
211
137
 
212
138
  - https://brainx.chaobrain.com/brainstate/apis/nn/linear.html
213
139
  - https://brainx.chaobrain.com/brainstate/apis/nn/conv.html
@@ -1,7 +1,17 @@
1
- # Brainstate model interoperation and migration
1
+ # BrainState model interoperation and migration
2
2
 
3
3
  Use this reference after the main BrainState skill when a task must move registered weighted layers between BrainState, Flax NNX, Flax Linen, or Equinox, or translate a PyTorch workflow into BrainState equivalents. It assumes the main skill's `State`, `Module`, parameter-collection, randomness, and state-aware transformation model; this file covers only interoperability and migration deltas.
4
4
 
5
+ ## Selection map
6
+
7
+ | Need | Use | Key constraint |
8
+ |---|---|---|
9
+ | Convert one supported layer or `Sequential` stack | `brainstate.interop.from_*` or `to_*` | Check `supported_layers()` in the installed version and verify numerical output equivalence. |
10
+ | Convert a spatial layer into BrainState | `from_nnx`, `from_linen`, or `from_equinox` with `sample_input` | The sample fixes shape and layout information needed for construction. |
11
+ | Add a conversion for a custom layer | `LayerMapping` and `register_layer_mapping` | Implement and test both conversion directions. |
12
+ | Port a PyTorch workflow | Translate parameters, gradient selection, optimizer ownership, and checkpoint paths separately | This is a semantic migration, not an automatic whole-model conversion. |
13
+ | Convert branching, skip connections, or arbitrary custom forward code | Rebuild and validate manually | The automatic boundary is registered layers and supported `Sequential` structure. |
14
+
5
15
  ## Interop contract and api surface
6
16
 
7
17
  Source: https://brainx.chaobrain.com/brainstate/apis/interop.html
@@ -2,6 +2,17 @@
2
2
 
3
3
  Use this reference to compose size-aware layers with `Sequential` and `.desc()`, or when stride, padding, dimensionality, pooling mode, or flatten axes make a layer's size behavior non-obvious.
4
4
 
5
+ ## Selection map
6
+
7
+ | Need | Use | Key constraint |
8
+ |---|---|---|
9
+ | Infer each next layer from the previous output | Give the first layer `in_size`, then use `.desc()` | Every descriptor must receive enough non-size constructor arguments to instantiate later. |
10
+ | Predict convolution output | Inspect `stride`, `padding`, dilation, rank, and channel layout | Use `stride`, not the obsolete `strides` spelling. |
11
+ | Reduce by local windows | `AvgPool*`, `MaxPool*`, or `LPPool*` | Kernel, stride, padding, and channel axis determine the result. |
12
+ | Produce a fixed spatial target | `AdaptiveAvgPool*` or `AdaptiveMaxPool*` | `target_size` determines the spatial output independently of input size. |
13
+ | Flatten a runtime batch | Set `start_axis` to preserve the batch axis | Runtime axes include batch; Module `in_size` metadata does not. |
14
+ | Flatten feature metadata for composition | Construct `Flatten(in_size=feature_size)` or use `.desc()` | Feature `in_size` excludes the batch dimension. |
15
+
5
16
  ## Compose `ComplexNet` with `Sequential` and `.desc()`
6
17
 
7
18
  Give the first layer an explicit `in_size`, then use `.desc()` wherever `Sequential` should instantiate a layer from the preceding `out_size`. Start the classifier from `self.features.out_size` so flattening and dense construction stay coupled to the feature extractor.