Skip to content

Add icdf for Wald distribution#8357

Draft
TalenMud wants to merge 1 commit into
pymc-devs:mainfrom
TalenMud:add-wald-icdf
Draft

Add icdf for Wald distribution#8357
TalenMud wants to merge 1 commit into
pymc-devs:mainfrom
TalenMud:add-wald-icdf

Conversation

@TalenMud

Copy link
Copy Markdown

Description

Adds icdf (inverse CDF / quantile function) for the Wald (Inverse Gaussian) distribution, as part of the broader effort to implement ICDF methods across all distributions.

Currently a draft skeleton with parameter checks is in place. ICDF formula and tests to follow.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@TalenMud

Copy link
Copy Markdown
Author

Hi, I've been researching the Wald ICDF implementation and found that unlike many other distributions it has no closed-form quantile function. The most reliable approach appears to be a Newton's method iteration started from the mode of the distribution, as described in Giner & Smyth (2016) "statmod: Probability Calculations for the Inverse Gaussian Distribution" https://arxiv.org/abs/1603.06687. This guarantees monotonic convergence for all parameter values.

Before proceeding I wanted to check, is the preferred approach to implement this as a proper Newton iteration using pytensor.scan, or would a scipy wrapper via SplineWrapper be more appropriate for PyMC's codebase? I'm keen to go with the full Newton implementation as it gives full machine accuracy and works for all parameter values, but happy to go the scipy wrapper route if that's what the maintainers prefer.

@ricardoV94

Copy link
Copy Markdown
Member

@TalenMud sorry for the delay and thanks for the initiative. Yes we've ran out of closed form solutions. You can check how #8339 does a binary search for discrete variables. For continuous you'll likely need something like you said.

If you want to look at an implementation boost has one here: https://github.com/boostorg/math/blob/8ee12a5355935cbaac5d5338372d0d0e3311b473/include/boost/math/distributions/inverse_gaussian.hpp#L343-L402

They are usually not how you'd write in PyMC/PyTensor but can be helpful as a reference. Feel free to take a stab. Note PyTensor has a minimize/root Ops that we can use if that's simpler than rolling a custom Scan

@TalenMud

Copy link
Copy Markdown
Author

Thanks for the pointers! I'll take a look at the Boost implementation and #8339 for the pattern. I'll also check out the PyTensor root Ops as the approach, it sounds better than rolling a custom Scan.

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.

2 participants