Debian Codegraph @

examples/frompapers/Stimberg_et_al_2018/example_1_COBA.py

raw
1 # coding=utf-8
2 """
3 Modeling neuron-glia interactions with the Brian 2 simulator
4 Marcel Stimberg, Dan F. M. Goodman, Romain Brette, Maurizio De Pittà
5 bioRxiv 198366; doi: https://doi.org/10.1101/198366
6
7 Figure 1: Modeling of neurons and synapses.
8
9 Randomly connected networks with conductance-based synapses (COBA; see Brunel,
10 2000). Synapses exhibit short-time plasticity (Tsodyks, 2005; Tsodyks et al.,
11 1998).
12 """
13 from brian2 import *
14 import sympy
15
16 import plot_utils as pu
17
18 seed(11922) # to get identical figures for repeated runs
19
20 ################################################################################
21 # Model parameters
22 ################################################################################
23 ### General parameters
24 duration = 1.0*second # Total simulation time
25 sim_dt = 0.1*ms # Integrator/sampling step
26 N_e = 3200 # Number of excitatory neurons
27 N_i = 800 # Number of inhibitory neurons
28
29 ### Neuron parameters
30 E_l = -60*mV # Leak reversal potential
31 g_l = 9.99*nS # Leak conductance
32 E_e = 0*mV # Excitatory synaptic reversal potential
33 E_i = -80*mV # Inhibitory synaptic reversal potential
34 C_m = 198*pF # Membrane capacitance
35 tau_e = 5*ms # Excitatory synaptic time constant
36 tau_i = 10*ms # Inhibitory synaptic time constant
37 tau_r = 5*ms # Refractory period
38 I_ex = 150*pA # External current
39 V_th = -50*mV # Firing threshold
40 V_r = E_l # Reset potential
41
42 ### Synapse parameters
43 w_e = 0.05*nS # Excitatory synaptic conductance
44 w_i = 1.0*nS # Inhibitory synaptic conductance
45 U_0 = 0.6 # Synaptic release probability at rest
46 Omega_d = 2.0/second # Synaptic depression rate
47 Omega_f = 3.33/second # Synaptic facilitation rate
48
49 ################################################################################
50 # Model definition
51 ################################################################################
52 # Set the integration time (in this case not strictly necessary, since we are
53 # using the default value)
54 defaultclock.dt = sim_dt
55
56 ### Neurons
57 neuron_eqs = '''
58 dv/dt = (g_l*(E_l-v) + g_e*(E_e-v) + g_i*(E_i-v) +
59 I_ex)/C_m : volt (unless refractory)
60 dg_e/dt = -g_e/tau_e : siemens # post-synaptic exc. conductance
61 dg_i/dt = -g_i/tau_i : siemens # post-synaptic inh. conductance
62 '''
63 neurons = NeuronGroup(N_e + N_i, model=neuron_eqs,
64 threshold='v>V_th', reset='v=V_r',
65 refractory='tau_r', method='euler')
66 # Random initial membrane potential values and conductances
67 neurons.v = 'E_l + rand()*(V_th-E_l)'
68 neurons.g_e = 'rand()*w_e'
69 neurons.g_i = 'rand()*w_i'
70 exc_neurons = neurons[:N_e]
71 inh_neurons = neurons[N_e:]
72
73 ### Synapses
74 synapses_eqs = '''
75 # Usage of releasable neurotransmitter per single action potential:
76 du_S/dt = -Omega_f * u_S : 1 (event-driven)
77 # Fraction of synaptic neurotransmitter resources available:
78 dx_S/dt = Omega_d *(1 - x_S) : 1 (event-driven)
79 '''
80 synapses_action = '''
81 u_S += U_0 * (1 - u_S)
82 r_S = u_S * x_S
83 x_S -= r_S
84 '''
85 exc_syn = Synapses(exc_neurons, neurons, model=synapses_eqs,
86 on_pre=synapses_action+'g_e_post += w_e*r_S')
87 inh_syn = Synapses(inh_neurons, neurons, model=synapses_eqs,
88 on_pre=synapses_action+'g_i_post += w_i*r_S')
89
90 exc_syn.connect(p=0.05)
91 inh_syn.connect(p=0.2)
92 # Start from "resting" condition: all synapses have fully-replenished
93 # neurotransmitter resources
94 exc_syn.x_S = 1
95 inh_syn.x_S = 1
96
97 # ##############################################################################
98 # # Monitors
99 # ##############################################################################
100 # Note that we could use a single monitor for all neurons instead, but in this
101 # way plotting is a bit easier in the end
102 exc_mon = SpikeMonitor(exc_neurons)
103 inh_mon = SpikeMonitor(inh_neurons)
104
105 ### We record some additional data from a single excitatory neuron
106 ni = 50
107 # Record conductances and membrane potential of neuron ni
108 state_mon = StateMonitor(exc_neurons, ['v', 'g_e', 'g_i'], record=ni)
109 # We make sure to monitor synaptic variables after synapse are updated in order
110 # to use simple recurrence relations to reconstruct them. Record all synapses
111 # originating from neuron ni
112 synapse_mon = StateMonitor(exc_syn, ['u_S', 'x_S'],
113 record=exc_syn[ni, :], when='after_synapses')
114
115 # ##############################################################################
116 # # Simulation run
117 # ##############################################################################
118 run(duration, report='text')
119
120 ################################################################################
121 # Analysis and plotting
122 ################################################################################
123 plt.style.use('figures.mplstyle')
124
125 ### Spiking activity (w/ rate)
126 fig1, ax = plt.subplots(nrows=2, ncols=1, sharex=False,
127 gridspec_kw={'height_ratios': [3, 1],
128 'left': 0.18, 'bottom': 0.18, 'top': 0.95,
129 'hspace': 0.1},
130 figsize=(3.07, 3.07))
131 ax[0].plot(exc_mon.t[exc_mon.i <= N_e//4]/ms,
132 exc_mon.i[exc_mon.i <= N_e//4], '|', color='C0')
133 ax[0].plot(inh_mon.t[inh_mon.i <= N_i//4]/ms,
134 inh_mon.i[inh_mon.i <= N_i//4]+N_e//4, '|', color='C1')
135 pu.adjust_spines(ax[0], ['left'])
136 ax[0].set(xlim=(0., duration/ms), ylim=(0, (N_e+N_i)//4), ylabel='neuron index')
137
138 # Generate frequencies
139 bin_size = 1*ms
140 spk_count, bin_edges = np.histogram(np.r_[exc_mon.t/ms, inh_mon.t/ms],
141 int(duration/ms))
142 rate = double(spk_count)/(N_e + N_i)/bin_size/Hz
143 ax[1].plot(bin_edges[:-1], rate, '-', color='k')
144 pu.adjust_spines(ax[1], ['left', 'bottom'])
145 ax[1].set(xlim=(0., duration/ms), ylim=(0, 10.),
146 xlabel='time (ms)', ylabel='rate (Hz)')
147 pu.adjust_ylabels(ax, x_offset=-0.18)
148
149 ### Dynamics of a single neuron
150 fig2, ax = plt.subplots(4, sharex=False,
151 gridspec_kw={'left': 0.27, 'bottom': 0.18, 'top': 0.95,
152 'hspace': 0.2},
153 figsize=(3.07, 3.07))
154 ### Postsynaptic conductances
155 ax[0].plot(state_mon.t/ms, state_mon.g_e[0]/nS, color='C0')
156 ax[0].plot(state_mon.t/ms, -state_mon.g_i[0]/nS, color='C1')
157 ax[0].plot([state_mon.t[0]/ms, state_mon.t[-1]/ms], [0, 0], color='grey',
158 linestyle=':')
159 # Adjust axis
160 pu.adjust_spines(ax[0], ['left'])
161 ax[0].set(xlim=(0., duration/ms), ylim=(-5.0, 0.25),
162 ylabel=f"postsyn.\nconduct.\n(${sympy.latex(nS)}$)")
163
164 ### Membrane potential
165 ax[1].axhline(V_th/mV, color='C2', linestyle=':') # Threshold
166 # Artificially insert spikes
167 ax[1].plot(state_mon.t/ms, state_mon.v[0]/mV, color='black')
168 ax[1].vlines(exc_mon.t[exc_mon.i == ni]/ms, V_th/mV, 0, color='black')
169 pu.adjust_spines(ax[1], ['left'])
170 ax[1].set(xlim=(0., duration/ms), ylim=(-1+V_r/mV, 0.),
171 ylabel=f"membrane\npotential\n(${sympy.latex(mV)}$)")
172
173 ### Synaptic variables
174 # Retrieves indexes of spikes in the synaptic monitor using the fact that we
175 # are sampling spikes and synaptic variables by the same dt
176 spk_index = np.in1d(synapse_mon.t, exc_mon.t[exc_mon.i == ni])
177 ax[2].plot(synapse_mon.t[spk_index]/ms, synapse_mon.x_S[0][spk_index], '.',
178 ms=4, color='C3')
179 ax[2].plot(synapse_mon.t[spk_index]/ms, synapse_mon.u_S[0][spk_index], '.',
180 ms=4, color='C4')
181 # Super-impose reconstructed solutions
182 time = synapse_mon.t # time vector
183 tspk = Quantity(synapse_mon.t, copy=True) # Spike times
184 for ts in exc_mon.t[exc_mon.i == ni]:
185 tspk[time >= ts] = ts
186 ax[2].plot(synapse_mon.t/ms, 1 + (synapse_mon.x_S[0]-1)*exp(-(time-tspk)*Omega_d),
187 '-', color='C3')
188 ax[2].plot(synapse_mon.t/ms, synapse_mon.u_S[0]*exp(-(time-tspk)*Omega_f),
189 '-', color='C4')
190 # Adjust axis
191 pu.adjust_spines(ax[2], ['left'])
192 ax[2].set(xlim=(0., duration/ms), ylim=(-0.05, 1.05),
193 ylabel='synaptic\nvariables\n$u_S,\,x_S$')
194
195 nspikes = np.sum(spk_index)
196 x_S_spike = synapse_mon.x_S[0][spk_index]
197 u_S_spike = synapse_mon.u_S[0][spk_index]
198 ax[3].vlines(synapse_mon.t[spk_index]/ms, np.zeros(nspikes),
199 x_S_spike*u_S_spike/(1-u_S_spike))
200 pu.adjust_spines(ax[3], ['left', 'bottom'])
201 ax[3].set(xlim=(0., duration/ms), ylim=(-0.01, 0.62),
202 yticks=np.arange(0, 0.62, 0.2), xlabel='time (ms)', ylabel='$r_S$')
203
204 pu.adjust_ylabels(ax, x_offset=-0.20)
205
206
207 plt.show()