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

InverseGamma logcdf method fails with invalid parameters when array is used #4340

Closed
ricardoV94 opened this issue Dec 14, 2020 · 3 comments
Closed

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Dec 14, 2020

The theano.tensor function gammaincc fails with a C code assertion that exits the process, when called with negative arguments. This function is now being called in the logcdf method of the InverseGamma distribution (and after #4331, in the logcdf of the Poisson distribution).

Using bound avoids the exception when a single value is evaluated. However, it fails when an array/tensor with one or multiple values is used, since bound is not lazy.

Should we be concerned about this? From the docstrings, it seems that all logcdf methods are intended to work with both scalars and arrays/tensors values.

pm.InverseGamma.dist(alpha=-1, beta=5).logcdf(1).eval()  # returns -np.inf
pm.InverseGamma.dist(alpha=1, beta=5).logcdf(-1).eval()  # returns -np.inf

pm.InverseGamma.dist(alpha=-1, beta=5).logcdf(np.array([1])).eval()  # fails assertion and exits process
pm.InverseGamma.dist(alpha=1, beta=5).logcdf(np.array([-1])).eval()  # fails assertion and exits process
pm.InverseGamma.dist(alpha=-1, beta=5).logcdf(np.array([1, 1])).eval()  # fails assertion and exits process

Error message:

python3: /home/ricardo/.theano/compiledir_Linux-5.4--generic-x86_64-with-glibc2.29-x86_64-3.8.5-64/tmpci20dxir/mod.cpp:240: double GammaQ(double, double): Assertion `(n > 0) && (x >= 0)' failed.
@ricardoV94 ricardoV94 changed the title InverseGamma logcdf method fails with invalid parameters when multiple values are being evaluated InverseGamma logcdf method fails with invalid parameters when array of values is used Dec 14, 2020
@ricardoV94 ricardoV94 changed the title InverseGamma logcdf method fails with invalid parameters when array of values is used InverseGamma logcdf method fails with invalid parameters when array is used Dec 14, 2020
@ricardoV94
Copy link
Member Author

Same issue occurs with the Gamma distribution logcdf method as it relies on the gammainc, which also asserts values at the C level code

@ricardoV94
Copy link
Member Author

ricardoV94 commented Jan 3, 2021

Fixed by #4393. Fix can be reverted once this Theano issue is fixed: aesara-devs/aesara#224

In the meantime feel free to close this issue.

@twiecki
Copy link
Member

twiecki commented Jan 3, 2021

Thanks @ricardoV94 for the deep dive into this!

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