distrax icon indicating copy to clipboard operation
distrax copied to clipboard

feat(distributions): add Poisson distribution

Open Sumu004 opened this issue 5 months ago • 1 comments

What does this PR do?

Adds distrax.Poisson(rate) — the Poisson distribution with rate parameter λ > 0, implementing the interface requested in #164.

The Poisson distribution models the number of discrete events occurring at a constant rate. Its PMF is:

P(X = k) = λ^k * exp(-λ) / k!,   k = 0, 1, 2, …

Implemented methods

Method Notes
log_prob(k) k·log(λ) − λ − log Γ(k+1)
mean() λ
variance() λ
mode() floor(λ)
entropy() Numerical sum (no closed form)
kl_divergence(other) Analytic when other is also Poisson: λ₁ log(λ₁/λ₂) + λ₂ − λ₁
sample() Delegates to jax.random.poisson

Supports integer and floating-point dtype for samples, batched rate, and JIT compilation.

Tests

31 tests in poisson_test.py covering:

  • log_prob accuracy vs scipy.stats.poisson.logpmf for k = 0, 1, 3, 10
  • Mean, variance, mode correctness
  • Entropy vs scipy
  • KL divergence (analytic formula and self-divergence = 0)
  • Sample shape, non-negativity, moments (large-sample)
  • Integer and float dtype samples
  • JIT compatibility

Notes

  • entropy() is computed via a numerical sum (TFP's JAX substrate does not implement Poisson.entropy()). The window is chosen as min(λ + 10√λ + 30, 2000), which captures >99.999 % of probability mass for rates up to ~1000.
  • equiv_tfp_cls = tfd.Poisson is set for TFP interoperability.

Fixes #164

Sumu004 avatar Jun 04 '26 17:06 Sumu004

Friendly bump on this new Poisson distribution PR, open about a month with no review yet. Happy to adjust anything needed. Thanks!

Sumu004 avatar Jul 10 '26 10:07 Sumu004