-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
BUG: ICDF implementation for the discrete geometric distribution fails some tests. #6670
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
Comments
Floating point is tricky. Nice investigation. Instead of truncating the number, maybe we can do as Scipy does? They manually check if if the logcdf disagrees, and tweak the value down: |
Created a pull request with a fix here #6671. |
Yes, it is. Thank you. 👍
Let me get back after I check this. |
Yes the scipy approach sounds like a good idea, more computation (CDF is computed again) but also less error prone. Let me implement this and get back. Is there any deadline for any release due to which this bug will be a blocker? |
No. I wouldn't count this as a blocker bug, or even a bug bug. More of a precision issue. We will merge the solution whenever it's ready and the subsequent release will incorporate it. No rush |
I have pushed code with the suggested changes in #6671. |
Describe the issue:
The ICDF function for the discrete geometric distribution involves the ceiling function applied on a ratio of two values which is a floating point number. If this ratio is close to an integer, a small noise added to it even in the smallest digit of precision can sway the result of the ceiling function to the other side resulting in a wrong ICDF value.
The example code below is for an example of a Geometric distribution with
p=0.99
, and CDF value0.9999
whose ICDF is expected to be2
. Within the ICDF function, defining the ratioa = pt.log1p(-value) / pt.log1p(-p)
The tiny numerical error
000000000000025
contributes to the wrong value after ceil.I also have a solution to this, which involves truncating the floating point value to a certain number of digits before using the ceiling function on it. This gets rid of the sensitivity to the smallest of noise. I will push a commit with this fix shortly.
Reproduceable code example:
Error message:
PyMC version information:
pytensor: 2.10.1
Python: 3.10.10
PyMC: latest commit 2a324bc
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: