forked from boldchan/SNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers.py
30 lines (27 loc) · 821 Bytes
/
layers.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
import numpy as np
from scipy.ndimage.interpolation import shift
def synapse(x, w, dt, T):
'''
Parameters
-------
x: output of former layer(input layer or hidden layer), shape N x (T/dt), N is the neuron number of
former layer
w: weights
b: bias
output
-------
PSP: postsynaptic potential, shape M x (T/dt), M is the neuron number of next layer
'''
time = np.arange(0, T + dt, dt)
gmax = 30
tao_s = 5
tf = x * np.array([[i * dt for i in range(x.shape[1])] for j in range(x.shape[0])])
alpha_t = gmax * time / tao_s * np.exp(1 - time / tao_s)
PSP = np.zeros((w.shape[1], len(time)))
for j in range(w.shape[1]):
for i in range(tf.shape[0]):
temp = np.zeros(len(time))
for t in np.where(tf[i] > 0)[0]:
temp += shift(alpha_t, t, cval = 0)
PSP[j] += w[i, j] * temp
return PSP