Malte J. Rasch
Goal of tutorial
Writing scripts
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Writing scripts
Usage of array notation
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Writing scripts
Usage of array notation
How to integrate ODEs
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Writing scripts
Usage of array notation
How to integrate ODEs
How to plot results
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Writing scripts
Usage of array notation
How to integrate ODEs
How to plot results
How to simulate neurons and synapses
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Writing scripts
Usage of array notation
How to integrate ODEs
How to plot results
How to simulate neurons and synapses
How to program a quite realistic network simulation
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Result plots
A single qIF neuron A single qIF neuron
with current step input with 100 Poisson inputs
40 40
Membrane voltage [mV]
600 600
400 400
200 200
0 0
0 200 400 600 800 1000 0 200 400 600 800 1000
Time [ms] Time [ms]
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
dVm 1 X
Cm = − (Vm − VL ) − gi (t)(Vm − Ei ) + I
dt Rm
i
Including non-linear dynamics of many channels in gi (t)
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
dVm 1 X
Cm = − (Vm − VL ) − gi (t)(Vm − Ei ) + I
dt Rm
i
Including non-linear dynamics of many channels in gi (t)
if v < 35 :
v̇ = (0.04v + 5) v + 150 − u − I
u̇ = a (b v − u)
if v ≥ 35 :
v ←c
u ←u+d
With b = 0.2, c = −65, and d = 8, a = 0.02 for excitatory neurons and d = 2, a = 0.1 for
inhibitory neurons.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Neuron model
peak 30 mV
RZ RS
v'= 0.04v 2+5v +140 - u + I LTS,TC
8
parameter d
0.25
parameter b
u'= a(bv - u)
reset c IB
RS,IB,CH FS 4
v(t) 0.2
if v = 30 mV, de
cay FS,LTS,RZ CH
reset d with r 2
then v c, u u + d ate a
0.05 TC
u(t)
sensitivity b 0 0.02 0.1 -65 -55 -50
parameter a parameter c
regular spiking (RS) intrinsically bursting (IB) chattering (CH) fast spiking (FS)
v(t)
I(t)
20 mV
40 ms
-63 mV
-87 mV
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 1
Simulate one excitatory neuron for 1000ms and plot the resulting voltage
trace. Apply a current step (Iapp = 7pA) between time 200ms and 700ms.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 1
Simulate one excitatory neuron for 1000ms and plot the resulting voltage
trace. Apply a current step (Iapp = 7pA) between time 200ms and 700ms.
Neuron model:
A single qIF neuron
if v < 35 : with current step input
40
if v ≥ 35 : −20
−40
v ←c
−60
u ←u+d −80
0 200 400 600 800 1000
Time [ms]
with d = 8, a = 0.02, b = 0.2, c = −65
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
3 Loop over T − 1 time steps and do for each step t
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
3 Loop over T − 1 time steps and do for each step t
1 set Iapp ← 7 if t∆t is between 200 and 700 (otherwise 0)
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
3 Loop over T − 1 time steps and do for each step t
1 set Iapp ← 7 if t∆t is between 200 and 700 (otherwise 0)
2 if vt < 35: update element t + 1 of v and u according to
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
3 Loop over T − 1 time steps and do for each step t
1 set Iapp ← 7 if t∆t is between 200 and 700 (otherwise 0)
2 if vt < 35: update element t + 1 of v and u according to
Step 1 in detail:
Open Spyder and create a new file (script) that will simulate the neuron. Import the
necessary modules (from pylab import *)
Proceed as follows:
1 Initialize parameter values (∆t = 0.5ms, a = 0.02, d = 8, · · · )
2 Reserve memory for voltage trace v and u (of length T = 1000/∆t) and set first
element to −70 and −14, respectively.
3 Loop over T − 1 time steps and do for each step t
1 set Iapp ← 7 if t∆t is between 200 and 700 (otherwise 0)
2 if vt < 35: update element t + 1 of v and u according to
Synapse model
where wj is the weight of the jth synapse and Ej its reversal potential (for
instance 0 mV for excitatory and −85 mV for inhibitory synapses).
Variable sj implements the dynamics of the jth synapse:
Synapse model
where wj is the weight of the jth synapse and Ej its reversal potential (for
instance 0 mV for excitatory and −85 mV for inhibitory synapses).
Variable sj implements the dynamics of the jth synapse:
sj ← sj + hj , hj ← 1 − (1 + (U − 1)hj )e −∆tj τd ,
with e.g. U = 0.5, τd = 500ms. ∆tj is the interval between current and previous spike of
neuron j.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 2
Simulate the neuron model for 1000ms and plot the resulting voltage trace.
Assume that 100 synapses are attached to the neuron, with each pre-synaptic
neuron firing with a Poisson process of rate frate = 2 Hz between time 200ms
and 700ms.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 2
Simulate the neuron model for 1000ms and plot the resulting voltage trace.
Assume that 100 synapses are attached to the neuron, with each pre-synaptic
neuron firing with a Poisson process of rate frate = 2 Hz between time 200ms
and 700ms.
Step 2 in detail:
Use the last script, save it under a new file name, and add the necessary lines.
Proceed as follows:
1 Initialize new parameter values (τs = 10, frate = 0.002ms−1 )
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 2 in detail:
Use the last script, save it under a new file name, and add the necessary lines.
Proceed as follows:
1 Initialize new parameter values (τs = 10, frate = 0.002ms−1 )
2 Reserve memory and initialize the vectors sin = (sjin ), win = (wjin ), and E = (Ej )
with nin = 100 constant elements (same values as in Step 1)
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 2 in detail:
Use the last script, save it under a new file name, and add the necessary lines.
Proceed as follows:
1 Initialize new parameter values (τs = 10, frate = 0.002ms−1 )
2 Reserve memory and initialize the vectors sin = (sjin ), win = (wjin ), and E = (Ej )
with nin = 100 constant elements (same values as in Step 1)
3 Inside the for-loop change/add the following:
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 2 in detail:
Use the last script, save it under a new file name, and add the necessary lines.
Proceed as follows:
1 Initialize new parameter values (τs = 10, frate = 0.002ms−1 )
2 Reserve memory and initialize the vectors sin = (sjin ), win = (wjin ), and E = (Ej )
with nin = 100 constant elements (same values as in Step 1)
3 Inside the for-loop change/add the following:
1 Set pj = 1 if rj ≤ frate ∆t (otherwise 0) during times of applied input. rj is an
uniform random number between 0 and 1. Use array notation to set the
input for all nin input synapses. Hint
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 2 in detail:
Use the last script, save it under a new file name, and add the necessary lines.
Proceed as follows:
1 Initialize new parameter values (τs = 10, frate = 0.002ms−1 )
2 Reserve memory and initialize the vectors sin = (sjin ), win = (wjin ), and E = (Ej )
with nin = 100 constant elements (same values as in Step 1)
3 Inside the for-loop change/add the following:
1 Set pj = 1 if rj ≤ frate ∆t (otherwise 0) during times of applied input. rj is an
uniform random number between 0 and 1. Use array notation to set the
input for all nin input synapses. Hint
2 before the vt update: Implement the conductance dynamics s and set Iapp
according to the input. Use array notation with dot “·” product and
element-wise “⊙” product. Hint
sjin ← sjin + pj
Iapp ← win · sin ⊙ Ein − win · sin ⊙ vt
Exercise 3
Simulate 1000 neurons for 1000 ms and plot the resulting spikes. Assume
that each neuron receives (random) 10% of the 100 Poisson spike trains of
rate frate = 2 Hz between time 200 ms and 700 ms. Note that the neurons
are not yet inter-connected.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 3
Simulate 1000 neurons for 1000 ms and plot the resulting spikes. Assume
that each neuron receives (random) 10% of the 100 Poisson spike trains of
rate frate = 2 Hz between time 200 ms and 700 ms. Note that the neurons
are not yet inter-connected.
0
0 200 400 600 800 1000
Time [ms]
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
2 Initialize 2 logical vectors kinh and kexc of length n, where kinh (i) is True with
probability p = 0.2 (marking an inhibitory neuron) and False otherwise. And
kexc = ¬kinh .
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
2 Initialize 2 logical vectors kinh and kexc of length n, where kinh (i) is True with
probability p = 0.2 (marking an inhibitory neuron) and False otherwise. And
kexc = ¬kinh .
3 Reserve memory and initialize vi,t , ui,t (now being T × n matrices). Set
parameter vectors a and d according to kexc and kinh .
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
2 Initialize 2 logical vectors kinh and kexc of length n, where kinh (i) is True with
probability p = 0.2 (marking an inhibitory neuron) and False otherwise. And
kexc = ¬kinh .
3 Reserve memory and initialize vi,t , ui,t (now being T × n matrices). Set
parameter vectors a and d according to kexc and kinh .
4 The weights wijin = 0.07 now form a n × nin matrix. Set 90 % random elements
to 0 to account for the connection probability.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
2 Initialize 2 logical vectors kinh and kexc of length n, where kinh (i) is True with
probability p = 0.2 (marking an inhibitory neuron) and False otherwise. And
kexc = ¬kinh .
3 Reserve memory and initialize vi,t , ui,t (now being T × n matrices). Set
parameter vectors a and d according to kexc and kinh .
4 The weights wijin = 0.07 now form a n × nin matrix. Set 90 % random elements
to 0 to account for the connection probability.
5 Inside the for-loop change/add the following:
1 Same update equations (for vi,t+1 and ui,t+1 ) but use array notation.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 3 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize new parameter values (n = 1000)
2 Initialize 2 logical vectors kinh and kexc of length n, where kinh (i) is True with
probability p = 0.2 (marking an inhibitory neuron) and False otherwise. And
kexc = ¬kinh .
3 Reserve memory and initialize vi,t , ui,t (now being T × n matrices). Set
parameter vectors a and d according to kexc and kinh .
4 The weights wijin = 0.07 now form a n × nin matrix. Set 90 % random elements
to 0 to account for the connection probability.
5 Inside the for-loop change/add the following:
1 Same update equations (for vi,t+1 and ui,t+1 ) but use array notation.
6 Plot the spike raster. Plot black dots at {(t, i)|vit ≥ 35} for excitatory neurons i.
Use red dots for inhibitory neurons.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 4
Simulate 1000 neurons as before but with added recurrent connections.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 4
Simulate 1000 neurons as before but with added recurrent connections.
200
Weights are Gamma distributed
(wavg = 0.005 and gsc = 0.002). Set the 0
0 200 400 600 800 1000
inhibitory to excitatory connections twice as Time [ms]
strong on average.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
2 Reserve memory and initialize weights W = (wij ) to zero. Randomly choose 10%
of the matrix elements.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
2 Reserve memory and initialize weights W = (wij ) to zero. Randomly choose 10%
of the matrix elements.
3 Set the chosen weight matrix elements to values drawn from a Gamma
distribution of scale gsc = 0.002 and shape gsh = wgavg
sc
, with wavg = 0.005. Hint
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
2 Reserve memory and initialize weights W = (wij ) to zero. Randomly choose 10%
of the matrix elements.
3 Set the chosen weight matrix elements to values drawn from a Gamma
distribution of scale gsc = 0.002 and shape gsh = wgavg
sc
, with wavg = 0.005. Hint
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
2 Reserve memory and initialize weights W = (wij ) to zero. Randomly choose 10%
of the matrix elements.
3 Set the chosen weight matrix elements to values drawn from a Gamma
distribution of scale gsc = 0.002 and shape gsh = wgavg
sc
, with wavg = 0.005. Hint
Step 4 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Initialize and allocate memory for the new variables (s = (sj ), Ej ). Set Ej = −85
if j is an inhibitory neuron (otherwise 0).
2 Reserve memory and initialize weights W = (wij ) to zero. Randomly choose 10%
of the matrix elements.
3 Set the chosen weight matrix elements to values drawn from a Gamma
distribution of scale gsc = 0.002 and shape gsh = wgavg
sc
, with wavg = 0.005. Hint
Solution to step 4
1 from p y l a b i m p o r t ∗ 43 T = c e i l ( tmax / d t )
2 from s c i p y . s p a r s e i m p o r t c s r m a t r i x 44 v = z e r o s ( ( T , n ) )
3 45 u = z e r o s ( ( T , n ) )
4 # 1) i n i t i a l i z e parameters 46 v [ 0 ] = −70
5 tmax = 1 0 0 0 . 47 u [ 0 ] = −14
6 dt = 0.5 48 s i n = z e r o s ( n i n )
7 49 E i n = z e r o s ( n i n )
8 # 1 . 1 ) Neuron / Network p a r s 50 p r a t e = d t ∗ r a t e i n ∗1e−3
9 n = 1000 51 s = z e r o s ( n ) # r e c s y n a p s e s
10 p i n h = 0 . 2 52
11 i n h = ( u n i f o r m ( s i z e=n)< p i n h ) 53 # 3 ) f o r −l o o p o v e r t i m e
12 e x c = l o g i c a l n o t ( i n h ) 54 f o r t i n a r a n g e (T−1):
13 a = i n h . c h o o s e ( 0 . 0 2 , 0 . 1 ) 55 # 3.1) get input
14 b = 0 . 2 56 i f t>t r [ 0 ] and t<t r [ 1 ] :
15 c = −65 57 p = u n i f o r m ( s i z e=n i n )< p r a t e ;
16 d = i n h . c h o o s e ( 8 , 2 ) 58 else :
17 t a u s = 10 59 p = 0;
18 60
19 # NEW r e c u r r e n t p a r a m e t e r 61 s i n = ( 1 − d t / t a u s )∗ s i n + p
20 w = 0 . 0 0 5 # a v e r a g e r e c u r r e n t w e i g h t 62 I = W in . d o t ( s i n ∗ E i n )
21 pconn = 0 . 1 # r e c u r r e n t c o n n e c t i o n p r o b 63 I −= W in . d o t ( s i n )∗ v [ t ]
22 s c a l e E I = 2 # s c a l e I−>E 64
23 g s c = 0 . 0 0 2 # s c a l e o f gamma 65 f i r e d = v [ t ]>=35
24 E = i n h . c h o o s e (0 , −85) 66
25 # NEW: make w e i g h t m a t r i x 67 # NEW: r e c u r r e n t i n p u t
26 W = z e r o s ( ( n , n ) ) 68 s = ( 1 − d t / t a u s )∗ s + f i r e d
27 C = u n i f o r m ( s i z e =(n , n ) ) 69 I s y n = W. d o t ( s ∗E ) − W. d o t ( s )∗ v [ t ]
28 i d x = n o n z e r o ( C<pconn ) # s p a r s e c o n n e c t i v i t y 70 I += I s y n # add t o i n p u t v e c t o r
29 W[ i d x ] = gamma (w/ g s c , s c a l e=g s c , s i z e=i d x [ 0 ] . s i z e ) 71
30 W[ i x ( exc , i n h ) ] ∗= s c a l e E I #submat i n d e x i n g 72 # 3 . 2 ) u p d a t e ODE
31 W = c s r m a t r i x (W) # make row s p a r s e 73 dv = ( 0 . 0 4 ∗ v [ t ]+5)∗ v [ t ]+140−u [ t ]
32 74 v [ t +1] = v [ t ] + ( dv+I )∗ d t
33 # 1 . 2 ) I n p u t p a r s 75 du = a ∗( b∗v [ t ]−u [ t ] )
34 t r=a r r a y ( [ 2 0 0 . , 7 0 0 ] ) / d t 76 u [ t +1] = u [ t ] + d t ∗du
35 r a t e i n = 2 77
36 n i n = 100 78 # 3.3) spikes !
37 w i n = 0 . 0 7 79 v [ t ] [ f i r e d ] = 35
38 p c o n n i n = 0 . 1 80 v [ t +1][ f i r e d ] = c
39 C = u n i f o r m ( s i z e =(n , n i n ))< p c o n n i n 81 u [ t + 1 ] [ f i r e d ] = u [ t ] [ f i r e d ]+d [ f i r e d ]
40 W in = C . c h o o s e ( 0 , w i n ) 82
41 83 # 4 ) p l o t t i n g
42 # 2 ) r e s e r v e memory 84 t s p k , n s p k = n o n z e r o ( v==35)
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 5
Restructure the connection matrix and the input to simulate an orientation
column. That is all E-E neurons only connect to neighboring neurons and the
network resembles a 1D ring.
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Exercise 5
Restructure the connection matrix and the input to simulate an orientation
column. That is all E-E neurons only connect to neighboring neurons and the
network resembles a 1D ring.
Ring structure
0
0 200 400 600 800 1000
Time [ms]
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 5 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Set indexes of the weight matrix to zero, which belong to exc-exc connections
further apart that π/4. Hint: One can use scipy.linalg.circulant
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Step 5 in detail:
Modify the last script (after saving it under new name).
Proceed as follows:
1 Set indexes of the weight matrix to zero, which belong to exc-exc connections
further apart that π/4. Hint: One can use scipy.linalg.circulant
2 Change the input so that only half (e.g. from 0 to pi) of the neurons receive
input (again with probability 0.2). neurons
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Solution to step 5
1 from p y l a b i m p o r t ∗ 43 W in = C . c h o o s e ( 0 , w i n )
2 from s c i p y . s p a r s e i m p o r t c s r m a t r i x 44 W in [ n / 2 : , : ] = 0 # NEW
3 from s c i p y . l i n a l g i m p o r t c i r c u l a n t 45
4 # 1) i n i t i a l i z e parameters 46 # 2 ) r e s e r v e memory
5 tmax = 1 0 0 0 . 47 T = c e i l ( tmax / d t )
6 dt = 0.5 48 v = z e r o s ( ( T , n ) )
7 49 u = z e r o s ( ( T , n ) )
8 # 1 . 1 ) Neuron / Network p a r s 50 v [ 0 ] = −70
9 n = 1000 51 u [ 0 ] = −14
10 p i n h = 0 . 2 52 s i n = z e r o s ( n i n )
11 i n h = ( u n i f o r m ( s i z e=n)< p i n h ) 53 E i n = z e r o s ( n i n )
12 e x c = l o g i c a l n o t ( i n h ) 54 p r a t e = d t ∗ r a t e i n ∗1e−3
13 a = i n h . c h o o s e ( 0 . 0 2 , 0 . 1 ) 55 s = z e r o s ( n ) # r e c s y n a p s e s
14 b = 0 . 2 56
15 c = −65 57 # 3 ) f o r −l o o p o v e r t i m e
16 d = i n h . c h o o s e ( 8 , 2 ) 58 f o r t i n a r a n g e (T−1):
17 t a u s = 10 59 # 3.1) get input
18 60 i f t>t r [ 0 ] and t<t r [ 1 ] :
19 w i d t h = p i /4 # h a l f −w i d t h o f t h e o r i e n t a t i o n t u n i n g 61 p = u n i f o r m ( s i z e=n i n )< p r a t e ;
20 w = 0 . 0 0 5 62 else :
21 pconn = 0 . 4 # s e t a b i t h i g h e r 63 p = 0;
22 s c a l e E I = 2 64
23 g s c = 0 . 0 0 2 65 s i n = ( 1 − d t / t a u s )∗ s i n + p
24 E = i n h . c h o o s e (0 , −85) 66 I = W in . d o t ( s i n ∗ E i n )
25 W = z e r o s ( ( n , n ) ) 67 I −= W in . d o t ( s i n )∗ v [ t ]
26 C = u n i f o r m ( s i z e =(n , n ) ) 68
27 i d x = n o n z e r o ( C<pconn ) 69 f i r e d = v [ t ]>=35
28 W[ i d x ] = gamma (w/ g s c , s c a l e=g s c , s i z e=i d x [ 0 ] . s i z e ) 70
29 W[ i x ( exc , i n h ) ] ∗= s c a l e E I 71 # NEW: r e c u r r e n t i n p u t
30 t h e t a = l i n s p a c e ( 0 , 2 ∗ p i , n ) # NEW 72 s = ( 1 − d t / t a u s )∗ s + f i r e d
31 R = c i r c u l a n t ( c o s ( t h e t a ))> c o s ( w i d t h ) #NEW 73 I s y n = W. d o t ( s ∗E ) − W. d o t ( s )∗ v [ t ]
32 W[ : , e x c ] = w h e r e (R [ : , e x c ] ,W[ : , e x c ] , 0 ) # NEW 74 I += I s y n # add t o i n p u t v e c t o r
33 W = c s r m a t r i x (W) 75
34 76 # 3 . 2 ) u p d a t e ODE
35 # 1 . 2 ) I n p u t p a r s 77 dv = ( 0 . 0 4 ∗ v [ t ]+5)∗ v [ t ]+140−u [ t ]
36 t r=a r r a y ( [ 2 0 0 . , 7 0 0 ] ) / d t 78 v [ t +1] = v [ t ] + ( dv+I )∗ d t
37 r a t e i n = 2 79 du = a ∗( b∗v [ t ]−u [ t ] )
38 i n w i d t h = p i /2 80 u [ t +1] = u [ t ] + d t ∗du
39 w i n = 0 . 0 7 81
40 p c o n n i n = 0 . 2 82 # 3.3) spikes !
41 n i n = 100 83 v [ t ] [ f i r e d ] = 35
42 C = u n i f o r m ( s i z e =(n , n i n ))< p c o n n i n 84 v [ t +1][ f i r e d ] = c
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
Congratulation !
1 f r o m numpy . random i m p o r t u n i f o r m
2 n i n = 100
3 r = u n i f o r m ( s i z e=n i n )
1 r = u n i f o r m ( s i z e=n i n )
2 v = ( r<p ) . c h o o s e ( b , a )
back
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
3 g s h a p e , g s c a l e , n = 0 . 0 0 3 , 2 , 1000
4 r = gamma( g s h a p e , g s c a l e , n )
back
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
1 from pylab i m p o r t ∗
2 from s c i p y . s p a r s e i m p o r t c s r m a t r i x
3
8 v = u n i f o r m ( s i z e =100) # example v e c t o r
9 x = W2. d o t ( v ) # matrix dot product
back
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
1 from pylab i m p o r t ∗
2
7 W( i x ( i r o w , i c o l ) ) += 1 # add 1 t o t h e e l e m e n t s
back
Introduction Step 1 Step 2 Step 3 Step 4 Step 5 Hints
1 from pylab i m p o r t ∗
2 a = array ([1. ,2 ,3 ,4])
3 b = array ([1. ,1 ,5 ,5])
4 c = a ∗b # e l e m e n t −w i s e !
5 c . size
6 4
7 d = a . dot ( b ) # s c a l a r product
8 d . size
9 1
back