Debian Codegraph @

examples/frompapers/Clopath_et_al_2010_homeostasis.py

raw
1 #!/usr/bin/env python
2 """
3 This code contains an adapted version of the voltage-dependent triplet STDP rule from:
4 Clopath et al., Connectivity reflects coding: a model of voltage-based STDP with homeostasis, Nature Neuroscience, 2010
5 (http://dx.doi.org/10.1038/nn.2479)
6
7 The plasticity rule is adapted for a leaky integrate & fire model in Brian2.
8 More specifically, the filters ``v_lowpass1`` and ``v_lowpass2`` are
9 incremented by a constant at every post-synaptic spike time, to
10 compensate for the lack of an actual spike in the integrate & fire model.
11
12 As an illustration of the rule, we simulate the competition between
13 inputs projecting on a downstream neuron. We would like to note that the
14 parameters have been chosen arbitrarily to qualitatively reproduce the
15 behavior of the original work, but need additional fitting.
16
17 We kindly ask to cite the article when using the model presented below.
18
19 This code was written by Jacopo Bono, 12/2015
20 """
21 from brian2 import *
22
23 ################################################################################
24 # PLASTICITY MODEL
25 ################################################################################
26
27 #### Plasticity Parameters
28
29 V_rest = -70.*mV # resting potential
30 V_thresh = -55.*mV # spiking threshold
31 Theta_low = V_rest # depolarization threshold for plasticity
32 x_reset = 1. # spike trace reset value
33 taux = 15.*ms # spike trace time constant
34 A_LTD = 1.5e-4 # depression amplitude
35 A_LTP = 1.5e-2 # potentiation amplitude
36 tau_lowpass1 = 40*ms # timeconstant for low-pass filtered voltage
37 tau_lowpass2 = 30*ms # timeconstant for low-pass filtered voltage
38 tau_homeo = 1000*ms # homeostatic timeconstant
39 v_target = 12*mV**2 # target depolarisation
40
41 #### Plasticity Equations
42
43 # equations executed at every timestepC
44 Syn_model = ('''
45 w_ampa:1 # synaptic weight (ampa synapse)
46 ''')
47
48 # equations executed only when a presynaptic spike occurs
49 Pre_eq = ('''
50 g_ampa_post += w_ampa*ampa_max_cond # increment synaptic conductance
51 A_LTD_u = A_LTD*(v_homeo**2/v_target) # metaplasticity
52 w_minus = A_LTD_u*(v_lowpass1_post/mV - Theta_low/mV)*int(v_lowpass1_post/mV - Theta_low/mV > 0) # synaptic depression
53 w_ampa = clip(w_ampa-w_minus, 0, w_max) # hard bounds
54 ''' )
55
56 # equations executed only when a postsynaptic spike occurs
57 Post_eq = ('''
58 v_lowpass1 += 10*mV # mimics the depolarisation effect due to a spike
59 v_lowpass2 += 10*mV # mimics the depolarisation effect due to a spike
60 v_homeo += 0.1*mV # mimics the depolarisation effect due to a spike
61 w_plus = A_LTP*x_trace_pre*(v_lowpass2_post/mV - Theta_low/mV)*int(v_lowpass2_post/mV - Theta_low/mV > 0) # synaptic potentiation
62 w_ampa = clip(w_ampa+w_plus, 0, w_max) # hard bounds
63 ''' )
64
65 ################################################################################
66 # I&F Parameters and equations
67 ################################################################################
68
69 #### Neuron parameters
70
71 gleak = 30.*nS # leak conductance
72 C = 300.*pF # membrane capacitance
73 tau_AMPA = 2.*ms # AMPA synaptic timeconstant
74 E_AMPA = 0.*mV # reversal potential AMPA
75
76 ampa_max_cond = 5.e-8*siemens # Ampa maximal conductance
77 w_max = 1. # maximal ampa weight
78
79 #### Neuron Equations
80
81 # We connect 10 presynaptic neurons to 1 downstream neuron
82
83 # downstream neuron
84 eqs_neurons = '''
85 dv/dt = (gleak*(V_rest-v) + I_ext + I_syn)/C: volt # voltage
86 dv_lowpass1/dt = (v-v_lowpass1)/tau_lowpass1 : volt # low-pass filter of the voltage
87 dv_lowpass2/dt = (v-v_lowpass2)/tau_lowpass2 : volt # low-pass filter of the voltage
88 dv_homeo/dt = (v-V_rest-v_homeo)/tau_homeo : volt # low-pass filter of the voltage
89 I_ext : amp # external current
90 I_syn = g_ampa*(E_AMPA-v): amp # synaptic current
91 dg_ampa/dt = -g_ampa/tau_AMPA : siemens # synaptic conductance
92 dx_trace/dt = -x_trace/taux :1 # spike trace
93 '''
94
95 # input neurons
96 eqs_inputs = '''
97 dv/dt = gleak*(V_rest-v)/C: volt # voltage
98 dx_trace/dt = -x_trace/taux :1 # spike trace
99 rates : Hz # input rates
100 selected_index : integer (shared) # active neuron
101 '''
102
103 ################################################################################
104 # Simulation
105 ################################################################################
106
107 #### Parameters
108
109 defaultclock.dt = 500.*us # timestep
110 Nr_neurons = 1 # Number of downstream neurons
111 Nr_inputs = 5 # Number of input neurons
112 input_rate = 35*Hz # Rates
113 init_weight = 0.5 # initial synaptic weight
114 final_t = 20.*second # end of simulation
115 input_time = 100.*ms # duration of an input
116
117 #### Create neuron objects
118
119 Nrn_downstream = NeuronGroup(Nr_neurons, eqs_neurons, threshold='v>V_thresh',
120 reset='v=V_rest;x_trace+=x_reset/(taux/ms)',
121 method='euler')
122 Nrns_input = NeuronGroup(Nr_inputs, eqs_inputs, threshold='rand()<rates*dt',
123 reset='v=V_rest;x_trace+=x_reset/(taux/ms)',
124 method='exact')
125
126 #### create Synapses
127
128 Syn = Synapses(Nrns_input, Nrn_downstream,
129 model=Syn_model,
130 on_pre=Pre_eq,
131 on_post=Post_eq
132 )
133
134 Syn.connect(i=numpy.arange(Nr_inputs), j=0)
135
136 #### Monitors and storage
137 W_evolution = StateMonitor(Syn, 'w_ampa', record=True)
138
139 #### Run
140
141 # Initial values
142 Nrn_downstream.v = V_rest
143 Nrn_downstream.v_lowpass1 = V_rest
144 Nrn_downstream.v_lowpass2 = V_rest
145 Nrn_downstream.v_homeo = 0
146 Nrn_downstream.I_ext = 0.*amp
147 Nrn_downstream.x_trace = 0.
148 Nrns_input.v = V_rest
149 Nrns_input.x_trace = 0.
150 Syn.w_ampa = init_weight
151
152 # Switch on a different input every 100ms
153 Nrns_input.run_regularly('''
154 selected_index = int(floor(rand()*Nr_inputs))
155 rates = input_rate * int(selected_index == i) # All rates are zero except for the selected neuron
156 ''', dt=input_time)
157 run(final_t, report='text')
158
159 ################################################################################
160 # Plots
161 ################################################################################
162 stitle = 'Synaptic Competition'
163
164 fig = figure(figsize=(8, 5))
165 for kk in range(Nr_inputs):
166 plt.plot(W_evolution.t, W_evolution.w_ampa[kk], '-', linewidth=2)
167 xlabel('Time [ms]', fontsize=22)
168 ylabel('Weight [a.u.]', fontsize=22)
169 plt.subplots_adjust(bottom=0.2, left=0.15, right=0.95, top=0.85)
170 title(stitle, fontsize=22)
171 plt.show()