【发布时间】:2021-04-21 10:14:43
【问题描述】:
我正在使用 PyMC3 解决以下 ODE:
def production( y, t, p ):
return p[0]*getBeam( t ) - p[1]*y[0]
getBeam( t ) 是我的时间相关系数。这些系数由一个数据数组给出,该数组由时间索引访问,如下所示:
def getBeam( t ):
nBeam = I[int(t/10)]*pow( 10, -6 )/q_e
return nBeam
我已经通过使用scipy.integrate.odeint 成功实现了它,但是我很难用pymc3.ode 来实现它。事实上,通过使用以下内容:
ode_model = DifferentialEquation(func=production, times=x, n_states=1, n_theta=3, t0=0)
with pm.Model() as model:
a = pm.Uniform( "S-Factor", lower=0.01, upper=100 )
ode_solution = ode_model(y0=[0], theta=[a, Yield, lambd])
我显然得到了错误TypeError: __trunc__ returned non-Integral (type TensorVariable),因为t 是TensorVariable,因此不能用于访问存储系数的数组。
有没有办法克服这个困难?我考虑过使用theano.function,但我无法让它工作,因为不幸的是,系数不能用任何分析函数表示:它们只是存储在数组I 中,其中索引代表时间变量t。
谢谢
【问题讨论】:
-
为什么不把数值常量
pow( 10, -6 )直接给成1e-6? -
是的,你是对的,我可以这样写。谢谢,但问题仍然存在。
标签: python theano bayesian ode pymc3