Can I use infer_discrete() to get the posterior distribution of discrete latent variables?

Hi, guys, I’m a begginer of pyro. My question is:
infer_discrete() can get the map value of discrete latent sample site according to observation. So I guess there is a way to get the corresponding posterior distribution, where the map value comes from?

The only way I know to get the distribution is using sampling to approximate by running the api for multiple times with temperature as 1. But this method seems indirect and computation-consuming.
Is thers any misunderstanding of this api or anything I ignore?


1 Like

Hi @lyy, Indeed the recommended way to get the posterior joint distribution over discrete latent variables is to draw samples using infer_discrete(…, temperature=1). In general there is no compact representation of the posterior joint distribution. However if you are interested instead in posterior marginal distributions (one distribution per discrete latent variable), then the recommended way is to use TraceEnum_ELBO.compute_marginals(). Note however that those marginals are only correct if there are no upstream continuous latent variables. For example they are correct if all your latent variables are discrete and enumerated.

1 Like