【发布时间】:2014-12-18 11:23:43
【问题描述】:
如何在 PyMC3 中定义自定义可能性?在 PyMC2 中,我可以使用 @pymc.potential。我尝试在 PyMC3 中使用 pymc.Potential,但是,布尔运算似乎无法应用于参数(当我这样做时,我收到类似 this 的错误)。例如,以下代码不起作用:
from pymc import *
with Model() as model:
x = Normal('x', 1, 1)
def z(u):
if u > 0: #comparisons like this are not supported
# if theano.tensor.lt(0,u): this is how comparison should be done
return u ** 2
return -u**3
x2 = Potential('x2', z(x))
start = model.test_point
h = find_hessian(start)
step = Metropolis(model.vars, h)
sample(100, step, start)
我不可能将可能性内的所有比较都更改为 Theano 语法(即 theano.tensor.{lt,le,eq,neq,gt,ge})。有没有办法使用定义类似于 PyMC2 的似然函数?
【问题讨论】: