【问题标题】:logp in stochastic variables of pymclogp 在 pymc 的随机变量中
【发布时间】:2014-05-29 22:52:28
【问题描述】:

我对 logp 有一个非常内在的困惑。我想通过网页上的一个例子来解释,这样我就不会解释不好。

我按照本教程的说明编写了灾难模型.py: http://pymc-devs.github.io/pymc/tutorial.html

我启动了一个 python shell 并在导入所有必需的模块后,我做了以下操作

In [2]: import disaster_model
Out[2]: -2.9780301980174

In [3]: disaster_model.switchpoint.logp
Out[3]: -4.709530201312334

In [4]: disaster_model.late_mean.logp
Out[4]: -2.407183392124894

In [5]: disaster_model.early_mean.logp
Out[5]: -2.9780301980174

M = MCMC(disaster_model)
M.sample(iter = 10000, burn = 1000, thin = 10)

In [11]: M.switchpoint.logp
Out[11]: -4.709530201312334

In [12]: M.early_mean.logp
Out[12]: -3.2263189370368117

In [13]: M.late_mean.logp
Out[13]: -0.9012784557735074

In [14]: M.disasters.logp
Out[14]: -164.37141285002255

我会再次强调这一行(写在disaster_model.py中)

disasters = Poisson('disasters', mu=rate, value=disasters_array, observed=True

因此,灾难的价值永远不会改变。

现在我的问题是

1) 为什么除了switchpoint之外的每个变量的log概率都会发生变化?

(请解释为什么日志概率应该改变,如果应该改变,那么为什么 swithpoint 没有改变)

2) 新旧日志概率分别代表什么?

(这是 ipython shell 而不是 python,但这并不重要)

【问题讨论】:

    标签: python distribution pymc mcmc


    【解决方案1】:

    回复比较晚,但无论如何。您的问题。

    1) 为什么除了switchpoint之外的每个变量的log概率都会发生变化?

    logp 属性给出了一个变量的对数概率,给定它的父级。 switchpoint 的先验分布是从 0 到 110 年的离散均匀分布,其父级是均匀分布的上下界。不管switchpoint的值是多少,它的概率质量都是1/111,所以它的先验对数概率是ln(1/111) = -4.70953,这个永远不会改变。

    当 MCMC 算法在随机变量空间中跳跃时,其他变量(early_meanlate_mean)的对数概率会发生变化,因为它们的先验分布被定义为指数分布,而不是均匀分布。

    2) 新旧日志概率代表什么?

    在您的问题中,对数概率表示随机变量 early_meanlate_meanswitchpoint 的“当前”值的对数先验概率。您可以通过评估np.log(scipy.stats.expon.pdf(M.early_mean.value, scale=1)) 并与M.early_mean.logp 进行比较,自己验证early_mean。注意指数分布中的尺度参数反映了disaster_model.py中定义的尺度参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多