Skip to content

Commit c89bffa

Browse files
authored
Merge pull request #503 from brainpy/doc
[doc] add synapse model documentations
2 parents b31c0b7 + e610c84 commit c89bffa

File tree

12 files changed

+2505
-21
lines changed

12 files changed

+2505
-21
lines changed

brainpy/_src/dnn/linear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Dense(Layer, SupportOnline, SupportOffline, SupportSTDP):
4444
The number of the input feature. A positive integer.
4545
num_out: int
4646
The number of the output features. A positive integer.
47-
weight_initializer: optional, Initializer
47+
W_initializer: optional, Initializer
4848
The weight initialization.
4949
b_initializer: optional, Initializer
5050
The bias initialization.

brainpy/_src/dyn/projections/plasticity.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class STDP_Song2000(Projection):
4040
where :math:`t_{sp}` denotes the spike time and :math:`A_1` is the increment
4141
of :math:`A_{pre}`, :math:`A_2` is the increment of :math:`A_{post}` produced by a spike.
4242
43-
Example::
43+
Here is an example of the usage of this class::
44+
4445
import brainpy as bp
4546
import brainpy.math as bm
4647
@@ -138,10 +139,7 @@ def __init__(
138139
if not post.has_bef_update(self._post_repr):
139140
syn_cls = syn()
140141
out_cls = out()
141-
if out_label is None:
142-
out_name = self.name
143-
else:
144-
out_name = f'{out_label} // {self.name}'
142+
out_name = self.name if out_label is None else f'{out_label} // {self.name}'
145143
post.add_inp_fun(out_name, out_cls)
146144
post.add_bef_update(self._post_repr, _AlignPost(syn_cls, out_cls))
147145
# references
@@ -154,35 +152,29 @@ def __init__(
154152
# synapse initialization
155153
self._syn_id = f'Delay({str(delay)}) // {syn.identifier}'
156154
if not delay_cls.has_bef_update(self._syn_id):
157-
# delay
158155
delay_access = DelayAccess(delay_cls, delay)
159-
# synapse
160156
syn_cls = syn()
161-
# add to "after_updates"
162157
delay_cls.add_bef_update(self._syn_id, _AlignPreMg(delay_access, syn_cls))
163-
164158
# output initialization
165-
if out_label is None:
166-
out_name = self.name
167-
else:
168-
out_name = f'{out_label} // {self.name}'
159+
out_name = self.name if out_label is None else f'{out_label} // {self.name}'
169160
post.add_inp_fun(out_name, out)
170-
171161
# references
172162
self.refs = dict(pre=pre, post=post) # invisible to `self.nodes()`
173163
self.refs['delay'] = delay_cls.get_bef_update(self._syn_id)
174164
self.refs['syn'] = delay_cls.get_bef_update(self._syn_id).syn
175165
self.refs['out'] = out
176166

177-
self.refs['pre_trace'] = self.calculate_trace(pre, delay, Expon.desc(pre.num, tau=tau_s))
178-
self.refs['post_trace'] = self.calculate_trace(post, None, Expon.desc(post.num, tau=tau_t))
179-
# parameters
167+
# trace initialization
168+
self.refs['pre_trace'] = self._init_trace(pre, delay, Expon.desc(pre.num, tau=tau_s))
169+
self.refs['post_trace'] = self._init_trace(post, None, Expon.desc(post.num, tau=tau_t))
170+
171+
# synapse parameters
180172
self.tau_s = parameter(tau_s, sizes=self.pre_num)
181173
self.tau_t = parameter(tau_t, sizes=self.post_num)
182174
self.A1 = parameter(A1, sizes=self.pre_num)
183175
self.A2 = parameter(A2, sizes=self.post_num)
184176

185-
def calculate_trace(
177+
def _init_trace(
186178
self,
187179
target: DynamicalSystem,
188180
delay: Union[None, int, float],
@@ -234,5 +226,5 @@ def update(self):
234226
if issubclass(self.syn.cls, AlignPost):
235227
self.refs['syn'].add_current(current) # synapse post current
236228
else:
237-
self.refs['out'].bind_cond(current)
229+
self.refs['out'].bind_cond(current) # align pre
238230
return current

brainpy/_src/dyn/projections/tests/test_STDP.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ def run(i, I_pre, I_post):
5151

5252
indices = bm.arange(0, duration, bm.dt)
5353
bm.for_loop(run, [indices, I_pre, I_post], jit=True)
54+
bm.clear_buffer_memory()

brainpy/_src/dynsys.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ def __repr__(self):
593593

594594

595595
class Projection(DynamicalSystem):
596+
"""Base class to model synaptic projections.
597+
598+
Args:
599+
name: The name of the dynamic system.
600+
mode: The computing mode. It should be an instance of :py:class:`~.Mode`.
601+
"""
596602

597603
def update(self, *args, **kwargs):
598604
nodes = tuple(self.nodes(level=1, include_self=False).subset(DynamicalSystem).unique().values())
@@ -610,6 +616,10 @@ def reset_state(self, *args, **kwargs):
610616
else:
611617
raise ValueError('Do not implement the reset_state() function.')
612618

619+
def clear_input(self, *args, **kwargs):
620+
"""Empty function of clearing inputs."""
621+
pass
622+
613623

614624
class Dynamic(DynamicalSystem):
615625
"""Base class to model dynamics.

docs/_static/align_post.png

57.9 KB
Loading

docs/_static/align_pre.png

50.9 KB
Loading

docs/_static/csr_matrix.png

196 KB
Loading

docs/_static/masked_matrix.png

16.8 KB
Loading

0 commit comments

Comments
 (0)