这个问题可能很简单,但对于我的生活,我无法弄明白。基本上,我有一个神经元的电压我正在建模,但我让它随机接收来自其他神经元的输入尖峰。所以我的一个朋友帮助创建了一个功能,基本上有一些兴奋神经元提供随机泊松尖峰,随机增加电压和一些抑制神经元提供向下尖峰降低电压。我已经包含了下面的代码。基本上我试图弄清楚如何做的步骤是如何使迭代步骤中的I_syn术语起作用。我通常认为只写I_syn[i-1]
,但这给了我一个错误:
'function' object has no attribute '__getitem__'.
所以我确定这个问题非常简单,但这是一个我不知道如何克服的问题。如何让这个程序正确地迭代I_syn
项,这样我就可以做一个ODE的基本迭代方案,同时包含一个先前在代码中定义的函数?这很重要,因为在不久的将来我可能会有更复杂的神经元方程,因此事先编写函数然后根据需要将它们调用到迭代步骤会好得多。谢谢!
from numpy import *
from pylab import *
## setup parameters and state variables
T = 50 # total time to simulate (msec)
dt = 0.125 # simulation time step (msec)
time = arange(0, T+dt, dt) # time array
t_rest = 0 # initial refractory time
## LIF properties
Vm = zeros(len(time)) # potential (V) trace over time
Rm = 1 # resistance (kOhm)
Cm = 10 # capacitance (uF)
tau_m = Rm*Cm # time constant (msec)
tau_ref = 4 # refractory period (msec)
Vth = 1 # spike threshold (V)
V_spike = 0.5 # spike delta (V)
## Stimulus
I = 1.5 # input current (A)
N = 1000
N_ex = 0.8*N #(0..79)
N_in = 0.2*N #(80..99)
G_ex = 0.1
K = 4
def I_syn(spks, t):
"""
Synaptic current
spks = [[synid, t],]
"""
if len(spks) == 0:
return 0
exspk = spks[spks[:,0]<N_ex] # Check for all excitatory spikes
delta_k = exspk[:,1] == t # Delta function
if np.any(delta_k) > 0:
h_k = np.random.rand(len(delta_k)) < 0.90 # probability of successful transmission
else:
h_k = 0
inspk = spks[spks[:,0] >= N_ex] #Check remaining neurons for inhibitory spikes
delta_m = inspk[:,1] == t #Delta function for inhibitory neurons
if np.any(delta_m) > 0:
h_m = np.random.rand(len(delta_m)) < 0.90
else:
h_m = 0
isyn = C_m*G_ex*(np.sum(h_k*delta_k) - K*np.sum(h_m*delta_m))
return isyn
## iterate over each time step
for i, t in enumerate(time):
if t > t_rest:
Vm[i] = Vm[i-1] + (-Vm[i-1] + I_syn*Rm) / tau_m * dt
if Vm[i] >= Vth:
Vm[i] += V_spike
t_rest = t + tau_ref
## plot membrane potential trace
plot(time, Vm)
title('Leaky Integrate-and-Fire Example')
ylabel('Membrane Potential (V)')
xlabel('Time (msec)')
ylim([0,2])
show()
答案 0 :(得分:0)
I_syn
只是一个函数,因此使用I_syn[i-1]
会抛出此错误:
'function' object has no attribute '__getitem__'
如果您要查找的是该函数的返回值,那么您应首先调用它然后访问您想要的内容。
# pass related arguments as well since the function expects it
I_syn(arg1, arg2)[i-1]