我正在尝试使用pymc来解决一个简单的模型:
我知道N = 1000个通量来自帕累托分布:通量〜帕累托(alpha,1)
我正在尝试计算帕累托的alpha参数:alpha~Uniform(1,3)
我的通量测量被高斯噪声污染:flux_meas~Gurssian(flux,tau)
目前,我只想模拟如果我改变噪音量会发生什么。
问题在于,当我运行具有非常小(即可忽略的)噪声量的模型时,alpha的平均值会在每次运行时发生根本变化,并且似乎与alpha的真实值无关一点都不但是,如果我完全忽略高斯噪声,并说我只是直接观察帕累托分布,它就会按预期工作。
我做错了什么?
关键位如下:
import pymc
N = 1000
true_alpha = 2
noise = 0.001 # This noise is much smaller than the signal
# Simulated fluxes
s_arr = pymc.rpareto(true_alpha, 1, size=N)
# the unknown alpha
alpha = pymc.Uniform('alpha', 1, 3)
# fluxes are drawn from a Pareto distribution
flux = pymc.Pareto('flux', alpha, 1, size=N)
# My observed fluxes are contaminated by Gaussian noise
flux_meas = pymc.Normal('flux_meas', mu=flux, tau=noise**-2, observed=True,
value=pymc.rnormal(s_arr, tau=noise**-2, size=N))
model = pymc.MCMC([alpha, flux, flux_meas])
# If I run this model several times, the mean of alpha will be somewhere between
# 1 and 3. The variance of alpha is pretty small
model.sample(5000, 1000, 5)
答案 0 :(得分:0)
上面的模型对我来说运行良好:
In [5]: alpha.summary()
alpha:
Mean SD MC Error 95% HPD interval
------------------------------------------------------------------
2.473 0.079 0.005 [ 2.317 2.612]
Posterior quantiles:
2.5 25 50 75 97.5
|---------------|===============|===============|---------------|
2.317 2.422 2.474 2.522 2.613
如何诱导您报告的高度可变输出?请记住,alpha
指定的统一变量不是alpha变体的模型,它是先验变量,因此在alpha
中指定了我们的不确定性。