Debian Codegraph @

examples/frompapers/Izhikevich_2003.py

raw
1 #!/usr/bin/env python3
2 """
3 Fig. 3 of
4
5 Simple Model of Spiking Neurons
6 IEEE Transactions on Neural Networks ( Volume: 14, Issue: 6, Nov. 2003)
7 Eugene M. Izhikevich
8
9 based on net.m by Eugene M. Izhikevich (http://izhikevich.org/publications/spikes.htm)
10
11 Akif Erdem Sağtekin and Sebastian Schmitt, 2022
12 """
13 import matplotlib.pyplot as plt
14 import numpy as np
15
16 from brian2 import NeuronGroup, Synapses, SpikeMonitor, StateMonitor
17 from brian2 import ms, mV
18 from brian2 import defaultclock, run
19
20 tfinal = 1000 * ms
21 Ne = 800
22 Ni = 200
23
24 re = np.random.uniform(size=Ne)
25 ri = np.random.uniform(size=Ni)
26 weights = np.hstack(
27 [
28 0.5 * np.random.uniform(size=(Ne + Ni, Ne)),
29 -np.random.uniform(size=(Ne + Ni, Ni)),
30 ]
31 ).T
32
33 defaultclock.dt = 1 * ms
34
35 eqs = """dv/dt = (0.04*v**2 + 5*v + 140 - u + I + I_noise )/ms : 1
36 du/dt = (a*(b*v - u))/ms : 1
37 I : 1
38 I_noise : 1
39 a : 1
40 b : 1
41 c : 1
42 d : 1
43 """
44
45 N = NeuronGroup(Ne + Ni, eqs, threshold="v>=30", reset="v=c; u+=d", method="euler")
46 N.v = -65
47
48 N_exc = N[:Ne]
49 N_inh = N[Ne:]
50
51 spikemon = SpikeMonitor(N)
52 statemon = StateMonitor(N, 'v', record=0, when='after_thresholds')
53 N_exc.a = 0.02
54 N_exc.b = 0.2
55 N_exc.c = -65 + 15 * re**2
56 N_exc.d = 8 - 6 * re**2
57
58 N_inh.a = 0.02 + 0.08 * ri
59 N_inh.b = 0.25 - 0.05 * ri
60 N_inh.c = -65
61 N_inh.d = 2
62
63 N_exc.u = "b*v"
64 N_inh.u = "b*v"
65
66 S = Synapses(
67 N,
68 N,
69 "w : 1",
70 on_pre={"up": "I += w", "down": "I -= w"},
71 delay={"up": 0 * ms, "down": 1 * ms},
72 )
73 S.connect()
74 S.w[:] = weights.flatten()
75
76 N_exc.run_regularly("I_noise = 5*randn()", dt=1 * ms)
77 N_inh.run_regularly("I_noise = 2*randn()", dt=1 * ms)
78
79 run(tfinal)
80
81 fig, (ax, ax_voltage) = plt.subplots(2, 1, sharex=True,
82 gridspec_kw={'height_ratios': (3, 1)})
83
84 ax.scatter(spikemon.t / ms, spikemon.i[:], marker="_", color="k", s=10)
85 ax.set_xlim(0, tfinal / ms)
86 ax.set_ylim(0, len(N))
87 ax.set_ylabel("neuron number")
88 ax.set_yticks(np.arange(0, len(N), 100))
89 ax.spines['right'].set_visible(False)
90 ax.spines['top'].set_visible(False)
91 ax.axhline(Ne, color="k")
92 ax.text(500, 900, 'inhibitory', backgroundcolor='w', color='k', ha='center')
93 ax.text(500, 400, 'excitatory', backgroundcolor='w', color='k', ha='center')
94
95 ax_voltage.plot(statemon.t / ms, np.clip(statemon.v[0], -np.inf, 30),
96 color='k')
97 ax_voltage.text(25, 0, 'v₁(t)')
98 ax_voltage.set_xticks(np.arange(0, tfinal / ms, 100))
99 ax_voltage.spines['right'].set_visible(False)
100 ax_voltage.spines['top'].set_visible(False)
101 ax_voltage.set_xlabel("time, ms")
102
103 plt.show()