[英]Posterior Predictive Check on PyMC3 Deterministic Variable
TL; TL; DR
DR
What's the right way to do posterior predictive checks on pm.Deterministic
variables that take stochastics (rendering the deterministic also stochastic) as input? 在
pm.Deterministic
上进行后验预测检查的正确方法是什么?将随机性(呈现确定性也随机性)作为输入的确定性变量?
Too Short; 太短; Didn't Understand
没听懂
Say we have a pymc3
model like this: 假设我们有一个像这样的
pymc3
模型:
import pymc3 as pm
with pm.Model() as model:
# Arbitrary, trainable distributions.
dist1 = pm.Normal("dist1", 0, 1)
dist2 = pm.Normal("dist2", dist1, 1)
# Arbitrary, deterministic theano math.
val1 = pm.Deterministic("val1", arb1(dist2))
# Arbitrary custom likelihood.
cdist = pm.DensityDistribution("cdist", logp(val1), observed=get_data())
# Arbitrary, deterministic theano math.
val2 = pm.Deterministic("val2", arb2(val1))
I may be misunderstanding, but my intention is for the posteriors of dist1
and dist2
to be sampled, and for those samples to fed into the deterministic variables. 我可能会误会,但我的意图是要对
dist1
和dist2
进行采样,并将这些采样输入确定性变量中。 Is the posterior predictive check only possible on observed random variables? 只能对观察到的随机变量进行后验预测检查吗?
It's straightforward to get posterior predictive samples from dist2
and other random variables using pymc3.sampling.sample_ppc
, but the majority of my model's value is derived from the state of val1
and val2
, given those samples. 使用
pymc3.sampling.sample_ppc
从dist2
和其他随机变量中获取后验预测样本dist2
pymc3.sampling.sample_ppc
,但是给定了这些样本,我模型的大部分值来自val1
和val2
的状态。
The problem arises in that pm.Deterministic(.)
seems to return a th.TensorVariable
. 问题出现在
pm.Deterministic(.)
似乎返回th.TensorVariable
。 So, when this is called: 因此,在调用此方法时:
ppc = pm.sample_ppc(_trace, vars=[val1, val2])["val1", "val2"]
...and pymc3
attempts this block of code in pymc3.sampling
: ...和
pymc3
试图在这个代码块pymc3.sampling
:
410 for var in vars:
--> 411 ppc[var.name].append(var.distribution.random(point=param,
412 size=size))
...it complains because a th.TensorVariable
obviously doesn't have a .distribution
. ...抱怨是因为
th.TensorVariable
显然没有.distribution
。
So, what is the right way to carry the posterior samples of stochastics through deterministics? 那么,通过确定性方法携带随机后验样本的正确方法是什么? Do I need to explicitly create a
th.function
that takes stochastic posterior samples and calculates the deterministic values? 我需要明确地创建一个
th.function
是采取随机采样后,计算确定性值? That seems silly given the fact that pymc3
already has the graph in place. 鉴于
pymc3
已经具有图形的事实,这似乎很愚蠢。
Yes, I was misunderstanding the purpose of .sample_ppc
. 是的,我误解了
.sample_ppc
的目的。 You don't need it for unobserved variables because those have samples in the trace. 对于未观察到的变量,您不需要它,因为这些变量在跟踪中都有样本。 Observed variables aren't sampled from, because their data is observed, thus you need
sample_ppc
to generate samples. 由于不会观察到变量,因此不会对其进行采样,因此您需要
sample_ppc
来生成样本。
In short, I can gather samples of the pm.Deterministic
variables from the trace. 简而言之,我可以从跟踪中收集
pm.Deterministic
变量的样本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.