No posterior samples when using categorical distribution [bug]
Author: joshuaspearCreated May 17, 2024Updated Jul 23, 2026
Labelsbug
Issue Description
I have developed which depends on categorical distributions however, I am unable to obtain posterior samples. When running the code define in "Code snippet", I would expect an output of the form:
{"oil":[torch.tensor(0),...]}
Environment
For any bugs, please provide the following:
- OS and python version: GoogleCollab, Python 3.10
- PyTorch version, or if relevant, output of
pip freeze.: 2.2.1 - Pyro version: output of
python -c 'import pyro; print pyro.__version__': 1.9.0
Code Snippet
class Model:
def __init__(self):
pass
def __call__(self, oil_pr):
oil = pyro.sample("oil", dist.Categorical(oil_pr)) # 0,1,2
seis_dist = torch.tensor(
[
[0.1,0.3,0.6], # 0,1,2|0
[0.3,0.4,0.3], # 0,1,2|1
[0.5,0.4,0.1] # 0,1,2|2
]
)
seis = pyro.sample("seis", dist.Categorical(seis_dist[oil,:]))
return seis
pyro.clear_param_store()
model = Model()
conditioned_seis = pyro.condition(
belief_model, data={"seis": torch.tensor(1.0)})
hmc_kernel = HMC(conditioned_seis, step_size=0.9, num_steps=4)
posterior = MCMC(
hmc_kernel,
num_samples=10,
warmup_steps=50,
)
posterior.run(torch.tensor([1/3,1/3,1/3]))
samples = posterior.get_samples()
samplesSource: pyro-ppl/pyro