我试图用stochastic pymc3编写我自己的和deterministic变量,但是已经出版的pymc2.3介绍了如何将变量参数化不再有效。例如,我试图使用这种direct方法,但失败了:
def x_logp(value, x_l, x_h):
if ((value>x_h) or (value<x_l)):
return -np.inf
else:
return -np.log(x_h-x_l+1)
def x_rand(x_l,x_h):
return np.round((x_h-x_l)*np.random.random_sample())+x_l
Xpos=pm.stochastic(logp=x_logp,
doc="X position of halo center ",
observed=False,
trace=True,
name='Xpos',
random=x_rand,
value=25.32,
parents={'x_l':0,'x_h'=500},
dtype=float64,
plot=True,
verbose=0)我收到以下错误消息:
ERROR: AttributeError: 'module' object has no attribute 'Stochastic' [unknown]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Stochastic'我想知道如何在不使用装饰器和可用的pymc3发行版的情况下在pymc中定义自己的优先级或可能性?
发布于 2014-09-15 10:37:49
增加自定义密度的方法主要有两种:
DensityDist,例如:dists.pyTheano有一个可以像这样使用的装饰器:@theano.compile.ops.as_op(itypes=[t.lscalar, t.dscalar, t.dscalar],otypes=[t.dvector])
def rate(switchpoint,early_mean, late_mean):
''' Concatenate Poisson means '''
out = empty(years)
out[:switchpoint] = early_mean
out[switchpoint:] = late_mean
return out摘自本例:determinisitc.py
判断可以直接通过组合随机变量来完成,或者,如果您希望它们出现在跟踪中,可以使用例如pm.Determinstic('sum', alpha + beta)。
https://stackoverflow.com/questions/25532235
复制相似问题