Skip to content

Commit 00eeff9

Browse files
author
Alexander Ororbia
committed
wrote dynamics for exp-syn
1 parent d8636ce commit 00eeff9

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

ngclearn/components/synapses/exponentialSynapse.py

+51-42
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,33 @@ class ExponentialSynapse(DenseSynapse): ## dynamic exponential synapse cable
1818
1919
2020
| --- Synapse Compartments: ---
21-
| inputs - input (takes in external signals)
22-
| outputs - output signals
21+
| inputs - input (takes in external signals, e.g., pre-synaptic pulses/spikes)
22+
| outputs - output signals (also equal to i_syn, total electrical current)
23+
| v - coupled voltages from post-synaptic neurons this synaptic cable connects to
2324
| weights - current value matrix of synaptic efficacies
2425
| biases - current value vector of synaptic bias values
25-
| --- Short-Term Plasticity Compartments: ---
26-
| resources - fixed value matrix of synaptic resources (U)
27-
| u - release probability; fraction of resources ready for use
28-
| x - fraction of resources available after neurotransmitter depletion
29-
30-
| Dynamics note:
31-
| If tau_d >> tau_f and resources U are large, then synapse is STD-dominated
32-
| If tau_d << tau_f and resources U are small, then synases is STF-dominated
26+
| --- Dynamic / Short-term Plasticity Compartments: ---
27+
| g_syn - fixed value matrix of synaptic resources (U)
28+
| i_syn - derived total electrical current variable
3329
3430
Args:
3531
name: the string name of this cell
3632
3733
shape: tuple specifying shape of this synaptic cable (usually a 2-tuple
3834
with number of inputs by number of outputs)
3935
36+
tau_syn: synaptic time constant (ms)
37+
38+
g_syn_bar: maximum conductance elicited by each incoming spike ("synaptic weight")
39+
40+
syn_rest: synaptic reversal potential
41+
4042
weight_init: a kernel to drive initialization of this synaptic cable's values;
4143
typically a tuple with 1st element as a string calling the name of
4244
initialization to use
4345
4446
bias_init: a kernel to drive initialization of biases for this synaptic cable
45-
(Default: None, which turns off/disables biases)
47+
(Default: None, which turns off/disables biases) <unused>
4648
4749
resist_scale: a fixed (resistance) scaling factor to apply to synaptic
4850
transform (Default: 1.), i.e., yields: out = ((W * Rscale) * in)
@@ -51,52 +53,56 @@ class ExponentialSynapse(DenseSynapse): ## dynamic exponential synapse cable
5153
this to < 1 and > 0. will result in a sparser synaptic structure
5254
(lower values yield sparse structure)
5355
54-
tau_f: short-term facilitation (STF) time constant (default: `750` ms); note
55-
that setting this to `0` ms will disable STF
56-
57-
tau_d: shoft-term depression time constant (default: `50` ms); note
58-
that setting this to `0` ms will disable STD
56+
is_nonplastic: boolean indicating if this synapse permits plasticity adjustments (Default: True)
5957
60-
resources_int: initialization kernel for synaptic resources matrix
6158
"""
6259

6360
# Define Functions
64-
def __init__(self, name, shape, weight_init=None, bias_init=None,
65-
resist_scale=1., p_conn=1., tau_f=750., tau_d=50.,
66-
resources_init=None, **kwargs):
61+
def __init__(
62+
self, name, shape, tau_syn, g_syn_bar, syn_rest, weight_init=None, bias_init=None, resist_scale=1., p_conn=1.,
63+
is_nonplastic=True, **kwargs
64+
):
6765
super().__init__(name, shape, weight_init, bias_init, resist_scale, p_conn, **kwargs)
68-
## STP meta-parameters
69-
self.resources_init = resources_init
70-
self.tau_f = tau_f
71-
self.tau_d = tau_d
66+
## dynamic synapse meta-parameters
67+
self.tau_syn = tau_syn
68+
self.g_syn_bar = g_syn_bar
69+
self.syn_rest = syn_rest ## synaptic resting potential
7270

7371
## Set up short-term plasticity / dynamic synapse compartment values
74-
tmp_key, *subkeys = random.split(self.key.value, 4)
75-
preVals = jnp.zeros((self.batch_size, shape[0]))
76-
self.i = Compartment(preVals) ## electrical current output
77-
self.g = Compartment(preVals) ## conductance variable
78-
79-
80-
@transition(output_compartments=["outputs", "i", "g"])
72+
#tmp_key, *subkeys = random.split(self.key.value, 4)
73+
#preVals = jnp.zeros((self.batch_size, shape[0]))
74+
postVals = jnp.zeros((self.batch_size, shape[1]))
75+
self.v = Compartment(postVals) ## coupled voltage (from a post-synaptic neuron)
76+
self.i_syn = Compartment(postVals) ## electrical current output
77+
self.g_syn = Compartment(postVals) ## conductance variable
78+
if is_nonplastic:
79+
self.weights.set(self.weights * 0 + 1.)
80+
81+
@transition(output_compartments=["outputs", "i_syn", "g_syn"])
8182
@staticmethod
8283
def advance_state(
83-
tau_f, tau_d, Rscale, inputs, weights, biases, i, g
84+
dt, tau_syn, g_syn_bar, syn_rest, Rscale, inputs, weights, i_syn, g_syn, v
8485
):
8586
s = inputs
86-
87-
outputs = None #jnp.matmul(inputs, Wdyn * Rscale) + biases
88-
return outputs
89-
90-
@transition(output_compartments=["inputs", "outputs", "i", "g"])
87+
## advance conductance variable
88+
_out = jnp.matmul(s, weights) ## sum all pre-syn spikes at t going into post-neuron)
89+
dgsyn_dt = _out * g_syn_bar - g_syn/tau_syn
90+
g_syn = g_syn + dgsyn_dt * dt ## run Euler step to move conductance
91+
i_syn = g_syn * (v - syn_rest)
92+
outputs = i_syn #jnp.matmul(inputs, Wdyn * Rscale) + biases
93+
return outputs, i_syn, g_syn
94+
95+
@transition(output_compartments=["inputs", "outputs", "i_syn", "g_syn", "v"])
9196
@staticmethod
9297
def reset(batch_size, shape):
9398
preVals = jnp.zeros((batch_size, shape[0]))
9499
postVals = jnp.zeros((batch_size, shape[1]))
95100
inputs = preVals
96101
outputs = postVals
97-
i = preVals
98-
g = preVals
99-
return inputs, outputs, i, g
102+
i_syn = postVals
103+
g_syn = postVals
104+
v = postVals
105+
return inputs, outputs, i_syn, g_syn, v
100106

101107
def save(self, directory, **kwargs):
102108
file_name = directory + "/" + self.name + ".npz"
@@ -135,11 +141,14 @@ def help(cls): ## component help function
135141
"bias_init": "Initialization conditions for bias/base-rate (b) values",
136142
"resist_scale": "Resistance level scaling factor (applied to output of transformation)",
137143
"p_conn": "Probability of a connection existing (otherwise, it is masked to zero)",
144+
"tau_syn": "Synaptic time constant (ms)",
145+
"g_bar_syn": "Maximum conductance value",
146+
"syn_rest": "Synaptic reversal potential"
138147
}
139148
info = {cls.__name__: properties,
140149
"compartments": compartment_props,
141-
"dynamics": "outputs = [(W * Rscale) * inputs] + b; "
142-
"dg/dt = ",
150+
"dynamics": "outputs = g_syn * (v - syn_rest); "
151+
"dgsyn_dt = (W * inputs) * g_syn_bar - g_syn/tau_syn ",
143152
"hyperparameters": hyperparams}
144153
return info
145154

0 commit comments

Comments
 (0)