我对logp有一种内在的困惑。我想通过一个在na网页上的例子来解释,这样我就不会缺少对它的解释。
如本教程所示,我编写了disaster_model.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) 为什么除了开关点外,每个变量的日志概率都会发生变化?
(请解释为什么日志概率应该改变,如果应该的话,那么为什么swithpoint没有改变)
2) 新旧日志概率代表什么?
(它是ipython shell,而不是python,但它并不重要)
发布于 2015-01-26 11:56:21
很晚才回复,但无论如何。你的问题。
1)为什么除了开关点外,每个变量的日志概率都会发生变化?
logp属性给出了给定其父变量的变量的日志概率。switchpoint的先验分布是0~110年的离散均匀分布,其父分布是均匀分布的上下界。无论考虑switchpoint的哪个值,其概率质量为1/111,故其先验对数概率为ln(1/111) = -4.70953,且不变。
由于其它变量(early_mean和late_mean)的先验分布被定义为指数分布而不是均匀分布,因此当它们在随机变量空间中跳跃时,其对数概率会发生变化。
2)新旧日志概率代表什么?
在您的问题中,日志概率表示随机变量early_mean、late_mean和switchpoint的对数先验概率,表示它们的“当前”值。您可以通过评估early_mean并与M.early_mean.logp进行比较来验证这一点。注意,指数分布中的比例参数反映了disaster_model.py中定义的刻度参数。
https://stackoverflow.com/questions/23944314
复制相似问题