Debian Codegraph @

examples/synapses/state_variables.py

raw
1 """
2 Set state variable values with a string (using code generation).
3 """
4
5 from brian2 import *
6
7 G = NeuronGroup(100, 'v:volt', threshold='v>-50*mV')
8 G.v = '(sin(2*pi*i/N) - 70 + 0.25*randn()) * mV'
9 S = Synapses(G, G, 'w : volt', on_pre='v += w')
10 S.connect()
11
12 space_constant = 200.0
13 S.w['i > j'] = 'exp(-(i - j)**2/space_constant) * mV'
14
15 # Generate a matrix for display
16 w_matrix = np.zeros((len(G), len(G)))
17 w_matrix[S.i[:], S.j[:]] = S.w[:]
18
19 subplot(1, 2, 1)
20 plot(G.v[:] / mV)
21 xlabel('Neuron index')
22 ylabel('v')
23 subplot(1, 2, 2)
24 imshow(w_matrix)
25 xlabel('i')
26 ylabel('j')
27 title('Synaptic weight')
28 tight_layout()
29 show()