如何在 PyMC3 中定义自定义可能性?在 PyMC2 中,我可以使用@pymc.potential
. 我尝试pymc.Potential
在 PyMC3 中使用,但是,布尔运算似乎无法应用于参数(当我这样做时出现这样的错误)。例如,以下代码不起作用:
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 的似然函数吗?