-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_sample.py
45 lines (35 loc) · 1.13 KB
/
if_sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from spine import IF
from spine.tools import PoissonSpike, plot_spike_scatter
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
duration = 500 # ms
dt = 0.1 # time step
time = int(duration / dt)
# create DLIF instance
neu = IF(duration,
dt,
k='double',
tau=(10, 1.0))
# random spike trains
spikes = PoissonSpike(np.random.random(10),
time=duration,
dt=dt).spikes
# random weights whose size is the same as spikes
weights = np.random.random(10) + 2.0
# calc voltage and get results
# v: membrane voltage
# s: output spike as boolean list
# f: firing times
v, s, f = neu.calc_v((spikes, weights))
# plotting
plt.subplot(2, 1, 1)
plot_spike_scatter(spikes, duration, dt, title='input spike trains', xlabel=None)
t = np.arange(0, duration, dt)
plt.subplot(2, 1, 2)
plt.plot(t, v)
plt.plot(t, np.full_like(t, neu.th), linestyle='dashed')
plt.xlim(0, duration)
plt.xlabel('time [ms]')
plt.ylabel('Membrane Voltage [mV]')
plt.show()