-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiring_rate.py
118 lines (88 loc) · 3 KB
/
firing_rate.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from imports import *
from HRneuron import *
c = constants()
neuron1 = HRneuron(1)
time_vec = np.arange(0, c.ms, c.scale)
current_vec = np.zeros(c.iterations) + c.I
# print(time_vec[20])
# neuron1.set_current(1.2)
# neuron1.set_a(1.8)
# for i in range(c.iterations):
# neuron1.calculate_x(i)
# neuron1.calculate_y(i)
# neuron1.calculate_z(i)
# pot = neuron1.xarr
# peaks, other = find_peaks(pot, height=c.MIN_HEIGHT, threshold = 0, distance=c.MIN_DISTANCE, width=c.MIN_WIDTH)
# plt.plot(pot)
# plt.plot(peaks, pot[peaks], "x")
# plt.show()
# forward euler time :D
# --------- VARYING I ---------
firing_rate = []
interspike_interval = []
for j in range(3000, 3300):
neuron1.set_current(j * 0.001)
for i in range(c.iterations):
neuron1.calculate_x(i)
neuron1.calculate_y(i)
neuron1.calculate_z(i)
pot = neuron1.xarr
peaks, other = find_peaks(
pot, height=c.MIN_HEIGHT, threshold=0, distance=c.MIN_DISTANCE, width=c.MIN_WIDTH)
firing_rate.append(len(peaks) / (c.ms))
if len(peaks) != 0:
interspike_interval.append(c.ms / len(peaks))
else:
interspike_interval.append(0)
print(j*0.001)
firing_vec = np.arange(3, 3.3, 0.001)
#plt.plot(firing_vec, firing_rate)
# np.save("firing_rate.npy", firing_rate)
plt.plot(firing_vec, firing_rate, linewidth=1, color="black")
plt.xlabel("Injected Current")
plt.ylabel("Firing Rate (peaks / ms)")
plt.title("Firing Rate Based on Current")
plt.savefig("firing_rate_owo.png", dpi=300)
plt.show()
# --------- VARYING A ---------
# neuron1.set_current(1.5)
# firing_rate = []
# for k in range(10, 20):
# neuron1.set_current(k * 0.1)
# for j in range(5, 15):
# neuron1.set_a(j * 0.2)
# for i in range(c.iterations):
# neuron1.calculate_x(i)
# neuron1.calculate_y(i)
# neuron1.calculate_z(i)
# pot = neuron1.xarr
# peaks, other = find_peaks(pot, height=c.MIN_HEIGHT, threshold = 0, distance=c.MIN_DISTANCE, width=c.MIN_WIDTH)
# print("current: ", k * 0.1, " a: ", j * 0.2, len(peaks))
# firing_rate.append(len(peaks) / (c.ms))
# print(j*0.2)
# print("K ", k * 0.1)
"""
firing_rate = []
a_list = [1.2, 1.4, 1.6, 1.8]
color_list = ["red", "yellow", "green", "blue"]
for k in range(len(a_list)):
firing_rate = []
neuron1.set_a(a_list[k])
for j in range(50):
neuron1.set_current(j * 0.1)
for i in range(c.iterations):
neuron1.calculate_x(i)
neuron1.calculate_y(i)
neuron1.calculate_z(i)
pot = neuron1.xarr
peaks, other = find_peaks(pot, height=c.MIN_HEIGHT, threshold = 0, distance=c.MIN_DISTANCE, width=c.MIN_WIDTH)
firing_rate.append(len(peaks))
print(j*0.1)
firing_vec = np.arange(0, 5, 0.1)
plt.plot(firing_vec, firing_rate, color=color_list[k], label=str(a_list[k]))
plt.xlabel("Injected Current")
plt.ylabel("Firing Rate (peaks / ms)")
plt.title("Firing Rate Based on Current")
leg = plt.legend()
plt.show()
"""