我在探索有界分布在pymc中的应用。我试图在两个值之间绑定Gamma先验分布。由于缺少测试值,模型规范似乎失败了。如何传递testval参数,以便能够指定这些类型的模型?
为了完整起见,我已经包括了这个错误,以及下面的一个最小的例子。谢谢您!AttributeError: <pymc.quickclass.Gamma object at 0x110a62890> has no default value to use, checked for: ['median', 'mean', 'mode'] pass testval argument or provide one of these.
import pymc as pm
import numpy as np
ndims = 2
nobs = 20
zdata = np.random.normal(loc=0, scale=0.75, size=(ndims, nobs))
BoundedGamma = pm.Bound(pm.Gamma, 0.5, 2)
with pm.Model() as model:
xbound = BoundedGamma('xbound', alpha=1, beta=2)
z = pm.Normal('z', mu=0, tau=xbound, shape=(ndims, 1), observed=zdata)
编辑:为了便于参考,这里有一个使用有界伽马先验分布的简单工作模型:
import pymc as pm
import numpy as np
ndims = 2
nobs = 20
zdata = np.random.normal(loc=0, scale=0.75, size=(ndims, nobs))
BoundedGamma = pm.Bound(pm.Gamma, 0.5, 2)
with pm.Model() as model:
xbound = BoundedGamma('xbound', alpha=1, beta=2, testval=2)
z = pm.Normal('z', mu=0, tau=xbound, shape=(ndims, 1), observed=zdata)
with model:
start = pm.find_MAP()
with model:
step = pm.NUTS()
with model:
trace = pm.sample(3000, step, start)
pm.traceplot(trace);
最佳答案
用那句话:
xbound = BoundedGamma('xbound', alpha=1, beta=2, testval=1)
关于python - 在pymc 3中提供测试值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19798958/