Skip to content

Add GenPareto and ExtGenPareto distributions#53

Draft
maresb wants to merge 2 commits into
pymc-devs:mainfrom
maresb:add-genpareto-distributions
Draft

Add GenPareto and ExtGenPareto distributions#53
maresb wants to merge 2 commits into
pymc-devs:mainfrom
maresb:add-genpareto-distributions

Conversation

@maresb
Copy link
Copy Markdown

@maresb maresb commented May 6, 2026

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 in ppf/isf/rvs/median so a single formula handles all xi including the xi = 0 limit.
  • _log1p_ratio(xi, z) = log1p(xi*z)/xi — used in logpdf/cdf/logcdf/sf/logsf for the same reason; falls back to a Taylor expansion to avoid 0/0 near xi*z = 0 and to avoid inf * 0 near the boundary.
  • _safe_mul materialises 0 * inf to 0 so PyTensor's constant folding stays consistent across consumers.
  • rvs samples 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 pass
  • full suite (pytest) — 537 passed, no regressions

GPD is tested against scipy.stats.genpareto via the existing run_distribution_tests harness. ExtGPD has no scipy equivalent and is tested against numpy reference implementations built on scipy.stats.genpareto, including a kappa=1 reduction-to-GPD check and a KS goodness-of-fit test for rvs.

🤖 Generated with Claude Code

maresb and others added 2 commits May 6, 2026 14:54
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>
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.

1 participant