| 1 |
#!/usr/bin/env python |
| 2 |
""" |
| 3 |
Spike-timing dependent plasticity. |
| 4 |
Adapted from Song, Miller and Abbott (2000) and Song and Abbott (2001). |
| 5 |
|
| 6 |
This example is modified from ``synapses_STDP.py`` and writes a standalone |
| 7 |
C++ project in the directory ``STDP_standalone``. |
| 8 |
""" |
| 9 |
from brian2 import * |
| 10 |
|
| 11 |
set_device('cpp_standalone', directory='STDP_standalone') |
| 12 |
|
| 13 |
N = 1000 |
| 14 |
taum = 10*ms |
| 15 |
taupre = 20*ms |
| 16 |
taupost = taupre |
| 17 |
Ee = 0*mV |
| 18 |
vt = -54*mV |
| 19 |
vr = -60*mV |
| 20 |
El = -74*mV |
| 21 |
taue = 5*ms |
| 22 |
F = 15*Hz |
| 23 |
gmax = .01 |
| 24 |
dApre = .01 |
| 25 |
dApost = -dApre * taupre / taupost * 1.05 |
| 26 |
dApost *= gmax |
| 27 |
dApre *= gmax |
| 28 |
|
| 29 |
eqs_neurons = ''' |
| 30 |
dv/dt = (ge * (Ee-v) + El - v) / taum : volt |
| 31 |
dge/dt = -ge / taue : 1 |
| 32 |
''' |
| 33 |
|
| 34 |
input = PoissonGroup(N, rates=F) |
| 35 |
neurons = NeuronGroup(1, eqs_neurons, threshold='v>vt', reset='v = vr', |
| 36 |
method='euler') |
| 37 |
S = Synapses(input, neurons, |
| 38 |
'''w : 1 |
| 39 |
dApre/dt = -Apre / taupre : 1 (event-driven) |
| 40 |
dApost/dt = -Apost / taupost : 1 (event-driven)''', |
| 41 |
on_pre='''ge += w |
| 42 |
Apre += dApre |
| 43 |
w = clip(w + Apost, 0, gmax)''', |
| 44 |
on_post='''Apost += dApost |
| 45 |
w = clip(w + Apre, 0, gmax)''', |
| 46 |
) |
| 47 |
S.connect() |
| 48 |
S.w = 'rand() * gmax' |
| 49 |
mon = StateMonitor(S, 'w', record=[0, 1]) |
| 50 |
s_mon = SpikeMonitor(input) |
| 51 |
|
| 52 |
run(100*second, report='text') |
| 53 |
|
| 54 |
subplot(311) |
| 55 |
plot(S.w / gmax, '.k') |
| 56 |
ylabel('Weight / gmax') |
| 57 |
xlabel('Synapse index') |
| 58 |
subplot(312) |
| 59 |
hist(S.w / gmax, 20) |
| 60 |
xlabel('Weight / gmax') |
| 61 |
subplot(313) |
| 62 |
plot(mon.t/second, mon.w.T/gmax) |
| 63 |
xlabel('Time (s)') |
| 64 |
ylabel('Weight / gmax') |
| 65 |
tight_layout() |
| 66 |
show() |