Skip to content

No posterior samples when using categorical distribution [bug] - #3463

Open
aBiR1D wants to merge 1 commit into
pyro-ppl:devfrom
aBiR1D:fix-no-posterior-samples-when-using-categori-8
Open

No posterior samples when using categorical distribution [bug]#3463
aBiR1D wants to merge 1 commit into
pyro-ppl:devfrom
aBiR1D:fix-no-posterior-samples-when-using-categori-8

Conversation

@aBiR1D

@aBiR1D aBiR1D commented Jul 24, 2026

Copy link
Copy Markdown

Fixes #3368
Add automatic discrete variable sampling to MCMC.get_samples()

Modified MCMC.get_samples() to automatically include posterior samples of discrete latent variables that were enumerated during inference, using forward-filtering backward-sampling via infer_discrete. Previously, categorical and other discrete distributions were marginalized out during MCMC but not included in the returned samples, causing confusion for users.

Modified MCMC.get_samples() to automatically include posterior samples of discrete latent variables that were enumerated during inference, using forward-filtering backward-sampling via infer_discrete. Previously, categorical and other discrete distributions were marginalized out during MCMC but not included in the returned samples, causing confusion for users.

Changes
pyro/infer/mcmc/api.py: Added include_discrete parameter to get_samples() method; capture prototype trace during sampling; use infer_discrete to sample discrete latent variables from their posterior when include_discrete=True (default)
tests/infer/mcmc/test_discrete_samples.py: Added comprehensive tests for discrete variable sampling in MCMC with various configurations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No posterior samples when using categorical distribution [bug]

1 participant