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

ENH: special: add log of wright_bessel #20598

Closed
lorentzenchr opened this issue Apr 28, 2024 · 0 comments · Fixed by #20646
Closed

ENH: special: add log of wright_bessel #20598

lorentzenchr opened this issue Apr 28, 2024 · 0 comments · Fixed by #20646
Labels
enhancement A new feature or improvement scipy.special
Milestone

Comments

@lorentzenchr
Copy link
Contributor

lorentzenchr commented Apr 28, 2024

Is your feature request related to a problem? Please describe.

When the log-likelihood of a Tweedie distribution (compound Poisson-Gamma) is computed, one needs to evaluation np.log(wright_bessel(a, 0, x)) where 0<a<inf and x is potentially large. This can lead to inf or nan value, see statsmodels/statsmodels#9234.

Describe the solution you'd like.

Provide a new function log_wright_bessel that takes care for large x. Similar functions are

Describe alternatives you've considered.

No response

Additional context (e.g. screenshots, GIFs)

The implementation would be relatively straight forward:

  • wb_small_a: Replace multiplicative exp(x) * rgamma(b) by +x-loggamma(b)
  • wb_large_a: similar
  • wb_asymptotic: replace multiplicative std::pow(Z, 0.5 - b) * std::exp(Ap1[1] / a * Z) by +(0.5 - b) * log(Z) + Ap1[1] / a * Z

This would already work for most cases.

wright_bessel was introduced in v1.7.0 with PR #11313.

@lorentzenchr lorentzenchr added the enhancement A new feature or improvement label Apr 28, 2024
@lucascolley lucascolley added this to the 1.14.0 milestone May 7, 2024
@lucascolley lucascolley changed the title ENH: add log of wright_bessel ENH: special: add log of wright_bessel May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.special
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants