【发布时间】:2016-03-15 09:31:56
【问题描述】:
我正在尝试实现 Lee&Wagenmakers 的书(第 5.5 章,第 70 页)中的删失数据示例。在pymc2中,我有以下模型:
nattempts = 950
nfails = 949
n = 50 # Number of questions
y = np.zeros(nattempts)
y[nattempts-1] = 1
z = 30
unobsmin = 15
unobsmax = 25
unobsrange = np.arange(unobsmin,unobsmax+1)
theta = pymc.Uniform("theta",lower = .25, upper = 1)
@pymc.observed
def Ylike(value=z, theta = theta, n=n, censorn=nfails, unobs=unobsrange):
ylikeobs = pymc.binomial_like(x=value, n=n, p=theta)
ylikeunobs = np.array([])
for i in unobs:
ylikeunobs = np.append(pymc.binomial_like(x=i, n=n, p=theta),ylikeunobs)
return ylikeobs+sum(ylikeunobs)*censorn
testmodel = pymc.Model([theta,Ylike])
mcmc = pymc.MCMC(testmodel)
mcmc.sample(iter = 20000, burn = 50, thin = 2)
涉及到装饰者@pymc.observed。
我想我需要使用pm.DensityDist 来表达可能性,但是我不知道该怎么做。
【问题讨论】:
-
这个答案可能会帮助您指出正确的方向。 stackoverflow.com/questions/22015055/…