Add GenPareto and ExtGenPareto distributions#53
Draft
maresb wants to merge 2 commits into
Draft
Conversation
Implements the Generalized Pareto and Extended Generalized Pareto distributions with the full functional API (logpdf, pdf, cdf, logcdf, sf, logsf, ppf, isf, rvs, mean, median, mode, var, std, entropy, skewness, kurtosis). Numerical primitives _exprel and _log1p_ratio give a single formula that stays accurate for all xi (including the xi=0 limit and the xi*z -> -1 boundary). Ports pymc-devs/pymc-extras#638 to the pytensor-distributions functional API. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Drops redundant one-line docstrings on public distribution functions so genpareto/extgenpareto match the convention used by pareto, matrixnormal, polyagamma, etc., and resolves the remaining D401 ruff failures. Also demotes the rvs numerical-trick note to a regular comment. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Adds the Generalized Pareto Distribution (GPD) and Extended Generalized Pareto Distribution (ExtGPD) following this repo's functional, one-file-per-distribution layout.
Each distribution provides the full API surface used elsewhere in the package:
logpdf,pdf,cdf,logcdf,sf,logsf,ppf,isf,rvs,mean,median,mode,var,std,entropy,skewness,kurtosis. ExtGPD reuses GPD primitives where possible (_gpd_isf,_log1p_ratio,_safe_mul,_upper_bound).This is a port of pymc-devs/pymc-extras#638, reshaped from PyMC's class-based distribution API to this repo's flat-function style and extended with the additional moments/quantile functions the package expects.
Numerical notes
_exprel(t) = (exp(t) - 1) / t— used inppf/isf/rvs/medianso a single formula handles allxiincluding thexi = 0limit._log1p_ratio(xi, z) = log1p(xi*z)/xi— used inlogpdf/cdf/logcdf/sf/logsffor the same reason; falls back to a Taylor expansion to avoid0/0nearxi*z = 0and to avoidinf * 0near the boundary._safe_mulmaterialises0 * infto0so PyTensor's constant folding stays consistent across consumers.rvssamples by inverse CDF (-expm1(log(u)/kappa)for ExtGPD's GPD survival probability) — backend-agnostic, no rejection sampling, numerically stable in the upper tail.Test plan
pytest tests/test_genpareto.py tests/test_extgenpareto.py— 76 tests, all passpytest) — 537 passed, no regressionsGPD is tested against
scipy.stats.genparetovia the existingrun_distribution_testsharness. ExtGPD has no scipy equivalent and is tested against numpy reference implementations built onscipy.stats.genpareto, including a kappa=1 reduction-to-GPD check and a KS goodness-of-fit test forrvs.🤖 Generated with Claude Code