brainstate 0.1.0.post20250413__py2.py3-none-any.whl → 0.1.0.post20250422__py2.py3-none-any.whl

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 (91) hide show
  1. brainstate/_compatible_import.py +73 -0
  2. brainstate/_state.py +5 -4
  3. brainstate/_state_test.py +2 -1
  4. brainstate/augment/_autograd_test.py +3 -2
  5. brainstate/augment/_eval_shape.py +2 -1
  6. brainstate/augment/_mapping.py +0 -1
  7. brainstate/augment/_mapping_test.py +1 -0
  8. brainstate/compile/_ad_checkpoint.py +2 -1
  9. brainstate/compile/_conditions.py +4 -2
  10. brainstate/compile/_conditions_test.py +2 -1
  11. brainstate/compile/_error_if.py +2 -1
  12. brainstate/compile/_error_if_test.py +2 -1
  13. brainstate/compile/_jit.py +3 -2
  14. brainstate/compile/_jit_test.py +2 -1
  15. brainstate/compile/_loop_collect_return.py +2 -2
  16. brainstate/compile/_loop_collect_return_test.py +2 -1
  17. brainstate/compile/_loop_no_collection.py +1 -1
  18. brainstate/compile/_make_jaxpr.py +10 -13
  19. brainstate/compile/_make_jaxpr_test.py +3 -6
  20. brainstate/compile/_progress_bar.py +2 -1
  21. brainstate/compile/_unvmap.py +1 -5
  22. brainstate/environ.py +4 -4
  23. brainstate/environ_test.py +2 -1
  24. brainstate/functional/_activations.py +2 -1
  25. brainstate/functional/_activations_test.py +1 -1
  26. brainstate/functional/_normalization.py +2 -1
  27. brainstate/functional/_others.py +2 -1
  28. brainstate/graph/_graph_operation.py +3 -2
  29. brainstate/graph/_graph_operation_test.py +4 -3
  30. brainstate/init/_base.py +2 -1
  31. brainstate/init/_generic.py +2 -1
  32. brainstate/nn/__init__.py +4 -0
  33. brainstate/nn/_collective_ops.py +1 -0
  34. brainstate/nn/_collective_ops_test.py +0 -4
  35. brainstate/nn/_common.py +0 -1
  36. brainstate/nn/_dyn_impl/__init__.py +0 -4
  37. brainstate/nn/_dyn_impl/_dynamics_neuron.py +431 -13
  38. brainstate/nn/_dyn_impl/_dynamics_neuron_test.py +2 -1
  39. brainstate/nn/_dyn_impl/_dynamics_synapse.py +405 -103
  40. brainstate/nn/_dyn_impl/_dynamics_synapse_test.py +2 -1
  41. brainstate/nn/_dyn_impl/_inputs.py +236 -29
  42. brainstate/nn/_dyn_impl/_rate_rnns.py +238 -82
  43. brainstate/nn/_dyn_impl/_rate_rnns_test.py +2 -1
  44. brainstate/nn/_dyn_impl/_readout.py +91 -8
  45. brainstate/nn/_dyn_impl/_readout_test.py +2 -1
  46. brainstate/nn/_dynamics/_dynamics_base.py +676 -96
  47. brainstate/nn/_dynamics/_dynamics_base_test.py +2 -1
  48. brainstate/nn/_dynamics/_projection_base.py +29 -30
  49. brainstate/nn/_dynamics/_state_delay.py +3 -3
  50. brainstate/nn/_dynamics/_synouts_test.py +2 -1
  51. brainstate/nn/_elementwise/_dropout.py +3 -2
  52. brainstate/nn/_elementwise/_dropout_test.py +2 -1
  53. brainstate/nn/_elementwise/_elementwise.py +2 -1
  54. brainstate/nn/{_dyn_impl/_projection_alignpost.py → _event/__init__.py} +8 -7
  55. brainstate/nn/_event/_fixedprob_mv.py +169 -0
  56. brainstate/nn/_event/_fixedprob_mv_test.py +115 -0
  57. brainstate/nn/_event/_linear_mv.py +85 -0
  58. brainstate/nn/_event/_linear_mv_test.py +121 -0
  59. brainstate/nn/_exp_euler.py +2 -1
  60. brainstate/nn/_exp_euler_test.py +2 -1
  61. brainstate/nn/_interaction/_conv.py +2 -1
  62. brainstate/nn/_interaction/_linear.py +2 -1
  63. brainstate/nn/_interaction/_linear_test.py +2 -1
  64. brainstate/nn/_interaction/_normalizations.py +2 -1
  65. brainstate/nn/_interaction/_poolings.py +4 -3
  66. brainstate/nn/_module_test.py +2 -1
  67. brainstate/nn/metrics.py +4 -3
  68. brainstate/optim/_lr_scheduler.py +2 -1
  69. brainstate/optim/_lr_scheduler_test.py +2 -1
  70. brainstate/optim/_optax_optimizer_test.py +2 -1
  71. brainstate/optim/_sgd_optimizer.py +3 -2
  72. brainstate/random/_rand_funs.py +2 -1
  73. brainstate/random/_rand_funs_test.py +3 -2
  74. brainstate/random/_rand_seed.py +3 -2
  75. brainstate/random/_rand_seed_test.py +2 -1
  76. brainstate/random/_rand_state.py +4 -3
  77. brainstate/surrogate.py +1 -5
  78. brainstate/typing.py +4 -4
  79. brainstate/util/_caller.py +2 -1
  80. brainstate/util/_others.py +4 -4
  81. brainstate/util/_pretty_pytree.py +1 -1
  82. brainstate/util/_pretty_pytree_test.py +2 -1
  83. brainstate/util/_pretty_table.py +43 -43
  84. brainstate/util/_struct.py +2 -1
  85. brainstate/util/filter.py +0 -1
  86. {brainstate-0.1.0.post20250413.dist-info → brainstate-0.1.0.post20250422.dist-info}/METADATA +3 -3
  87. brainstate-0.1.0.post20250422.dist-info/RECORD +133 -0
  88. brainstate-0.1.0.post20250413.dist-info/RECORD +0 -128
  89. {brainstate-0.1.0.post20250413.dist-info → brainstate-0.1.0.post20250422.dist-info}/LICENSE +0 -0
  90. {brainstate-0.1.0.post20250413.dist-info → brainstate-0.1.0.post20250422.dist-info}/WHEEL +0 -0
  91. {brainstate-0.1.0.post20250413.dist-info → brainstate-0.1.0.post20250422.dist-info}/top_level.txt +0 -0
@@ -17,9 +17,10 @@
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ from typing import Callable, Optional
21
+
20
22
  import brainunit as u
21
23
  import jax
22
- from typing import Callable, Optional
23
24
 
24
25
  from brainstate import init, surrogate, environ
25
26
  from brainstate._state import HiddenState, ShortTermState
@@ -34,10 +35,33 @@ __all__ = [
34
35
 
35
36
  class Neuron(Dynamics):
36
37
  """
37
- Base class for neuronal dynamics.
38
-
39
- All neuron models are differentiable since they use surrogate gradient functions to
40
- generate the spiking state.
38
+ Base class for all spiking neuron models.
39
+
40
+ This abstract class serves as the foundation for implementing various spiking neuron
41
+ models. It extends the Dynamics class and provides common functionality for spike
42
+ generation and membrane potential dynamics.
43
+
44
+ All neuron models should inherit from this class and implement the required methods,
45
+ particularly the `get_spike()` method which defines the spike generation mechanism.
46
+
47
+ Parameters
48
+ ----------
49
+ in_size : Size
50
+ Size of the input to the neuron.
51
+ spk_fun : Callable, default=surrogate.InvSquareGrad()
52
+ Surrogate gradient function for the non-differentiable spike generation.
53
+ spk_reset : str, default='soft'
54
+ Reset mechanism after spike generation:
55
+ - 'soft': subtract threshold from membrane potential
56
+ - 'hard': use stop_gradient for reset
57
+ name : str, optional
58
+ Name of the neuron layer.
59
+
60
+ Methods
61
+ -------
62
+ get_spike(*args, **kwargs)
63
+ Abstract method that generates spikes based on neuron state variables.
64
+ Must be implemented by subclasses.
41
65
  """
42
66
  __module__ = 'brainstate.nn'
43
67
 
@@ -57,8 +81,95 @@ class Neuron(Dynamics):
57
81
 
58
82
 
59
83
  class IF(Neuron):
60
- """
61
- Integrate-and-fire neuron model.
84
+ r"""Integrate-and-Fire (IF) neuron model.
85
+
86
+ This class implements the classic Integrate-and-Fire neuron model, one of the simplest
87
+ spiking neuron models. It accumulates input current until the membrane potential reaches
88
+ a threshold, at which point it fires a spike and resets the potential.
89
+
90
+ The model is characterized by the following differential equation:
91
+
92
+ $$
93
+ \tau \frac{dV}{dt} = -V + R \cdot I(t)
94
+ $$
95
+
96
+ Spike condition:
97
+ If $V \geq V_{th}$: emit spike and reset $V = V - V_{th}$ (soft reset) or $V = 0$ (hard reset)
98
+
99
+ Parameters
100
+ ----------
101
+ in_size : Size
102
+ Size of the input to the neuron.
103
+ R : ArrayLike, default=1. * u.ohm
104
+ Membrane resistance.
105
+ tau : ArrayLike, default=5. * u.ms
106
+ Membrane time constant.
107
+ V_th : ArrayLike, default=1. * u.mV
108
+ Firing threshold voltage (should be positive).
109
+ V_initializer : Callable, default=init.Constant(0. * u.mV)
110
+ Initializer for the membrane potential state.
111
+ spk_fun : Callable, default=surrogate.ReluGrad()
112
+ Surrogate gradient function for the non-differentiable spike generation.
113
+ spk_reset : str, default='soft'
114
+ Reset mechanism after spike generation:
115
+ - 'soft': subtract threshold V = V - V_th
116
+ - 'hard': strict reset using stop_gradient
117
+ name : str, optional
118
+ Name of the neuron layer.
119
+
120
+ Attributes
121
+ ----------
122
+ V : HiddenState
123
+ Membrane potential.
124
+
125
+ Methods
126
+ -------
127
+ init_state(batch_size=None, **kwargs)
128
+ Initialize the neuron state variables.
129
+ reset_state(batch_size=None, **kwargs)
130
+ Reset the neuron state variables.
131
+ get_spike(V=None)
132
+ Generate spikes based on the membrane potential.
133
+ update(x=0. * u.mA)
134
+ Update the neuron state for one time step and return spikes.
135
+
136
+ Examples
137
+ --------
138
+ >>> import brainstate as bs
139
+ >>> import brainunit as u
140
+ >>>
141
+ >>> # Create an IF neuron layer with 10 neurons
142
+ >>> if_neuron = bs.nn.IF(10, tau=8*u.ms, V_th=1.2*u.mV)
143
+ >>>
144
+ >>> # Initialize the state
145
+ >>> if_neuron.init_state(batch_size=1)
146
+ >>>
147
+ >>> # Apply an input current and update the neuron state
148
+ >>> spikes = if_neuron.update(x=2.0*u.mA)
149
+ >>>
150
+ >>> # Create a network with IF neurons
151
+ >>> network = bs.nn.Sequential([
152
+ ... bs.nn.IF(100, tau=5.0*u.ms),
153
+ ... bs.nn.Linear(100, 10)
154
+ ... ])
155
+
156
+ Notes
157
+ -----
158
+ - Unlike the LIF model, the IF model has no leak towards a resting potential.
159
+ - The membrane potential decays exponentially with time constant tau in the absence of input.
160
+ - The time-dependent dynamics are integrated using an exponential Euler method.
161
+ - The IF model is perfect integrator in the sense that it accumulates input indefinitely
162
+ until reaching threshold, without any leak current.
163
+
164
+ References
165
+ ----------
166
+ .. [1] Lapicque, L. (1907). Recherches quantitatives sur l'excitation électrique
167
+ des nerfs traitée comme une polarisation. Journal de Physiologie et de
168
+ Pathologie Générale, 9, 620-635.
169
+ .. [2] Abbott, L. F. (1999). Lapicque's introduction of the integrate-and-fire
170
+ model neuron (1907). Brain Research Bulletin, 50(5-6), 303-304.
171
+ .. [3] Burkitt, A. N. (2006). A review of the integrate-and-fire neuron model:
172
+ I. Homogeneous synaptic input. Biological cybernetics, 95(1), 1-19.
62
173
  """
63
174
 
64
175
  __module__ = 'brainstate.nn'
@@ -108,8 +219,92 @@ class IF(Neuron):
108
219
 
109
220
 
110
221
  class LIF(Neuron):
111
- """
112
- Leaky integrate-and-fire neuron model.
222
+ r"""Leaky Integrate-and-Fire (LIF) neuron model.
223
+
224
+ This class implements the Leaky Integrate-and-Fire neuron model, which extends the basic
225
+ Integrate-and-Fire model by adding a leak term. The leak causes the membrane potential
226
+ to decay towards a resting value in the absence of input, making the model more
227
+ biologically plausible.
228
+
229
+ The model is characterized by the following differential equation:
230
+
231
+ $$
232
+ \tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I(t)
233
+ $$
234
+
235
+ Spike condition:
236
+ If $V \geq V_{th}$: emit spike and reset $V = V_{reset}$
237
+
238
+ Parameters
239
+ ----------
240
+ in_size : Size
241
+ Size of the input to the neuron.
242
+ R : ArrayLike, default=1. * u.ohm
243
+ Membrane resistance.
244
+ tau : ArrayLike, default=5. * u.ms
245
+ Membrane time constant.
246
+ V_th : ArrayLike, default=1. * u.mV
247
+ Firing threshold voltage.
248
+ V_reset : ArrayLike, default=0. * u.mV
249
+ Reset voltage after spike.
250
+ V_rest : ArrayLike, default=0. * u.mV
251
+ Resting membrane potential.
252
+ V_initializer : Callable, default=init.Constant(0. * u.mV)
253
+ Initializer for the membrane potential state.
254
+ spk_fun : Callable, default=surrogate.ReluGrad()
255
+ Surrogate gradient function for the non-differentiable spike generation.
256
+ spk_reset : str, default='soft'
257
+ Reset mechanism after spike generation:
258
+ - 'soft': subtract threshold V = V - V_th
259
+ - 'hard': strict reset using stop_gradient
260
+ name : str, optional
261
+ Name of the neuron layer.
262
+
263
+ Attributes
264
+ ----------
265
+ V : HiddenState
266
+ Membrane potential.
267
+
268
+ Methods
269
+ -------
270
+ init_state(batch_size=None, **kwargs)
271
+ Initialize the neuron state variables.
272
+ reset_state(batch_size=None, **kwargs)
273
+ Reset the neuron state variables.
274
+ get_spike(V=None)
275
+ Generate spikes based on the membrane potential.
276
+ update(x=0. * u.mA)
277
+ Update the neuron state for one time step and return spikes.
278
+
279
+ Examples
280
+ --------
281
+ >>> import brainstate
282
+ >>> import brainunit as u
283
+ >>>
284
+ >>> # Create a LIF neuron layer with 10 neurons
285
+ >>> lif = brainstate.nn.LIF(10, tau=10*u.ms, V_th=0.8*u.mV)
286
+ >>>
287
+ >>> # Initialize the state
288
+ >>> lif.init_state(batch_size=1)
289
+ >>>
290
+ >>> # Apply an input current and update the neuron state
291
+ >>> spikes = lif.update(x=1.5*u.mA)
292
+
293
+ Notes
294
+ -----
295
+ - The leak term causes the membrane potential to decay exponentially towards V_rest
296
+ with time constant tau when no input is present.
297
+ - The time-dependent dynamics are integrated using an exponential Euler method.
298
+ - Spike generation is non-differentiable, so surrogate gradients are used for
299
+ backpropagation during training.
300
+
301
+ References
302
+ ----------
303
+ .. [1] Gerstner, W., Kistler, W. M., Naud, R., & Paninski, L. (2014).
304
+ Neuronal dynamics: From single neurons to networks and models of cognition.
305
+ Cambridge University Press.
306
+ .. [2] Burkitt, A. N. (2006). A review of the integrate-and-fire neuron model:
307
+ I. Homogeneous synaptic input. Biological cybernetics, 95(1), 1-19.
113
308
  """
114
309
  __module__ = 'brainstate.nn'
115
310
 
@@ -161,8 +356,116 @@ class LIF(Neuron):
161
356
 
162
357
 
163
358
  class LIFRef(Neuron):
164
- """
165
- Leaky integrate-and-fire neuron model with refractory period.
359
+ r"""Leaky Integrate-and-Fire neuron model with refractory period.
360
+
361
+ This class implements a Leaky Integrate-and-Fire neuron model that includes a
362
+ refractory period after spiking, during which the neuron cannot fire regardless
363
+ of input. This better captures the behavior of biological neurons that exhibit
364
+ a recovery period after action potential generation.
365
+
366
+ The model is characterized by the following equations:
367
+
368
+ When not in refractory period:
369
+ $$
370
+ \tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I(t)
371
+ $$
372
+
373
+ During refractory period:
374
+ $$
375
+ V = V_{reset}
376
+ $$
377
+
378
+ Spike condition:
379
+ If $V \geq V_{th}$: emit spike, set $V = V_{reset}$, and enter refractory period for $\tau_{ref}$
380
+
381
+ Parameters
382
+ ----------
383
+ in_size : Size
384
+ Size of the input to the neuron.
385
+ R : ArrayLike, default=1. * u.ohm
386
+ Membrane resistance.
387
+ tau : ArrayLike, default=5. * u.ms
388
+ Membrane time constant.
389
+ tau_ref : ArrayLike, default=5. * u.ms
390
+ Refractory period duration.
391
+ V_th : ArrayLike, default=1. * u.mV
392
+ Firing threshold voltage.
393
+ V_reset : ArrayLike, default=0. * u.mV
394
+ Reset voltage after spike.
395
+ V_rest : ArrayLike, default=0. * u.mV
396
+ Resting membrane potential.
397
+ V_initializer : Callable, default=init.Constant(0. * u.mV)
398
+ Initializer for the membrane potential state.
399
+ spk_fun : Callable, default=surrogate.ReluGrad()
400
+ Surrogate gradient function for the non-differentiable spike generation.
401
+ spk_reset : str, default='soft'
402
+ Reset mechanism after spike generation:
403
+ - 'soft': subtract threshold V = V - V_th
404
+ - 'hard': strict reset using stop_gradient
405
+ name : str, optional
406
+ Name of the neuron layer.
407
+
408
+ Attributes
409
+ ----------
410
+ V : HiddenState
411
+ Membrane potential.
412
+ last_spike_time : ShortTermState
413
+ Time of the last spike, used to implement refractory period.
414
+
415
+ Methods
416
+ -------
417
+ init_state(batch_size=None, **kwargs)
418
+ Initialize the neuron state variables.
419
+ reset_state(batch_size=None, **kwargs)
420
+ Reset the neuron state variables.
421
+ get_spike(V=None)
422
+ Generate spikes based on the membrane potential.
423
+ update(x=0. * u.mA)
424
+ Update the neuron state for one time step and return spikes.
425
+
426
+ Examples
427
+ --------
428
+ >>> import brainstate as bs
429
+ >>> import brainunit as u
430
+ >>>
431
+ >>> # Create a LIFRef neuron layer with 10 neurons
432
+ >>> lifref = bs.nn.LIFRef(10,
433
+ ... tau=10*u.ms,
434
+ ... tau_ref=5*u.ms,
435
+ ... V_th=0.8*u.mV)
436
+ >>>
437
+ >>> # Initialize the state
438
+ >>> lifref.init_state(batch_size=1)
439
+ >>>
440
+ >>> # Apply an input current and update the neuron state
441
+ >>> spikes = lifref.update(x=1.5*u.mA)
442
+ >>>
443
+ >>> # Create a network with refractory neurons
444
+ >>> network = bs.nn.Sequential([
445
+ ... bs.nn.LIFRef(100, tau_ref=4*u.ms),
446
+ ... bs.nn.Linear(100, 10)
447
+ ... ])
448
+
449
+ Notes
450
+ -----
451
+ - The refractory period is implemented by tracking the time of the last spike
452
+ and preventing membrane potential updates if the elapsed time is less than tau_ref.
453
+ - During the refractory period, the membrane potential remains at the reset value
454
+ regardless of input current strength.
455
+ - Refractory periods prevent high-frequency repetitive firing and are critical
456
+ for realistic neural dynamics.
457
+ - The time-dependent dynamics are integrated using an exponential Euler method.
458
+ - The simulation environment time variable 't' is used to track the refractory state.
459
+
460
+ References
461
+ ----------
462
+ .. [1] Gerstner, W., Kistler, W. M., Naud, R., & Paninski, L. (2014).
463
+ Neuronal dynamics: From single neurons to networks and models of cognition.
464
+ Cambridge University Press.
465
+ .. [2] Burkitt, A. N. (2006). A review of the integrate-and-fire neuron model:
466
+ I. Homogeneous synaptic input. Biological cybernetics, 95(1), 1-19.
467
+ .. [3] Izhikevich, E. M. (2003). Simple model of spiking neurons. IEEE Transactions on
468
+ neural networks, 14(6), 1569-1572.
166
469
  """
167
470
  __module__ = 'brainstate.nn'
168
471
 
@@ -222,8 +525,123 @@ class LIFRef(Neuron):
222
525
 
223
526
 
224
527
  class ALIF(Neuron):
225
- """
226
- Adaptive Leaky Integrate-and-Fire (LIF) neuron model.
528
+ r"""Adaptive Leaky Integrate-and-Fire (ALIF) neuron model.
529
+
530
+ This class implements the Adaptive Leaky Integrate-and-Fire neuron model, which extends
531
+ the basic LIF model by adding an adaptation variable. This adaptation mechanism increases
532
+ the effective firing threshold after each spike, allowing the neuron to exhibit
533
+ spike-frequency adaptation - a common feature in biological neurons that reduces
534
+ firing rate during sustained stimulation.
535
+
536
+ The model is characterized by the following differential equations:
537
+
538
+ $$
539
+ \tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I(t)
540
+ $$
541
+
542
+ $$
543
+ \tau_a \frac{da}{dt} = -a
544
+ $$
545
+
546
+ Spike condition:
547
+ If $V \geq V_{th} + \beta \cdot a$: emit spike, set $V = V_{reset}$, and increment $a = a + 1$
548
+
549
+ Parameters
550
+ ----------
551
+ in_size : Size
552
+ Size of the input to the neuron.
553
+ R : ArrayLike, default=1. * u.ohm
554
+ Membrane resistance.
555
+ tau : ArrayLike, default=5. * u.ms
556
+ Membrane time constant.
557
+ tau_a : ArrayLike, default=100. * u.ms
558
+ Adaptation time constant (typically much longer than tau).
559
+ V_th : ArrayLike, default=1. * u.mV
560
+ Base firing threshold voltage.
561
+ V_reset : ArrayLike, default=0. * u.mV
562
+ Reset voltage after spike.
563
+ V_rest : ArrayLike, default=0. * u.mV
564
+ Resting membrane potential.
565
+ beta : ArrayLike, default=0.1 * u.mV
566
+ Adaptation coupling parameter that scales the effect of the adaptation variable.
567
+ spk_fun : Callable, default=surrogate.ReluGrad()
568
+ Surrogate gradient function for the non-differentiable spike generation.
569
+ spk_reset : str, default='soft'
570
+ Reset mechanism after spike generation:
571
+ - 'soft': subtract threshold V = V - V_th
572
+ - 'hard': strict reset using stop_gradient
573
+ V_initializer : Callable, default=init.Constant(0. * u.mV)
574
+ Initializer for the membrane potential state.
575
+ a_initializer : Callable, default=init.Constant(0.)
576
+ Initializer for the adaptation variable.
577
+ name : str, optional
578
+ Name of the neuron layer.
579
+
580
+ Attributes
581
+ ----------
582
+ V : HiddenState
583
+ Membrane potential.
584
+ a : HiddenState
585
+ Adaptation variable that increases after each spike and decays exponentially.
586
+
587
+ Methods
588
+ -------
589
+ init_state(batch_size=None, **kwargs)
590
+ Initialize the neuron state variables.
591
+ reset_state(batch_size=None, **kwargs)
592
+ Reset the neuron state variables.
593
+ get_spike(V=None, a=None)
594
+ Generate spikes based on the membrane potential and adaptation variable.
595
+ update(x=0. * u.mA)
596
+ Update the neuron state for one time step and return spikes.
597
+
598
+ Examples
599
+ --------
600
+ >>> import brainstate as bs
601
+ >>> import brainunit as u
602
+ >>>
603
+ >>> # Create an ALIF neuron layer with 10 neurons
604
+ >>> alif = bs.nn.ALIF(10,
605
+ ... tau=10*u.ms,
606
+ ... tau_a=200*u.ms,
607
+ ... beta=0.2*u.mV)
608
+ >>>
609
+ >>> # Initialize the state
610
+ >>> alif.init_state(batch_size=1)
611
+ >>>
612
+ >>> # Apply an input current and update the neuron state
613
+ >>> spikes = alif.update(x=1.5*u.mA)
614
+ >>>
615
+ >>> # Create a network with adaptation for burst detection
616
+ >>> network = bs.nn.Sequential([
617
+ ... bs.nn.ALIF(100, tau_a=150*u.ms, beta=0.3*u.mV),
618
+ ... bs.nn.Linear(100, 10)
619
+ ... ])
620
+
621
+ Notes
622
+ -----
623
+ - The adaptation variable 'a' increases by 1 with each spike and decays exponentially
624
+ with time constant tau_a between spikes.
625
+ - The effective threshold increases by beta*a, making it progressively harder for the
626
+ neuron to fire when it has recently been active.
627
+ - This adaptation mechanism creates spike-frequency adaptation, allowing the neuron
628
+ to respond strongly to input onset but then reduce its firing rate even if the
629
+ input remains constant.
630
+ - The adaptation time constant tau_a is typically much larger than the membrane time
631
+ constant tau, creating a longer-lasting adaptation effect.
632
+ - The time-dependent dynamics are integrated using an exponential Euler method.
633
+
634
+ References
635
+ ----------
636
+ .. [1] Gerstner, W., Kistler, W. M., Naud, R., & Paninski, L. (2014).
637
+ Neuronal dynamics: From single neurons to networks and models of cognition.
638
+ Cambridge University Press.
639
+ .. [2] Brette, R., & Gerstner, W. (2005). Adaptive exponential integrate-and-fire model
640
+ as an effective description of neuronal activity. Journal of neurophysiology,
641
+ 94(5), 3637-3642.
642
+ .. [3] Naud, R., Marcille, N., Clopath, C., & Gerstner, W. (2008). Firing patterns in
643
+ the adaptive exponential integrate-and-fire model. Biological cybernetics,
644
+ 99(4), 335-347.
227
645
  """
228
646
  __module__ = 'brainstate.nn'
229
647
 
@@ -17,10 +17,11 @@
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ import unittest
21
+
20
22
  import brainunit as u
21
23
  import jax
22
24
  import jax.numpy as jnp
23
- import unittest
24
25
 
25
26
  import brainstate as bst
26
27
  from brainstate.nn import IF, LIF, ALIF