将突触前电压作为数组传递给odeint函数

时间:2019-07-17 13:55:38

标签: python odeint neuroscience

我有两个神经元的耦合代码。用odeint求解微分方程比任何其他数值方法快得多。 有什么方法可以将数组传递给odeint函数吗?

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from numpy import concatenate as cc
import scipy as sp

def HHodeint(I,preVoltage):
    #counter = 0
    preVoltage = sp.array(preVoltage)
    t = np.linspace(0,100,1000)
    def alpha_n(v):
        return 0.01*(v+50)/(1-np.exp(-(v+50)/10))
    def beta_n(v):
        return 0.125*np.exp(-(v+60)/80)
    def alpha_h(v):
        return 0.07*np.exp(-0.05*(v+60))
    def beta_h(v):
        return 1/(1+np.exp(-(0.1)*(v+30.0)))
    def alpha_m(v):
        return 0.1*(v+35.0)/(1-np.exp(-(v+35.0)/10.0))
    def beta_m(v):
        return 4.0*np.exp(-0.0556*(v+60))
    def alpha_s(preV):
        return 1/(1+np.exp(-(preV)))
    def beta_s(preV):
        return 1/(2+np.exp(preV))


    def HHmodel(x,t,preVoltage):

        v = x[0] #initial values
        m = x[1]
        h = x[2]
        n = x[3]
        s = x[4]
        #spikes_train = x[4]

        Cm = 1.0 #microFarad
        E_Na=50 #miliVolt
        E_K=-77  #miliVolt
        E_l=-54 #miliVolt
        g_Na=120 #mScm-2
        g_K=36 #mScm-2
        g_l=0.03 #mScm-2
        E_syn = 4 #mScm-2
        g_syn = 0.1

        def I_Na(v,m,h):
            return g_Na * m**3 * h * (v - E_Na)
        def I_K(v,n):
            return g_K * n**4 * (v - E_K)
        def I_L(v):
            return g_l * (v - E_l)
        def I_syn(v):
            return g_syn * s * (v - E_syn)


        dvdt = (I - I_Na(v,m,h) - I_K(v,n) - I_L(v) - I_syn(v))/Cm
        dmdt = alpha_m(v)*(1.0 - m) - beta_m(v)*m
        dhdt = alpha_h(v)*(1.0 - h) - beta_h(v)*h
        dndt = alpha_n(v)*(1.0 - n) - beta_n(v)*n
        dsdt = alpha_s(preVoltage)*(1.0 - s) - beta_s(preVoltage)*s
        #counter += 1
        return [dvdt,dmdt,dhdt,dndt,dsdt]


    v0 = -65.0
    n0 = float(alpha_n(v0)/(alpha_n(v0)+beta_n(v0)))
    h0 = float(alpha_h(v0)/(alpha_h(v0)+beta_h(v0)))
    m0 = float(alpha_m(v0)/(alpha_m(v0)+beta_m(v0)))
    s0 = float(alpha_s(preVoltage[0])/(alpha_s(preVoltage[0])+beta_s(preVoltage[0])))
    x0 = [v0,m0,h0,n0,s0]
    x = odeint(HHmodel,x0,t,args=(preVoltage,))
    voltage = x[:, 0]


    #mchannels = x[:, 1]
    #hchannels = x[:, 2]
    #nchannels = x[:, 3]

    return voltage

功能:

def HHmodel(x,t,preVoltage):

求解部分:

x = odeint(HHmodel,x0,t,args=(preVoltage,))

这是我从终端收到的错误:

ValueError: setting an array element with a sequence.

有人可以帮我解决这个问题吗?

0 个答案:

没有答案