| 1 |
#!/usr/bin/env python3 |
| 2 |
""" |
| 3 |
Fig. 2 C, panel DP from: |
| 4 |
|
| 5 |
Calcium-based plasticity model explains sensitivity of synaptic changes |
| 6 |
to spike pattern, rate, and dendritic location |
| 7 |
|
| 8 |
PNAS 109 (10): 3991-3996 (2012) |
| 9 |
https://doi.org/10.1073/pnas.1109359109 |
| 10 |
|
| 11 |
by Graupner M. and Brunel N. (2012) |
| 12 |
|
| 13 |
For the noise term see corrections https://www.pnas.org/doi/10.1073/pnas.1220044110. |
| 14 |
|
| 15 |
For the original implementations see https://github.com/mgraupe/CalciumBasedPlasticityModel/tree/main/Graupner2012PNAS. |
| 16 |
|
| 17 |
Sebastian Schmitt, 2022 |
| 18 |
""" |
| 19 |
import multiprocessing |
| 20 |
|
| 21 |
import numpy as np |
| 22 |
import matplotlib.pyplot as plt |
| 23 |
|
| 24 |
from brian2 import NeuronGroup, Synapses |
| 25 |
from brian2 import ms, second |
| 26 |
from brian2 import run |
| 27 |
|
| 28 |
# number of time differences in STDP plot |
| 29 |
POINTS = 41 |
| 30 |
|
| 31 |
# maximal time difference |
| 32 |
STDP_DT_MAX = 100 * ms |
| 33 |
|
| 34 |
# (symmetric) minimal time difference |
| 35 |
STDP_DT_MIN = -STDP_DT_MAX |
| 36 |
|
| 37 |
# number of repetitions |
| 38 |
REPETITIONS = 1000 |
| 39 |
|
| 40 |
# time difference step size |
| 41 |
STDP_DT_STEP = (STDP_DT_MAX - STDP_DT_MIN) / (POINTS - 1) |
| 42 |
|
| 43 |
|
| 44 |
def run_sim(point_index): |
| 45 |
"""Run simulation for one STDP time difference""" |
| 46 |
|
| 47 |
# Cf. https://brian2.readthedocs.io/en/stable/resources/tutorials/2-intro-to-brian-synapses.html#more-complex-synapse-models-stdp |
| 48 |
# set up two groups of neurons, G spikes at fixed times starting from STDP_DT_MAX |
| 49 |
# H spikes shifted according to point_index and has as many neurons as REPETITIONS*2 |
| 50 |
# (we need to multiply by 2 for both initial states (UP and DOWN)) |
| 51 |
# G: | |
| 52 |
# H: | |
| 53 |
# H: | |
| 54 |
# H: | |
| 55 |
# ... |
| 56 |
G = NeuronGroup(1, "", threshold=f"t>{STDP_DT_MAX/ms}*ms", refractory=1 * second) |
| 57 |
H = NeuronGroup( |
| 58 |
REPETITIONS * 2, "tspike:second", threshold="t>tspike", refractory=1 * second |
| 59 |
) |
| 60 |
H.tspike = [point_index * STDP_DT_STEP] * REPETITIONS * 2 |
| 61 |
|
| 62 |
synapses_eqs = """ |
| 63 |
tau : second (constant, shared) |
| 64 |
rho_star : 1 (constant, shared) |
| 65 |
gamma_p : 1 (constant, shared) |
| 66 |
theta_p : 1 (constant, shared) |
| 67 |
gamma_d : 1 (constant, shared) |
| 68 |
theta_d : 1 (constant, shared) |
| 69 |
drho/dt = (-rho*(1-rho)*(rho_star-rho) |
| 70 |
+ gamma_p*(1-rho)*int((c - theta_p) > 0) |
| 71 |
- gamma_d*rho*int((c-theta_d) > 0) |
| 72 |
+ sigma*sqrt(tau)*sqrt(int((c-theta_d) > 0) + int((c-theta_p) > 0))*xi |
| 73 |
) / tau : 1 (clock-driven) |
| 74 |
dc/dt = -c/tau_Ca : 1 (clock-driven) |
| 75 |
tau_Ca : second (constant, shared) |
| 76 |
sigma : 1 (constant, shared) |
| 77 |
""" |
| 78 |
|
| 79 |
C_pre = 1 |
| 80 |
C_post = 2 |
| 81 |
D = 13.7 * ms |
| 82 |
|
| 83 |
synapses = Synapses( |
| 84 |
G, |
| 85 |
H, |
| 86 |
model=synapses_eqs, |
| 87 |
on_pre="c += C_pre", |
| 88 |
on_post="c += C_post", |
| 89 |
delay=D, |
| 90 |
method="heun", |
| 91 |
) |
| 92 |
|
| 93 |
synapses.connect() |
| 94 |
|
| 95 |
synapses.tau_Ca = 20 * ms |
| 96 |
synapses.theta_d = 1 |
| 97 |
synapses.theta_p = 1.3 |
| 98 |
synapses.gamma_d = 200 |
| 99 |
synapses.gamma_p = 321.808 |
| 100 |
synapses.sigma = 2.8284 |
| 101 |
synapses.tau = 150 * second |
| 102 |
synapses.rho_star = 0.5 |
| 103 |
|
| 104 |
# start with equal number of synapses in DOWN and UP state |
| 105 |
# must match b in analysis below |
| 106 |
rho_initial = np.array([0] * REPETITIONS + [1] * REPETITIONS) |
| 107 |
synapses.rho = rho_initial |
| 108 |
|
| 109 |
def report_callback(elapsed, completed, start, duration): |
| 110 |
print( |
| 111 |
f"time difference {(point_index*STDP_DT_STEP - STDP_DT_MAX)/ms:.0f} ms is {completed:2.0%} done" |
| 112 |
) |
| 113 |
|
| 114 |
run(60 * second, report=report_callback) |
| 115 |
|
| 116 |
return synapses.rho[:], rho_initial |
| 117 |
|
| 118 |
|
| 119 |
if __name__ == "__main__": |
| 120 |
|
| 121 |
with multiprocessing.Pool() as p: |
| 122 |
results = p.map(run_sim, range(POINTS)) |
| 123 |
|
| 124 |
# initial fraction of synapses in DOWN state |
| 125 |
beta = 0.5 |
| 126 |
|
| 127 |
# ratio of UP and DOWN state weights (w1/w0) |
| 128 |
b = 5 |
| 129 |
|
| 130 |
change_in_syn_strengths = [] |
| 131 |
|
| 132 |
for rhos, rhos_initial in results: |
| 133 |
|
| 134 |
# average switching probabilities |
| 135 |
U = np.mean(rhos[rhos_initial < 0.5] > 0.5) |
| 136 |
D = np.mean(rhos[rhos_initial > 0.5] < 0.5) |
| 137 |
|
| 138 |
change_in_syn_strength = ( |
| 139 |
(1 - U) * beta + D * (1 - beta) + b * (U * beta + (1 - D) * (1 - beta)) |
| 140 |
) / (beta + (1 - beta) * b) |
| 141 |
|
| 142 |
change_in_syn_strengths.append(change_in_syn_strength) |
| 143 |
|
| 144 |
stdp_dts = [ |
| 145 |
point_index * STDP_DT_STEP - STDP_DT_MAX for point_index in range(POINTS) |
| 146 |
] |
| 147 |
|
| 148 |
plt.axvline(0, linestyle="dashed", color="k") |
| 149 |
plt.axhline(1, linestyle="dashed", color="k") |
| 150 |
plt.plot(stdp_dts / ms, change_in_syn_strengths, marker="o", linestyle="None") |
| 151 |
plt.xlim( |
| 152 |
(STDP_DT_MIN - STDP_DT_STEP / 2) / ms, (STDP_DT_MAX + STDP_DT_STEP / 2) / ms |
| 153 |
) |
| 154 |
plt.ylim(0.3, 1.7) |
| 155 |
plt.xlabel(r"time difference $\Delta$t (ms)") |
| 156 |
plt.ylabel("change in synaptic strength (after/before)") |
| 157 |
plt.show() |