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

Fix InverseGaussian cdf overflows #1882

Merged
merged 7 commits into from
Aug 9, 2024

Conversation

quildtide
Copy link
Contributor

Closes #1873

Originally I intended to just add clamp(z, 0, 1), but when I found the source of the overflow, I realized there was room for something better.

The original example in the issue, currently:

julia> d = InverseGaussian(1.65,590)
InverseGaussian{Float64}=1.65, λ=590.0)

julia> cdf(d, 2.)
Inf

julia> exp(logcdf(d, 2.))
0.9998791763271095

With this pull request:

julia> d = InverseGaussian(1.65,590)
InverseGaussian{Float64}=1.65, λ=590.0)

julia> cdf(d, 2.)
0.9998791763271095

julia> exp(logcdf(d, 2.))
0.9998791763271095

There is also a backup clamp just in case someone manages to go even further and break the primary fix.

@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.99%. Comparing base (47c040b) to head (a810907).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1882   +/-   ##
=======================================
  Coverage   85.99%   85.99%           
=======================================
  Files         144      144           
  Lines        8666     8666           
=======================================
  Hits         7452     7452           
  Misses       1214     1214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/univariate/continuous/inversegaussian.jl Outdated Show resolved Hide resolved
src/univariate/continuous/inversegaussian.jl Outdated Show resolved Hide resolved
test/univariate/continuous.jl Outdated Show resolved Hide resolved
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good!

test/univariate/continuous/inversegaussian.jl Show resolved Hide resolved
@devmotion devmotion merged commit 6e0f1dc into JuliaStats:master Aug 9, 2024
11 checks passed
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

Successfully merging this pull request may close these issues.

cdf of InverseGaussian
3 participants