| 1 |
#!/usr/bin/env python3 |
| 2 |
""" |
| 3 |
Fig. 1 from: |
| 4 |
|
| 5 |
M. Tsodyks, K. Pawelzik, H. Markram |
| 6 |
Neural Networks with Dynamic Synapses |
| 7 |
Neural Computation 10, 821–835 (1998) |
| 8 |
|
| 9 |
https://doi.org/10.1162/089976698300017502 |
| 10 |
|
| 11 |
Sebastian Schmitt, 2022 |
| 12 |
""" |
| 13 |
|
| 14 |
import numpy as np |
| 15 |
import matplotlib.pyplot as plt |
| 16 |
|
| 17 |
from brian2 import ( |
| 18 |
NeuronGroup, |
| 19 |
Synapses, |
| 20 |
SpikeGeneratorGroup, |
| 21 |
SpikeMonitor, |
| 22 |
StateMonitor, |
| 23 |
) |
| 24 |
from brian2 import ms, mV, pA, Mohm, Gohm, Hz |
| 25 |
from brian2 import run |
| 26 |
|
| 27 |
|
| 28 |
def get_neuron(tau_mem, R_in): |
| 29 |
""" |
| 30 |
tau_mem -- membrane time constant |
| 31 |
R_in -- input resistance |
| 32 |
""" |
| 33 |
neuron = NeuronGroup(1, |
| 34 |
""" |
| 35 |
tau_mem : second |
| 36 |
I_syn : ampere |
| 37 |
R_in : ohm |
| 38 |
dv/dt = -v/tau_mem + (R_in*I_syn)/tau_mem : volt |
| 39 |
""", |
| 40 |
method="exact") |
| 41 |
|
| 42 |
neuron.tau_mem = tau_mem |
| 43 |
neuron.R_in = R_in |
| 44 |
|
| 45 |
return neuron |
| 46 |
|
| 47 |
|
| 48 |
def get_synapses(stimulus, neuron, tau_inact, A_SE, U_SE, tau_rec, tau_facil=None): |
| 49 |
""" |
| 50 |
stimulus -- input stimulus |
| 51 |
neuron -- target neuron |
| 52 |
tau_inact -- inactivation time constant |
| 53 |
A_SE -- absolute synaptic strength |
| 54 |
U_SE -- utilization of synaptic efficacy |
| 55 |
tau_rec -- recovery time constant |
| 56 |
tau_facil -- facilitation time constant (optional) |
| 57 |
""" |
| 58 |
|
| 59 |
synapses_eqs = """ |
| 60 |
dx/dt = z/tau_rec : 1 (clock-driven) # recovered |
| 61 |
dy/dt = -y/tau_inact : 1 (clock-driven) # active |
| 62 |
A_SE : ampere |
| 63 |
U_SE : 1 |
| 64 |
tau_inact : second |
| 65 |
tau_rec : second |
| 66 |
z = 1 - x - y : 1 # inactive |
| 67 |
I_syn_post = A_SE*y : ampere (summed) |
| 68 |
""" |
| 69 |
|
| 70 |
if tau_facil: |
| 71 |
synapses_eqs += """ |
| 72 |
du/dt = -u/tau_facil : 1 (clock-driven) |
| 73 |
tau_facil : second |
| 74 |
""" |
| 75 |
|
| 76 |
synapses_action = """ |
| 77 |
u += U_SE*(1-u) |
| 78 |
y += u*x # important: update y first |
| 79 |
x += -u*x |
| 80 |
""" |
| 81 |
else: |
| 82 |
synapses_action = """ |
| 83 |
y += U_SE*x # important: update y first |
| 84 |
x += -U_SE*x |
| 85 |
""" |
| 86 |
|
| 87 |
synapses = Synapses(stimulus, |
| 88 |
neuron, |
| 89 |
model=synapses_eqs, |
| 90 |
on_pre=synapses_action, |
| 91 |
method="exponential_euler") |
| 92 |
synapses.connect() |
| 93 |
|
| 94 |
# start fully recovered |
| 95 |
synapses.x = 1 |
| 96 |
|
| 97 |
synapses.tau_inact = tau_inact |
| 98 |
synapses.A_SE = A_SE |
| 99 |
synapses.U_SE = U_SE |
| 100 |
synapses.tau_rec = tau_rec |
| 101 |
|
| 102 |
if tau_facil: |
| 103 |
synapses.tau_facil = tau_facil |
| 104 |
|
| 105 |
return synapses |
| 106 |
|
| 107 |
|
| 108 |
def get_stimulus(start, stop, frequency): |
| 109 |
""" |
| 110 |
start -- start time of stimulus |
| 111 |
stop -- stop time of stimulus |
| 112 |
frequency -- frequency of stimulus |
| 113 |
""" |
| 114 |
|
| 115 |
times = np.arange(start / ms, stop / ms, 1 / (frequency / Hz) * 1e3) * ms |
| 116 |
stimulus = SpikeGeneratorGroup(1, [0] * len(times), times) |
| 117 |
|
| 118 |
return stimulus |
| 119 |
|
| 120 |
|
| 121 |
parameters = { |
| 122 |
"A": { |
| 123 |
"neuron": {"tau_mem": 40 * ms, |
| 124 |
"R_in": 100*Mohm}, |
| 125 |
"synapse": { |
| 126 |
"tau_inact": 3 * ms, |
| 127 |
"A_SE": 250 * pA, |
| 128 |
"tau_rec": 800 * ms, |
| 129 |
"U_SE": 0.6, # 0.5 from publication does not match plot |
| 130 |
}, |
| 131 |
"stimulus": {"start": 100 * ms, |
| 132 |
"stop": 1100 * ms, |
| 133 |
"frequency": 20 * Hz}, |
| 134 |
"simulation": {"duration": 1200 * ms}, |
| 135 |
"plot": { |
| 136 |
"title": "A) D - 20 Hz", |
| 137 |
"ylim": [0, 1], |
| 138 |
"xlim": [0, 1200], |
| 139 |
"xtickstep": 200, |
| 140 |
}, |
| 141 |
}, |
| 142 |
"B": { |
| 143 |
"neuron": {"tau_mem": 60 * ms, |
| 144 |
"R_in": 1*Gohm}, |
| 145 |
"synapse": { |
| 146 |
"tau_inact": 1.5 * ms, |
| 147 |
"A_SE": 1540 * pA, |
| 148 |
"tau_rec": 130 * ms, |
| 149 |
"U_SE": 0.03, |
| 150 |
"tau_facil": 530 * ms, |
| 151 |
}, |
| 152 |
"stimulus": {"start": 100 * ms, |
| 153 |
"stop": 1100 * ms, |
| 154 |
"frequency": 20 * Hz}, |
| 155 |
"simulation": {"duration": 1200 * ms}, |
| 156 |
"plot": { |
| 157 |
"title": "B) F - 20 Hz", |
| 158 |
"ylim": [0, 14.9], |
| 159 |
"xlim": [0, 1200], |
| 160 |
"xtickstep": 200, |
| 161 |
}, |
| 162 |
}, |
| 163 |
"C": { |
| 164 |
"neuron": {"tau_mem": 60 * ms, |
| 165 |
"R_in": 1*Gohm}, |
| 166 |
"synapse": { |
| 167 |
"tau_inact": 1.5 * ms, |
| 168 |
"A_SE": 1540 * pA, |
| 169 |
"tau_rec": 130 * ms, |
| 170 |
"U_SE": 0.03, |
| 171 |
"tau_facil": 530 * ms, |
| 172 |
}, |
| 173 |
"stimulus": {"start": 100 * ms, |
| 174 |
"stop": 375 * ms, |
| 175 |
"frequency": 70 * Hz}, |
| 176 |
"simulation": {"duration": 500 * ms}, |
| 177 |
"plot": { |
| 178 |
"title": "C) F - 70 Hz", |
| 179 |
"ylim": [0, 20], |
| 180 |
"xlim": [0, 500], |
| 181 |
"xtickstep": 50, |
| 182 |
}, |
| 183 |
}, |
| 184 |
} |
| 185 |
|
| 186 |
fig, axes = plt.subplots(3) |
| 187 |
|
| 188 |
for ax, (panel, p) in zip(axes, parameters.items()): |
| 189 |
|
| 190 |
neuron = get_neuron(**p["neuron"]) |
| 191 |
stimulus = get_stimulus(**p["stimulus"]) |
| 192 |
synapses = get_synapses(stimulus, neuron, **p["synapse"]) |
| 193 |
|
| 194 |
state_monitor_neuron = StateMonitor(neuron, ["v"], record=True) |
| 195 |
|
| 196 |
run(p["simulation"]["duration"]) |
| 197 |
|
| 198 |
ax.plot( |
| 199 |
state_monitor_neuron.t / ms, |
| 200 |
state_monitor_neuron[0].v / mV, |
| 201 |
label=p["plot"]["title"], |
| 202 |
) |
| 203 |
|
| 204 |
ax.set_xlim(*p["plot"]["xlim"]) |
| 205 |
ax.set_ylim(*p["plot"]["ylim"]) |
| 206 |
ax.set_ylabel("mV") |
| 207 |
ax.set_xlabel("Time (ms)") |
| 208 |
|
| 209 |
ax.set_xticks( |
| 210 |
np.arange( |
| 211 |
p["plot"]["xlim"][0], |
| 212 |
p["plot"]["xlim"][1] + p["plot"]["xtickstep"], |
| 213 |
p["plot"]["xtickstep"], |
| 214 |
) |
| 215 |
) |
| 216 |
|
| 217 |
ax.legend() |
| 218 |
|
| 219 |
plt.show() |