brainstate 0.1.0.post20241221__py2.py3-none-any.whl → 0.1.0.post20250101__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.
- brainstate/__init__.py +0 -14
- brainstate/nn/_dyn_impl/_dynamics_synapse.py +85 -1
- brainstate/transform.py +5 -1
- {brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/METADATA +1 -1
- {brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/RECORD +8 -8
- {brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/LICENSE +0 -0
- {brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/WHEEL +0 -0
- {brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/top_level.txt +0 -0
brainstate/__init__.py
CHANGED
@@ -48,19 +48,5 @@ __all__ = (
|
|
48
48
|
_state_all
|
49
49
|
)
|
50
50
|
|
51
|
-
# ----------------------- #
|
52
|
-
# deprecations
|
53
|
-
# ----------------------- #
|
54
|
-
|
55
|
-
from ._utils import deprecation_getattr
|
56
|
-
|
57
|
-
transform._deprecations = dict()
|
58
|
-
for key in compile.__all__:
|
59
|
-
transform._deprecations[key] = (f'brainstate.transform.{key}', f'brainstate.compile.{key}', getattr(compile, key))
|
60
|
-
for key in augment.__all__:
|
61
|
-
transform._deprecations[key] = (f'brainstate.transform.{key}', f'brainstate.augment.{key}', getattr(augment, key))
|
62
|
-
transform.__getattr__ = deprecation_getattr('brainstate.transform', transform._deprecations)
|
63
|
-
del deprecation_getattr
|
64
|
-
|
65
51
|
# ----------------------- #
|
66
52
|
del _state_all
|
@@ -41,7 +41,8 @@ class Synapse(Dynamics):
|
|
41
41
|
|
42
42
|
|
43
43
|
class Expon(Synapse, AlignPost):
|
44
|
-
r"""
|
44
|
+
r"""
|
45
|
+
Exponential decay synapse model.
|
45
46
|
|
46
47
|
Args:
|
47
48
|
tau: float. The time constant of decay. [ms]
|
@@ -75,6 +76,89 @@ class Expon(Synapse, AlignPost):
|
|
75
76
|
return self.g.value
|
76
77
|
|
77
78
|
|
79
|
+
class DualExpon(Synapse, AlignPost):
|
80
|
+
__module__ = 'brainstate.nn'
|
81
|
+
|
82
|
+
def __init__(
|
83
|
+
self,
|
84
|
+
in_size: Size,
|
85
|
+
name: Optional[str] = None,
|
86
|
+
tau_decay: ArrayLike = 10.0 * u.ms,
|
87
|
+
tau_rise: ArrayLike = 1.0 * u.ms,
|
88
|
+
A: Optional[ArrayLike] = None,
|
89
|
+
g_initializer: ArrayLike = init.ZeroInit(unit=u.mS),
|
90
|
+
):
|
91
|
+
super().__init__(name=name, in_size=in_size)
|
92
|
+
|
93
|
+
# parameters
|
94
|
+
self.tau_decay = init.param(tau_decay, self.varshape)
|
95
|
+
self.tau_rise = init.param(tau_rise, self.varshape)
|
96
|
+
A = self._format_dual_exp_A(A)
|
97
|
+
self.a = (self.tau_decay - self.tau_rise) / self.tau_rise / self.tau_decay * A
|
98
|
+
self.g_initializer = g_initializer
|
99
|
+
|
100
|
+
def _format_dual_exp_A(self, A):
|
101
|
+
A = init.param(A, sizes=self.varshape, allow_none=True)
|
102
|
+
if A is None:
|
103
|
+
A = (
|
104
|
+
self.tau_decay / (self.tau_decay - self.tau_rise) *
|
105
|
+
u.math.float_power(self.tau_rise / self.tau_decay,
|
106
|
+
self.tau_rise / (self.tau_rise - self.tau_decay))
|
107
|
+
)
|
108
|
+
return A
|
109
|
+
|
110
|
+
def init_state(self, batch_size: int = None, **kwargs):
|
111
|
+
self.g_rise = HiddenState(init.param(self.g_initializer, self.varshape, batch_size))
|
112
|
+
self.g_decay = HiddenState(init.param(self.g_initializer, self.varshape, batch_size))
|
113
|
+
|
114
|
+
def reset_state(self, batch_size: int = None, **kwargs):
|
115
|
+
self.g_rise.value = init.param(self.g_initializer, self.varshape, batch_size)
|
116
|
+
self.g_decay.value = init.param(self.g_initializer, self.varshape, batch_size)
|
117
|
+
|
118
|
+
def update(self, x=None):
|
119
|
+
g_rise = exp_euler_step(lambda h: -h / self.tau_rise, self.g_rise.value)
|
120
|
+
g_decay = exp_euler_step(lambda g: -g / self.tau_decay, self.g_decay.value)
|
121
|
+
self.g_rise.value = self.sum_delta_inputs(g_rise)
|
122
|
+
self.g_decay.value = self.sum_delta_inputs(g_decay)
|
123
|
+
if x is not None:
|
124
|
+
self.g_rise.value += x
|
125
|
+
self.g_decay.value += x
|
126
|
+
return self.a * (self.g_decay.value - self.g_rise.value)
|
127
|
+
|
128
|
+
|
129
|
+
class Alpha(Synapse):
|
130
|
+
__module__ = 'brainstate.nn'
|
131
|
+
|
132
|
+
def __init__(
|
133
|
+
self,
|
134
|
+
in_size: Size,
|
135
|
+
name: Optional[str] = None,
|
136
|
+
tau: ArrayLike = 8.0 * u.ms,
|
137
|
+
g_initializer: ArrayLike = init.ZeroInit(unit=u.mS),
|
138
|
+
):
|
139
|
+
super().__init__(name=name, in_size=in_size)
|
140
|
+
|
141
|
+
# parameters
|
142
|
+
self.tau = init.param(tau, self.varshape)
|
143
|
+
self.g_initializer = g_initializer
|
144
|
+
|
145
|
+
def init_state(self, batch_size: int = None, **kwargs):
|
146
|
+
self.g = HiddenState(init.param(self.g_initializer, self.varshape, batch_size))
|
147
|
+
self.h = HiddenState(init.param(self.g_initializer, self.varshape, batch_size))
|
148
|
+
|
149
|
+
def reset_state(self, batch_size: int = None, **kwargs):
|
150
|
+
self.g.value = init.param(self.g_initializer, self.varshape, batch_size)
|
151
|
+
self.h.value = init.param(self.g_initializer, self.varshape, batch_size)
|
152
|
+
|
153
|
+
def update(self, x=None):
|
154
|
+
h = exp_euler_step(lambda h: -h / self.tau, self.h.value)
|
155
|
+
self.g.value = exp_euler_step(lambda g, h: -g / self.tau + h / self.tau, self.g.value, self.h.value)
|
156
|
+
self.h.value = self.sum_delta_inputs(h)
|
157
|
+
if x is not None:
|
158
|
+
self.h.value += x
|
159
|
+
return self.g.value
|
160
|
+
|
161
|
+
|
78
162
|
class STP(Synapse):
|
79
163
|
r"""Synaptic output with short-term plasticity.
|
80
164
|
|
brainstate/transform.py
CHANGED
@@ -13,4 +13,8 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
# ==============================================================================
|
15
15
|
|
16
|
-
#
|
16
|
+
# alias for compilation and augmentation functions
|
17
|
+
|
18
|
+
from .compile import *
|
19
|
+
from .augment import *
|
20
|
+
|
{brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: brainstate
|
3
|
-
Version: 0.1.0.
|
3
|
+
Version: 0.1.0.post20250101
|
4
4
|
Summary: A ``State``-based Transformation System for Program Compilation and Augmentation.
|
5
5
|
Home-page: https://github.com/chaobrain/brainstate
|
6
6
|
Author: BrainState Developers
|
@@ -1,4 +1,4 @@
|
|
1
|
-
brainstate/__init__.py,sha256=
|
1
|
+
brainstate/__init__.py,sha256=A-QKdOvSalsCMxgk80Iz6_xMiUin6con6JaONHfciSY,1526
|
2
2
|
brainstate/_state.py,sha256=4aDpLyHGr1VlPXeLSfM3USQG5K4o7orF7IlaBdYrtfE,29098
|
3
3
|
brainstate/_state_test.py,sha256=1boTp1w8DiCFLsPwNtlLrlIqGRpkasAmLid5bv2fgP4,2223
|
4
4
|
brainstate/_utils.py,sha256=uJ6WWKq3yb05ZdktCQGLWOXsOJveL1H9pR7eev70Jes,1693
|
@@ -7,7 +7,7 @@ brainstate/environ_test.py,sha256=jXX3nR1CO74aow5YqfqSd73isj9MWgHQxrwSsEjTDY8,19
|
|
7
7
|
brainstate/mixin.py,sha256=g7uVUwZphZWsNs9pb48ozG2cDGaj0hs0g3lq8tDk-Sg,11310
|
8
8
|
brainstate/mixin_test.py,sha256=Oq_0fwC9vpXDN4t4dTBhWzLdFDNlcYsrcip14F1yECI,3079
|
9
9
|
brainstate/surrogate.py,sha256=YaY6RJ6kzpuPXWFjaWsxWt2MzJfdm5v_jeOR8V_jPoU,48369
|
10
|
-
brainstate/transform.py,sha256=
|
10
|
+
brainstate/transform.py,sha256=cxbymTlJ6uHvJWEEYXzFUkAySs_TbUTHakt0NQgWJ3s,808
|
11
11
|
brainstate/typing.py,sha256=Qh-LBzm6oG4rSXv4V5qB8SNYcoOR7bASoK_iQxnlafk,10467
|
12
12
|
brainstate/augment/__init__.py,sha256=BtXIBel7GbttmfBX6grxOxl0IiOJxLEa7qCGAXumamE,1286
|
13
13
|
brainstate/augment/_autograd.py,sha256=o9ivoEY7BmtdM1XmzdMmeRXpj6Tvn5xNB8LSGp2HKC8,25238
|
@@ -81,7 +81,7 @@ brainstate/nn/metrics.py,sha256=iupHjSRTHYY-HmEPBC4tXWrZfF4zh1ek2NwSAA0gnwE,1473
|
|
81
81
|
brainstate/nn/_dyn_impl/__init__.py,sha256=Oazar7h89dp1WA2Vx4Tj7gCBhxJKH4LAUEABkBEG7vU,1462
|
82
82
|
brainstate/nn/_dyn_impl/_dynamics_neuron.py,sha256=cTbIn41EPYG0h3ICzKBXxpgB6wwA2K8k5FAcf3Pa5N8,10927
|
83
83
|
brainstate/nn/_dyn_impl/_dynamics_neuron_test.py,sha256=Tfzrzu7udGrLJGnqItiLWe5WT0dgduvYOgzGCnaPJQg,6317
|
84
|
-
brainstate/nn/_dyn_impl/_dynamics_synapse.py,sha256=
|
84
|
+
brainstate/nn/_dyn_impl/_dynamics_synapse.py,sha256=41P3qJf8fi4J7dZdDnjChJF6lYJjFAOkgy9aE3FReY4,15247
|
85
85
|
brainstate/nn/_dyn_impl/_dynamics_synapse_test.py,sha256=t5i-HV0ii9sUNzWTEv04o26QVtQ-mCdMJcFq2MD755A,4981
|
86
86
|
brainstate/nn/_dyn_impl/_inputs.py,sha256=pkcAVt_o5kQF_BGCTZZ-NUQpHgjlFHHPwtYC0fJkAA0,9099
|
87
87
|
brainstate/nn/_dyn_impl/_projection_alignpost.py,sha256=PNC1Tzx_SF2DHAHeJCufXzO_Q4qLoBpWABI45B3GRuc,876
|
@@ -137,8 +137,8 @@ brainstate/util/_scaling.py,sha256=pc_eM_SZVwkY65I4tJh1ODiHNCoEhsfFXl2zBK0PLAg,7
|
|
137
137
|
brainstate/util/_struct.py,sha256=0exv0oOiSt1hmx20Y4J2-pCGtCTx13WcAlEYSBkyung,17640
|
138
138
|
brainstate/util/_tracers.py,sha256=0r5T4nhxMzI79NtqroqitsdMT4YfpgV5RdYJLS5uJ0w,2285
|
139
139
|
brainstate/util/_visualization.py,sha256=n4ZVz10z7VBqA0cKO6vyHwEMprWJgPeEqtITzDMai2Y,1519
|
140
|
-
brainstate-0.1.0.
|
141
|
-
brainstate-0.1.0.
|
142
|
-
brainstate-0.1.0.
|
143
|
-
brainstate-0.1.0.
|
144
|
-
brainstate-0.1.0.
|
140
|
+
brainstate-0.1.0.post20250101.dist-info/LICENSE,sha256=VZe9u1jgUL2eCY6ZPOYgdb8KCblCHt8ECdbtJid6e1s,11550
|
141
|
+
brainstate-0.1.0.post20250101.dist-info/METADATA,sha256=QFsDpwFlj0QnoV3srIVjxTiWxJEmVROOlhLRM3u-B44,3533
|
142
|
+
brainstate-0.1.0.post20250101.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
|
143
|
+
brainstate-0.1.0.post20250101.dist-info/top_level.txt,sha256=eQbGgKn0ptx7FDWuua0V0wr4K1VHi2iOUCYo3fUQBRA,11
|
144
|
+
brainstate-0.1.0.post20250101.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{brainstate-0.1.0.post20241221.dist-info → brainstate-0.1.0.post20250101.dist-info}/top_level.txt
RENAMED
File without changes
|