-
Notifications
You must be signed in to change notification settings - Fork 78
Add Generalized Pareto (GPD) and Extended GPD distributions #638
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
base: main
Are you sure you want to change the base?
Conversation
- Add GenPareto distribution for peaks-over-threshold extreme value modeling - Add ExtGenPareto distribution following Naveau et al. (2016) for modeling entire distributions without threshold selection - ExtGPD uses CDF G(x) = H(x)^kappa where H is the GPD CDF and kappa > 0 controls lower tail behavior (reduces to GPD when kappa = 1) - Include comprehensive tests for logp, logcdf, support_point, and random sampling
This enables PyMC's Truncated distribution to use inverse CDF sampling
instead of rejection sampling, which is critical when the truncation
probability is high (e.g., when kappa is small and most mass is below
the truncation threshold).
The inverse CDF for ExtGPD is: G^{-1}(p) = H^{-1}(p^{1/kappa})
where H^{-1} is the GPD quantile function.
| from scipy import stats | ||
|
|
||
|
|
||
| class GenParetoRV(RandomVariable): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How tricky is the rvs method to implement symbolically? If scipy is just doing inverse cdf sampling we could also do it.
In that case you would implement the RV as a SymbolicRV. The advantage of that is that the random methods work out of the box on the different backends.
Same for the other distribution
…iable
Switch from scipy-based RandomVariable to symbolic inverse CDF sampling.
This enables backend-agnostic random sampling (JAX, NumPy, etc.) by
implementing the inverse CDF transformation directly in PyTensor.
The inverse CDF for GPD is:
- mu + sigma * [(1-u)^(-xi) - 1] / xi for xi != 0
- mu - sigma * log(1-u) for xi = 0
For ExtGPD, we use the transformation u^{1/kappa} before applying the GPD
inverse CDF.
Co-authored-by: Claude AI
Co-authored-by: Cursor <cursoragent@cursor.com>
- Add _exprel helper for (exp(t)-1)/t with correct gradient at t=0 - Use survival probability directly to avoid 1-u cancellation in upper tail - For ExtGPD, compute GPD survival probability via -expm1(log(u)/kappa) Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the tip @ricardoV94!!! |
|
Should we try to implement these distributions here https://github.com/pymc-devs/distributions? |
|
Oh cool, thanks @aloctavodia! I wasn't aware of that. I'd be happy to move it over, but it may be a while before I can get to it. |
Note
AI Assistance Disclosure: This PR was developed with significant assistance from an AI coding assistant (Claude) via Cursor. The code has not yet been fully reviewed by the author.
Summary
This PR adds two new probability distributions to PyMC-Extras:
Features
logp,logcdf,icdf, andsupport_pointmethodsgenparetoicdfmethod enables efficient inverse CDF sampling when used withpm.Truncated, avoiding rejection sampling failuresMathematical Background
The ExtGPD CDF is defined as:
$$G(x \mid \mu, \sigma, \xi, \kappa) = \left[H\left(\frac{x - \mu}{\sigma}\right)\right]^\kappa$$
where$H$ is the standard GPD CDF. The parameter $\kappa > 0$ controls lower tail behavior, and when $\kappa = 1$ , ExtGPD reduces to standard GPD.
Test plan
pytest tests/distributions/test_continuous.py::TestGenParetoClass- GPD testspytest tests/distributions/test_continuous.py::TestExtGenParetoClass- ExtGPD testspytest tests/distributions/test_continuous.py::TestGenPareto- GPD random samplingpytest tests/distributions/test_continuous.py::TestExtGenPareto- ExtGPD random sampling