Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No posterior samples when using categorical distribution [bug] #3368

Open
joshuaspear opened this issue May 17, 2024 · 0 comments
Open

No posterior samples when using categorical distribution [bug] #3368

joshuaspear opened this issue May 17, 2024 · 0 comments
Labels

Comments

@joshuaspear
Copy link

joshuaspear commented May 17, 2024

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()
samples
@fritzo fritzo added the bug label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants