- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想使用 pymc3 来估计 Hodgkin Huxley 神经元模型中的未知参数和状态。我在 pymc 中的代码基于 http://healthyalgorithms.com/2010/10/19/mcmc-in-python-how-to-stick-a-statistical-model-on-a-system-dynamics-model-in-pymc/并且执行得相当好。
#parameter priors
@deterministic
def HH(priors in here)
#model equations
#return numpy arrays that somehow contain the probability distributions as elements
return V,n,m,h
#Make V deterministic in one line. Seems to be the magic that makes this work.
V = Lambda('V', lambda HH=HH: HH[0])
#set up the likelihood
A = Normal('A',mu=V,tau=2.0,value=voltage_data,observed = True)
#run the sampling...
在 pymc3 中,我无法使用 Lambda 技巧。这是我的尝试之一:
import numpy as np
import theano.tensor as tt
from pymc3 import Model, Normal, Uniform, Deterministic, sample, NUTS, Metropolis, find_MAP
import scipy
#observed data
T = 10
dt = 0.02
voltage_data_file = 'noise_measured.dat'
voltage_data = np.loadtxt(voltage_data_file)
voltage_data = voltage_data[0:T]
current_data_file = 'current.dat'
current_data = np.loadtxt(current_data_file)
current_data = current_data[0:T]
#functions needed later
def x_inf(V,vx,dvx):
return 0.5*(1 + np.tanh((V - vx)/dvx))
def tau(V,vx_t,dvx_t,tx_0,tx_1):
return tx_0 + 0.5*tx_1*(1 + np.tanh((V- vx_t)/dvx_t))
#Model
NaKL_Model = Model()
with NaKL_Model:
#priors
g_Naa = Uniform('g_Naa',0.0,150.0)
E_Na = Uniform('E_Na',30.0,70.0)
g_K = Uniform('g_K',0.0,150.0)
E_K = Uniform('E_K',-100.0,-50.0)
g_L = Uniform('g_L',0.1,1.0)
E_L = Uniform('E_L',-90.0,-50.0)
vm = Uniform('vm',-60.0,-30.0)
vm_t = Uniform('vm_t',-60.0,-30.0)
dvm = Uniform('dvm',10.0,20.0)
dvm_t = Uniform('dvm_t',10.0,20.0)
tmm_0 = Uniform('tmm_0',0.05,0.25)
tm_1 = Uniform('tm_1',0.1,1.0)
vh = Uniform('vh',-80.0,-40.0)
vh_t = Uniform('vh_t',-80.0,-40.0)
dvh = Uniform('dvh',-30.0,-10.0)
dvh_t = Uniform('dvh_t',-30.0,-10.0)
th_0 = Uniform('th_0',0.5,1.5)
th_1 = Uniform('th_1',5.0,9.0)
vn = Uniform('vn',-70.0,-40.0)
vn_t = Uniform('vn_t',-70.0,-40.0)
dvn = Uniform('dvn',10.0,40.0)
dvn_t = Uniform('dvn_t',10.0,40.0)
tn_0 = Uniform('tn_0',0.5,1.5)
tn_1 = Uniform('tn_1',3.0,7.0)
#Initial Conditions
V_0 = Uniform('V_0',-100.0,50.0)
n_0 = Uniform('n_0',0.0,1.0)
m_0 = Uniform('m_0',0.0,1.0)
h_0 = Uniform('h_0',0.0,1.0)
def HH(i,V_current,n_current,m_current,h_current,g_Naa=g_Naa,E_Na=E_Na,g_K=g_K,E_K=E_K,g_L=g_L,E_L=E_L,vm=vm,vm_t=vm_t,dvm=dvm,dvm_t=dvm_t,tmm_0=tmm_0,tm_1=tm_1,vh=vh,vh_t=vh_t,dvh=dvh,dvh_t=dvh_t,th_0=th_0,th_1=th_1,vn=vn,vn_t=vn_t,dvn=dvn,dvn_t=dvn_t,tn_0=tn_0,tn_1=tn_1):
V_new = V_current + dt*(g_L*(E_L - V_current) + g_K*n_current**4*(E_K - V_current) + g_Naa*m_current**3*h_current*(E_Na - V_current) + current_data[i])
n_new = n_current + dt*(x_inf(V_current,vn,dvn)-n_current)/tau(V_current,vn_t,dvn_t,tn_0,tn_1)
m_new = m_current + dt*(x_inf(V_current,vm,dvm)-m_current)/tau(V_current,vm_t,dvm_t,tmm_0,tm_1)
h_new = h_current + dt*(x_inf(V_current,vh,dvh)-h_current)/tau(V_current,vh_t,dvh_t,th_0,th_1)
return V_new,n_new,m_new,h_new
V_state = [V_0]
n_state = [n_0]
m_state = [m_0]
h_state = [h_0]
#A = [Normal('A0',mu=V_0,tau=2.0,observed = voltage_data[0])]
for i in range(1,T):
V_state.append(Deterministic('V' + str(i), HH(i-1,V_state[i-1],n_state[i-1],m_state[i-1],h_state[i-1])[0]))
n_state.append(Deterministic('V' + str(i), HH(i-1,V_state[i-1],n_state[i-1],m_state[i-1],h_state[i-1])[1]))
m_state.append(Deterministic('V' + str(i), HH(i-1,V_state[i-1],n_state[i-1],m_state[i-1],h_state[i-1])[2]))
h_state.append(Deterministic('V' + str(i), HH(i-1,V_state[i-1],n_state[i-1],m_state[i-1],h_state[i-1])[3]))
#A.append(Normal('A' + str(i),mu=V_state[i],sd=2.0,observed = voltage_data[0]))
A = Normal('A',mu=V_state,sd=2.0,observed = voltage_data)
start = find_MAP()
#step = NUTS(scaling=start)
step = Metropolis(start=start)
trace = sample(100,step)
我在这些论坛上看到的唯一另一个例子是:Simple Dynamical Model in PyMC3
但是,这无助于回答我的问题,因为那里提出的解决方案均无效。我的解决方案也不起作用 - 我没有收到错误,但是当我运行脚本时,采样似乎永远不会开始。无论如何,我的解决方案似乎效率低下,因为我必须运行 python for 循环来定义所有确定性分布。我不确定 pymc3 是否能识别我将它们全部放在纯 python 列表中的方式。如果我的函数 HH() 可以返回一个 numpy 数组或某种 theano 对象,也许这会有所帮助。但我不知道如何实现它。
最佳答案
在阅读最后两行的微小变化后,您的方法对我有用:
step = Metropolis()
trace = sample(100, step, start=start)
不过,这需要一段时间,所以如果您想更快地看到结果,可以将 T
变小。
关于python - 在 pymc3 中重写用于动态系统参数估计的 pymc 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428677/
简而言之:我想从可变参数模板参数中提取各种选项,但不仅通过标签而且通过那些参数的索引,这些参数是未知的 标签。我喜欢 boost 中的方法(例如 heap 或 lockfree 策略),但想让它与 S
我可以对单元格中的 excel IF 语句提供一些帮助吗? 它在做什么? 对“BaselineAmount”进行了哪些评估? =IF(BaselineAmount, (Variance/Baselin
我正在使用以下方法: public async Task Save(Foo foo,out int param) { ....... MySqlParameter prmparamID
我正在使用 CodeGear RAD Studio IDE。 为了使用命令行参数测试我的应用程序,我多次使用了“运行 -> 参数”菜单中的“参数”字段。 但是每次我给它提供一个新值时,它都无法从“下拉
我已经为信用卡类编写了一些代码,粘贴在下面。我有一个接受上述变量的构造函数,并且正在研究一些方法将这些变量格式化为字符串,以便最终输出将类似于 号码:1234 5678 9012 3456 截止日期:
MySql IN 参数 - 在存储过程中使用时,VarChar IN 参数 val 是否需要单引号? 我已经像平常一样创建了经典 ASP 代码,但我没有更新该列。 我需要引用 VarChar 参数吗?
给出了下面的开始,但似乎不知道如何完成它。本质上,如果我调用 myTest([one, Two, Three], 2); 它应该返回元素 third。必须使用for循环来找到我的解决方案。 funct
将 1113355579999 作为参数传递时,该值在函数内部变为 959050335。 调用(main.c): printf("%d\n", FindCommonDigit(111335557999
这个问题在这里已经有了答案: Is Java "pass-by-reference" or "pass-by-value"? (92 个回答) 关闭9年前。 public class StackOve
我真的很困惑,当像 1 == scanf("%lg", &entry) 交换为 scanf("%lg", &entry) == 1 没有区别。我的实验书上说的是前者,而我觉得后者是可以理解的。 1 =
我正在尝试使用调用 SetupDiGetDeviceRegistryProperty 的函数使用德尔福 7。该调用来自示例函数 SetupEnumAvailableComPorts .它看起来像这样:
我需要在现有项目上实现一些事件的显示。我无法更改数据库结构。 在我的 Controller 中,我(从 ajax 请求)传递了一个时间戳,并且我需要显示之前的 8 个事件。因此,如果时间戳是(转换后)
rails 新手。按照多态关联的教程,我遇到了这个以在create 和destroy 中设置@client。 @client = Client.find(params[:client_id] || p
通过将 VM 参数设置为 -Xmx1024m,我能够通过 Eclipse 运行 Java 程序-Xms256M。现在我想通过 Windows 中的 .bat 文件运行相同的 Java 程序 (jar)
我有一个 Delphi DLL,它在被 Delphi 应用程序调用时工作并导出声明为的方法: Procedure ProduceOutput(request,inputs:widestring; va
浏览完文档和示例后,我还没有弄清楚 schema.yaml 文件中的参数到底用在哪里。 在此处使用 AWS 代码示例:https://github.com/aws-samples/aws-proton
程序参数: procedure get_user_profile ( i_attuid in ras_user.attuid%type, i_data_group in data_g
我有一个字符串作为参数传递给我的存储过程。 dim AgentString as String = " 'test1', 'test2', 'test3' " 我想在 IN 中使用该参数声明。 AND
这个问题已经有答案了: When should I use "this" in a class? (17 个回答) 已关闭 6 年前。 我运行了一些java代码,我看到了一些我不太明白的东西。为什么下
我输入 scroll(0,10,200,10);但是当它运行时,它会传递字符串“xxpos”或“yypos”,我确实在没有撇号的情况下尝试过,但它就是行不通。 scroll = function(xp
我是一名优秀的程序员,十分优秀!