Add Generalized Pareto (GPD) and Extended GPD distributions#638
Draft
maresb wants to merge 4 commits intopymc-devs:mainfrom
Draft
Add Generalized Pareto (GPD) and Extended GPD distributions#638maresb wants to merge 4 commits intopymc-devs:mainfrom
maresb wants to merge 4 commits intopymc-devs:mainfrom
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.
ricardoV94
reviewed
Feb 5, 2026
| from scipy import stats | ||
|
|
||
|
|
||
| class GenParetoRV(RandomVariable): |
Member
There was a problem hiding this comment.
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>
Collaborator
Author
|
Thanks for the tip @ricardoV94!!! |
Member
|
Should we try to implement these distributions here https://github.com/pymc-devs/distributions? |
Collaborator
Author
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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