-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspike_train
More file actions
96 lines (72 loc) · 2.51 KB
/
spike_train
File metadata and controls
96 lines (72 loc) · 2.51 KB
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
######################################################## README #############################################################
# This file generates rate based spike train from the potential map.
############################################################################################################################
\
import numpy as np
from numpy import interp
from matplotlib import pyplot as plt
import imageio
import math
from snn.parameters import param as par
from snn.recep_field import rf
def encode2(pixels):
#initializing spike train
train = []
for l in range(pixels.shape[0]):
for m in range(pixels.shape[1]):
temp = np.zeros([(par.T+1),])
#calculating firing rate proportional to the membrane potential
freq = interp(pixels[l][m], [0, 255], [1,20])
#print(pot[l][m], freq)
# print freq
assert freq > 0
freq1 = math.ceil(600/freq)
#generating spikes according to the firing rate
k = freq1
if(pixels[l][m]>0):
while k<(par.T+1):
temp[k] = 1
k = k + freq1
train.append(temp)
# print sum(temp)
return train
def encode(pot):
#initializing spike train
train = []
for l in range(pot.shape[0]):
for m in range(pot.shape[1]):
temp = np.zeros([(par.T+1),])
#calculating firing rate proportional to the membrane potential
freq = interp(pot[l][m], [-1.069,2.781], [1,20])
#print(pot[l][m], freq)
# print freq
assert freq > 0
freq1 = math.ceil(600/freq)
#generating spikes according to the firing rate
k = freq1
if(pot[l][m]>0):
while k<(par.T+1):
temp[int(k)] = 1
k = k + freq1
train.append(temp)
# print sum(temp)
return train
if __name__ == '__main__':
# m = []
# n = []
img = imageio.imread("/Users/johnsoni/Downloads/mnist_png/training/5/0.png")
#img = imageio.imread("data/training/0.png")
pot = rf(img)
# for i in pot:
# m.append(max(i))
# n.append(min(i))
# print max(m), min(n)
#train = encode2(img)
train = encode(pot)
f = open('train6.txt', 'w')
print(np.shape(train))
for j in range(len(train)):
for i in range(len(train[j])):
f.write(str(int(train[j][i])))
f.write('\n')
f.close()