Skip to content

Add generalized inverse Gaussian and generalized hyperbolic #1982

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ForceBru
Copy link

@ForceBru ForceBru commented Jun 4, 2025

This is at least the third attempt at implementing the generalized inverse Gaussian (GIG) distribution to close #554. Previous attempts by other people: #587 (closed, last activity in 2019), #1300 (open, last activity in 2021).

Features of this implementation:

  1. rand closely follows Devroye, Luc. 2014. “Random Variate Generation for the Generalized Inverse Gaussian Distribution.” Statistics and Computing 24 (2): 239–46. https://doi.org/10.1007/s11222-012-9367-z. Single algorithm for all values of parameters, as opposed to multiple algos in Add Generalized inverse Gaussian Distribution #1300. In my evaluation, the Kolmogorov-Smirnov test fails to reject the null, thus verifying that samples agree with the true GIG for multiple parameter values.
  2. Has documentation.
  3. Implements PDF, CDF (via quadgk), mean, variance, MGF, CF etc from Wikipedia and Wolfram Mathematica.
  4. I want to work on this implementation because I need it.

I also implemented, documented and tested the generalized hyperbolic distribution with sampling based on GIG. This probably should be a separate pull request, but they're very related, so the generalized hyperbolic is here for now.

@ForceBru
Copy link
Author

ForceBru commented Jun 4, 2025

One design issue I'm not sure how to solve is implementing multiple parameterizations of the same distribution. In particular, I want the usual $\mathrm{GIG}(a,b,p)$ as well as Wolfram's $\mathrm{GIG}(\mu,\lambda,\theta)$. Both have 3 parameters, so I can't implement two different methods with the same number of params. I tried to implement Wolfram's parameterization as a function with required keyword params like GeneralizedInverseGaussian(; mu::Real, lambda::Real, theta::Real=-1/2), but now one test is failing (e.g. https://github.com/JuliaStats/Distributions.jl/actions/runs/15453605220/job/43501263178?pr=1982#step:6:619) because these lines try to call it without any arguments:

filter!(x -> hasmethod(x, ()), dists)
filter!(x -> isbounded(x()), dists)


Wolfram Language parameterization, equivalent to `InverseGamma(μ, λ)`
"""
GeneralizedInverseGaussian(; μ::Real, λ::Real, θ::Real=-1/2) =
Copy link
Author

Choose a reason for hiding this comment

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

Here I wanted to have a different parameterization, but tests assume that one can call GeneralizedInverseGaussian() with no arguments. The test fails because GeneralizedInverseGaussian has mandatory keyword arguments here.

@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 90.04329% with 23 lines in your changes missing coverage. Please review.

Project coverage is 86.38%. Comparing base (46bb0c3) to head (4e4db5f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/univariate/continuous/generalizedhyperbolic.jl 87.70% 15 Missing ⚠️
...nivariate/continuous/generalizedinversegaussian.jl 92.66% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1982      +/-   ##
==========================================
+ Coverage   86.28%   86.38%   +0.09%     
==========================================
  Files         146      148       +2     
  Lines        8787     9018     +231     
==========================================
+ Hits         7582     7790     +208     
- Misses       1205     1228      +23     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ForceBru ForceBru changed the title Add generalized inverse Gaussian (again) Add generalized inverse Gaussian and generalized hyperbolic Jun 5, 2025
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.

Generalized inverse Gaussian
2 participants