pymc3 模型在默认初始化的采样器中失败,但适用于 'map'

pymc3 Model fails in sampler with default init, but works with 'map'

在解决 "Statistical Rethinking" 中的问题时 - 我正在使用 pymc3 解决 "Salamanders" 问题 10H4。 (下面的代码)

采样器总是因错误而失败:

The derivative of RV alpha.ravel()[0] is zero.

但是当我将 init='map' 选项传递给采样器时,我得到了与使用 R code 的其他人相似的结果。 'map' init 选项在采样器的输出中被严重劝阻,但许多其他 init 选项也有问题。

数据为here

我已尝试按照与错误消息相关的网络搜索中的建议更改先验。

with pm.Model() as hw_10_4:
    alpha = pm.Normal('alpha',mu=0,sd=5)
    beta = pm.Normal('beta',mu=0,sd=5)
    l = pm.Deterministic('lambda',pm.math.exp(alpha + beta*pctcover))
    s = pm.Poisson('salam',l,observed=salaman)
    trace_10_4 = pm.sample(1000, tune=1000, init='map')

我得到了我想要的结果,但我有兴趣更多地了解我最初遇到问题的原因。我是 PYMC3 的新手,想完全了解发生了什么。

谢谢!

是的,PyMC3 似乎确实不能很好地处理全局缩放。很高兴 Stan 似乎不像 PyMC3 那样窒息,但实际上在这两种情况下,当回归预测变量标准化时,理想的抽样都会发生。 The unofficial port of some of the Statistical Rethinking code to PyMC3 does exactly this for that problem。 FWIW,我通常从 sklearn.preprocessing 导入 scale,它的行为与文本中使用的 R scale 相同。

至于使用 MAP init,这主要是 high-dimensional 预测器 space 的问题。我不会在这里只用一个预测器。