如何评估pymc3中的对数后验 [英] How to evaluate the log-posterior in pymc3

查看:84
本文介绍了如何评估pymc3中的对数后验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在样本点和一些手动输入的点(例如,合成数据集的真实参数值点)上评估对数后验(理想情况下分别对数先验和对数似然)值.如何在PyMC3中实现这一目标?

I want to evaluate the log posterior (ideally separately the log prior and log likelihood) values at sample points and at some manually entered points (e.g. the true parameter value points for synthetic datasets). How can I achieve this in PyMC3?

更新:我已经找到了 logp()方法,但是对多个点使用它不是很方便.有一些标准/惯用的方法吗?

Update: I've found the logp() method, however it's not very convenient to use for multiple points. Is are there some standard / idiomatic approach?

更新: [[y.logp(trace [i])for i in range(len(trace))] 可以工作,但是速度很慢.

Update: This [y.logp(trace[i]) for i in range(len(trace))] works, but is superslow.

更新:缓慢是由 y 是观察到的随机变量引起的,因此调用模型的 logp 方法会很快.

Update: Slowness was caused by the fact that y is the observed random variable, calling logp method of the model works fast.

推荐答案

好的,实际上是最好在其

OK, the reality is that it's best to ask PyMC3 related questions on their discourse forum.

因此获得对数后验的值采样后使用

<代码>logp = mvg_model.logplnp = np.array([logp(trace.point(i,chain = c))在trace中的c.在range(len(trace))中的i

在采样期间保存它们使用

```

with model:
   llk = pm.Deterministic(likelihood_name, model.logpt)

```

这篇关于如何评估pymc3中的对数后验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆