Debian Codegraph @

examples/synapses/STDP.py

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