Debian Codegraph @

examples/frompapers/Izhikevich_2007.py

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 STDP modulated with reward
5
6 Adapted from Fig. 1c of:
7
8 Eugene M. Izhikevich
9 Solving the distal reward problem through linkage of STDP and dopamine signaling.
10 Cerebral cortex 17, no. 10 (2007): 2443-2452.
11
12 Note:
13 The variable "mode" can switch the behavior of the synapse from "Classical STDP" to "Dopamine modulated STDP".
14
15 Author: Guillaume Dumas (Institut Pasteur)
16 Date: 2018-08-24
17 """
18 from brian2 import *
19
20 # Parameters
21 simulation_duration = 6 * second
22
23 ## Neurons
24 taum = 10*ms
25 Ee = 0*mV
26 vt = -54*mV
27 vr = -60*mV
28 El = -74*mV
29 taue = 5*ms
30
31 ## STDP
32 taupre = 20*ms
33 taupost = taupre
34 gmax = .01
35 dApre = .01
36 dApost = -dApre * taupre / taupost * 1.05
37 dApost *= gmax
38 dApre *= gmax
39
40 ## Dopamine signaling
41 tauc = 1000*ms
42 taud = 200*ms
43 taus = 1*ms
44 epsilon_dopa = 5e-3
45
46 # Setting the stage
47
48 ## Stimuli section
49 input_indices = array([0, 1, 0, 1, 1, 0,
50 0, 1, 0, 1, 1, 0])
51 input_times = array([ 500, 550, 1000, 1010, 1500, 1510,
52 3500, 3550, 4000, 4010, 4500, 4510])*ms
53 spike_input = SpikeGeneratorGroup(2, input_indices, input_times)
54
55 neurons = NeuronGroup(2, '''dv/dt = (ge * (Ee-v) + El - v) / taum : volt
56 dge/dt = -ge / taue : 1''',
57 threshold='v>vt', reset='v = vr',
58 method='euler')
59 neurons.v = vr
60 neurons_monitor = SpikeMonitor(neurons)
61
62 synapse = Synapses(spike_input, neurons,
63 model='''s: volt''',
64 on_pre='v += s')
65 synapse.connect(i=[0, 1], j=[0, 1])
66 synapse.s = 100. * mV
67
68 ## STDP section
69 synapse_stdp = Synapses(neurons, neurons,
70 model='''mode: 1
71 dc/dt = -c / tauc : 1 (clock-driven)
72 dd/dt = -d / taud : 1 (clock-driven)
73 ds/dt = mode * c * d / taus : 1 (clock-driven)
74 dApre/dt = -Apre / taupre : 1 (event-driven)
75 dApost/dt = -Apost / taupost : 1 (event-driven)''',
76 on_pre='''ge += s
77 Apre += dApre
78 c = clip(c + mode * Apost, -gmax, gmax)
79 s = clip(s + (1-mode) * Apost, -gmax, gmax)
80 ''',
81 on_post='''Apost += dApost
82 c = clip(c + mode * Apre, -gmax, gmax)
83 s = clip(s + (1-mode) * Apre, -gmax, gmax)
84 ''',
85 method='euler'
86 )
87 synapse_stdp.connect(i=0, j=1)
88 synapse_stdp.mode = 0
89 synapse_stdp.s = 1e-10
90 synapse_stdp.c = 1e-10
91 synapse_stdp.d = 0
92 synapse_stdp_monitor = StateMonitor(synapse_stdp, ['s', 'c', 'd'], record=[0])
93
94 ## Dopamine signaling section
95 dopamine_indices = array([0, 0, 0])
96 dopamine_times = array([3520, 4020, 4520])*ms
97 dopamine = SpikeGeneratorGroup(1, dopamine_indices, dopamine_times)
98 dopamine_monitor = SpikeMonitor(dopamine)
99 reward = Synapses(dopamine, synapse_stdp, model='''''',
100 on_pre='''d_post += epsilon_dopa''',
101 method='exact')
102 reward.connect()
103
104 # Simulation
105 ## Classical STDP
106 synapse_stdp.mode = 0
107 run(simulation_duration/2)
108 ## Dopamine modulated STDP
109 synapse_stdp.mode = 1
110 run(simulation_duration/2)
111
112 # Visualisation
113 dopamine_indices, dopamine_times = dopamine_monitor.it
114 neurons_indices, neurons_times = neurons_monitor.it
115 figure(figsize=(12, 6))
116 subplot(411)
117 plot([0.05, 2.95], [2.7, 2.7], linewidth=5, color='k')
118 text(1.5, 3, 'Classical STDP', horizontalalignment='center', fontsize=20)
119 plot([3.05, 5.95], [2.7, 2.7], linewidth=5, color='k')
120 text(4.5, 3, 'Dopamine modulated STDP', horizontalalignment='center', fontsize=20)
121 plot(neurons_times, neurons_indices, 'ob')
122 plot(dopamine_times, dopamine_indices + 2, 'or')
123 xlim([0, simulation_duration/second])
124 ylim([-0.5, 4])
125 yticks([0, 1, 2], ['Pre-neuron', 'Post-neuron', 'Reward'])
126 xticks([])
127 subplot(412)
128 plot(synapse_stdp_monitor.t/second, synapse_stdp_monitor.d.T/gmax, 'r-')
129 xlim([0, simulation_duration/second])
130 ylabel('Extracellular\ndopamine d(t)')
131 xticks([])
132 subplot(413)
133 plot(synapse_stdp_monitor.t/second, synapse_stdp_monitor.c.T/gmax, 'b-')
134 xlim([0, simulation_duration/second])
135 ylabel('Eligibility\ntrace c(t)')
136 xticks([])
137 subplot(414)
138 plot(synapse_stdp_monitor.t/second, synapse_stdp_monitor.s.T/gmax, 'g-')
139 xlim([0, simulation_duration/second])
140 ylabel('Synaptic\nstrength s(t)')
141 xlabel('Time (s)')
142 tight_layout()
143 show()