| 1 |
#!/usr/bin/env python3 |
| 2 |
""" |
| 3 |
Reproduces Figure 2F of |
| 4 |
|
| 5 |
The Use of Hebbian Cell Assemblies for Nonlinear Computation |
| 6 |
by Tetzlaff C., Dasgupta S., Kulvicius T. and Wörgötter F. |
| 7 |
|
| 8 |
Sci Rep 5, 12866 (2015). |
| 9 |
https://doi.org/10.1038/srep12866 |
| 10 |
|
| 11 |
Sebastian Schmitt, 2022 |
| 12 |
""" |
| 13 |
|
| 14 |
import numpy as np |
| 15 |
import matplotlib.pyplot as plt |
| 16 |
|
| 17 |
from brian2 import NeuronGroup, Synapses, StateMonitor, run, defaultclock, ms, second, TimedArray, seed |
| 18 |
|
| 19 |
# random seed that gives curves similar to the ones in the publication |
| 20 |
seed(9873487) |
| 21 |
|
| 22 |
# neuron parameters (sigmoidal activation) |
| 23 |
beta = 0.03 |
| 24 |
epsilon = 120 |
| 25 |
F_max = 100 |
| 26 |
F_T = 1 |
| 27 |
tau_u = 1*ms |
| 28 |
R = 0.012 |
| 29 |
|
| 30 |
# plasticity timescales |
| 31 |
tau_ratio = 60 |
| 32 |
# hebbian |
| 33 |
tau_H = 3e4*ms |
| 34 |
# synaptic scaling |
| 35 |
tau_SS = tau_ratio * tau_H |
| 36 |
|
| 37 |
# synaptic weights |
| 38 |
W_max = np.sqrt(tau_ratio*(F_max**2/(F_max - F_T))) |
| 39 |
W_ext = W_max |
| 40 |
W_input = W_max |
| 41 |
W_I = 0.3*W_max |
| 42 |
|
| 43 |
# stimulus |
| 44 |
N_units = 100 |
| 45 |
N_stim_units = 20 |
| 46 |
stim_A_units_until = N_stim_units |
| 47 |
stim_B_units_from = N_units-N_stim_units |
| 48 |
|
| 49 |
# connection probabilities |
| 50 |
p_E = 0.1 |
| 51 |
p_I = 0.2 |
| 52 |
|
| 53 |
# paper uses 0.3*ms |
| 54 |
DT = 0.5*ms |
| 55 |
defaultclock.dt = DT |
| 56 |
|
| 57 |
# duration of a learning trial |
| 58 |
lt = 5000*DT |
| 59 |
|
| 60 |
duration = 100*lt |
| 61 |
no_input_until = 5*lt |
| 62 |
balanced_until = duration/2 |
| 63 |
|
| 64 |
# gate balanced presentation of stimulus 1 and 2 |
| 65 |
balanced = TimedArray([lt_counter*lt < balanced_until for lt_counter in range(int(duration/lt))], dt=lt) |
| 66 |
|
| 67 |
# function used for stimulus (typo in paper, +1 is not part of the argument of sin) |
| 68 |
stim_func = TimedArray([100*(np.sin(0.1*(i+1))+1) for i in range(int(duration/DT))], dt=DT) |
| 69 |
|
| 70 |
# gate learning phase of either stimulus 1 or 2 |
| 71 |
learning_phase = TimedArray([i%10 > 3 for i in range(int(duration/(0.1*lt)))], dt=0.1*lt) |
| 72 |
|
| 73 |
# if not balanced present stimulus A three times more often than stimulus B |
| 74 |
stim_A_gate = TimedArray([lt_counter % 2 == 0 if balanced(lt_counter*lt) else lt_counter % 4 in [0,1,2] |
| 75 |
for lt_counter in range(int(duration/lt))], dt=lt) |
| 76 |
|
| 77 |
stim_B_gate = TimedArray([lt_counter % 2 == 1 if balanced(lt_counter*lt) else lt_counter % 4 == 3 |
| 78 |
for lt_counter in range(int(duration/lt))], dt=lt) |
| 79 |
|
| 80 |
# noise is applied also during stimulation |
| 81 |
neurons = NeuronGroup(N_units, |
| 82 |
""" |
| 83 |
F = F_max/(1+exp(beta*(epsilon-u))) : 1 |
| 84 |
du/dt = (-u + R*(I_E - I_I + W_input*(I_stim_A + I_stim_B)))/tau_u + R*W_ext*20*sqrt((DT/ms)/ms)*xi: 1 |
| 85 |
I_E : 1 |
| 86 |
I_I : 1 |
| 87 |
index : 1 (constant) |
| 88 |
stim_units_A = index < stim_A_units_until : boolean |
| 89 |
stim_units_B = index >= (stim_B_units_from) : boolean |
| 90 |
I_stim_A = learning_phase(t)*int(stim_units_A)*stim_A_gate(t)*stim_func(t) : 1 |
| 91 |
I_stim_B = learning_phase(t)*int(stim_units_B)*stim_B_gate(t)*stim_func(t) : 1 |
| 92 |
""", |
| 93 |
method = "euler") |
| 94 |
neurons.index = range(len(neurons)) |
| 95 |
|
| 96 |
# excitatory connections with Hebbian plasticity and synaptic scaling |
| 97 |
synapses_E = Synapses(neurons, neurons, |
| 98 |
""" |
| 99 |
dw/dt = 1/tau_H*F_pre*F_post + 1/tau_SS*(F_T - F_post)*w**2 : 1 (clock-driven) |
| 100 |
I_E_post = w*F_pre : 1 (summed) |
| 101 |
""", |
| 102 |
method="euler" |
| 103 |
) |
| 104 |
# do not connect between the two populations of stimulated neurons |
| 105 |
synapses_E.connect(p=p_E, condition="((j > stim_A_units_until and i >= stim_B_units_from) or (j < stim_B_units_from and i < stim_A_units_until))" |
| 106 |
"or ((i > stim_A_units_until and i < stim_B_units_from) and (j > stim_A_units_until and j < stim_B_units_from))") |
| 107 |
|
| 108 |
# fixed weight inhibitory connections |
| 109 |
synapses_I = Synapses(neurons, neurons, |
| 110 |
""" |
| 111 |
w : 1 |
| 112 |
I_I_post = w*F_pre : 1 (summed) |
| 113 |
""" |
| 114 |
) |
| 115 |
synapses_I.connect(p=p_I) |
| 116 |
synapses_I.w = W_I |
| 117 |
|
| 118 |
statemon_neurons = StateMonitor(neurons, ["F", "I_stim_A", "I_stim_B"], record=True, dt=100*defaultclock.dt) |
| 119 |
statemon_synapses_E = StateMonitor(synapses_E, "w", record=True, dt=100*defaultclock.dt) |
| 120 |
statemon_synapses_for_assembly_analysis = StateMonitor(synapses_E, "w", record=True, dt=lt) |
| 121 |
|
| 122 |
run(duration, report="text") |
| 123 |
|
| 124 |
# threshold saying that synaptic efficacies larger than theta are |
| 125 |
# 'strong' and others are 'weak' |
| 126 |
theta = 0.5*W_max |
| 127 |
|
| 128 |
in_assembly_A = [] |
| 129 |
in_assembly_B = [] |
| 130 |
|
| 131 |
# traverse through the graph following 'strong' synapses |
| 132 |
def go(W, source, units_in_assembly): |
| 133 |
units_in_assembly.add(source) |
| 134 |
# check all possible targets |
| 135 |
for target in range(N_units): |
| 136 |
w = W[source][target] |
| 137 |
if w > theta: |
| 138 |
W[source][target] = 0 |
| 139 |
go(W, target, units_in_assembly) |
| 140 |
|
| 141 |
# for each learning trial |
| 142 |
for ws in statemon_synapses_for_assembly_analysis.w.T: |
| 143 |
|
| 144 |
# construct a full weight matrix |
| 145 |
W = np.full((N_units, N_units), np.nan) |
| 146 |
W[synapses_E.i[:], synapses_E.j[:]] = ws |
| 147 |
|
| 148 |
for in_assembly, stim_units in zip([in_assembly_A, in_assembly_B], |
| 149 |
[range(stim_A_units_until), |
| 150 |
range(stim_B_units_from, N_units)]): |
| 151 |
|
| 152 |
units_in_assembly = set() |
| 153 |
|
| 154 |
# start with units that are stimulated |
| 155 |
for stim_unit in stim_units: |
| 156 |
go(W, stim_unit, units_in_assembly) |
| 157 |
|
| 158 |
in_assembly.append(len(units_in_assembly)) |
| 159 |
|
| 160 |
# competitive development of the two competing cell assemblies A and B as a function of the input protocol |
| 161 |
fig, ax = plt.subplots() |
| 162 |
|
| 163 |
ax.plot(in_assembly_A, linestyle="None", marker='o', color='orange', label="A") |
| 164 |
ax.plot(in_assembly_B, linestyle="None", marker='o', color='olivedrab', label="B") |
| 165 |
ax.set_ylim(19, 51) |
| 166 |
ax.set_xlim(0, 100) |
| 167 |
|
| 168 |
ax.set_ylabel("Neurons in Cell Assembly [%]") |
| 169 |
ax.set_xlabel("Learning Trial") |
| 170 |
|
| 171 |
ax.axvline(balanced_until/lt, linestyle='dashed', color='k') |
| 172 |
|
| 173 |
ax.text(15, 52, " A A", color='orange', fontfamily="monospace", fontsize="xx-large") |
| 174 |
ax.text(15, 52, " B B", color='olivedrab', fontfamily="monospace", fontsize="xx-large") |
| 175 |
|
| 176 |
ax.text(65, 52, " 3A 3A", color='orange', fontfamily="monospace", fontsize="xx-large") |
| 177 |
ax.text(65, 52, " B B", color='olivedrab', fontfamily="monospace", fontsize="xx-large") |
| 178 |
|
| 179 |
plt.show() |
| 180 |
|
| 181 |
# stimulus, neuronal activity and excitatory weights as function of time |
| 182 |
fig, axes = plt.subplots(3, sharex=True) |
| 183 |
|
| 184 |
axes[0].plot(statemon_neurons.I_stim_A[0], label="A", color='orange') |
| 185 |
axes[0].plot(statemon_neurons.I_stim_B[-1], label="B", color='olivedrab') |
| 186 |
axes[0].legend(loc="upper right") |
| 187 |
axes[0].set_title("Stimulus") |
| 188 |
|
| 189 |
axes[1].imshow(statemon_neurons.F, aspect='auto') |
| 190 |
axes[1].set_title("Neuron Activity") |
| 191 |
axes[1].axhline(stim_A_units_until, linestyle='dashed', color='white') |
| 192 |
axes[1].axhline(stim_B_units_from, linestyle='dashed', color='white') |
| 193 |
|
| 194 |
axes[2].imshow(statemon_synapses_E.w, aspect='auto') |
| 195 |
axes[2].set_title("Excitatory Weights") |
| 196 |
|
| 197 |
axes[2].set_xticks(range(0, 5000, 250)) |
| 198 |
axes[2].set_xticklabels(f"{i}" for i in range(0, 100, 5)) |
| 199 |
|
| 200 |
axes[2].set_xlabel("Learning Trial") |
| 201 |
axes[2].set_xlim(0, 5000) |
| 202 |
|
| 203 |
fig.tight_layout() |
| 204 |
|
| 205 |
plt.show() |