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

Nutpie and PYMC Hurdle Gamma Distribution #163

Open
zwelitunyiswa opened this issue Dec 3, 2024 · 5 comments
Open

Nutpie and PYMC Hurdle Gamma Distribution #163

zwelitunyiswa opened this issue Dec 3, 2024 · 5 comments

Comments

@zwelitunyiswa
Copy link

Pardon my ignorance, but I cannot get nutpie to sample from PYMC's hurdle-gamma likelihood.

I get "TypeError: The fgraph of ScalarLoop must be exclusively composed of scalar operations."

Is this just not possible at this time?

Screenshot 2024-12-03 at 11 18 51 AM
@aseyboldt
Copy link
Member

This looks like an issue with the numba backend of pytensor.
Can you provide an example I can run to further debug this?

In the meantime, you can also give the jax backend a go:

compiled = nutpie.compile_pymc_model(model, backend="jax", gradient_backend="jax")
trace = nutpie.sample(compiled)

@zwelitunyiswa
Copy link
Author

Sure. Here is a simple model that replicates the error:

x = pm.HurdleGamma.dist(psi=.2, alpha=1, beta=2)
x_draws = pm.draw(x, draws=500, random_seed=1)
data = pd.DataFrame({'variable':x_draws})

with pm.Model() as model:
    
    alpha = pm.HalfNormal("alpha", sigma=2)
    beta = pm.HalfNormal("beta", sigma=2)
    psi = pm.Beta("psi", alpha=2, beta=2)

    obs = pm.HurdleGamma("obs", psi=psi, alpha=alpha, beta=beta, observed=data)

    idata = pm.sample(nuts_sampler='nutpie')

This fails with the same "TypeError: The fgraph of ScalarLoop must be exclusively composed of scalar operations."

@zwelitunyiswa
Copy link
Author

compiled = nutpie.compile_pymc_model(model, backend="jax", gradient_backend="jax")
trace = nutpie.sample(compiled)

I tried that with the simple model above and I got this a "RuntimeError: All initialization points failed" error. Image attached.

Screenshot 2024-12-03 at 12 18 33 PM

@aseyboldt
Copy link
Member

Sorry for the delay.
I opened a pytensor issue for the problem.

@zwelitunyiswa
Copy link
Author

No worries. Thank you for looking into it and opening the issue.

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

No branches or pull requests

2 participants