distrax icon indicating copy to clipboard operation
distrax copied to clipboard

feat(distributions): add LogNormal distribution

Open Sumu004 opened this issue 5 months ago • 1 comments

What does this PR do?

Adds distrax.LogNormal(loc, scale) — the Log-Normal distribution on (0, ∞). If X ~ LogNormal(μ, σ), then log(X) ~ Normal(μ, σ).

The Log-Normal arises naturally in probabilistic ML wherever multiplicative noise is present: financial returns, rainfall, protein expression, and many Bayesian model priors. Unlike Beta/Gamma (bounded or semi-bounded), LogNormal covers the full positive real line with a simple reparameterizable sampler.

Implemented

Method Formula
log_prob(x) Normal(μ,σ).log_prob(log x) − log x
mean() exp(μ + σ²/2)
variance() (exp(σ²)−1) · exp(2μ+σ²)
mode() exp(μ − σ²)
median() exp(μ)
entropy() μ + ½ + log(σ) + ½ log(2π) (exact)
kl_divergence Analytic when other is LogNormal (= Normal KL in log-space)
sample() exp(Normal(μ,σ).sample()) — reparameterizable

Tests

17 tests in log_normal_test.py: log_prob vs TFP and scipy, mean / variance / mode / median / entropy vs TFP, KL divergence (self=0, analytic vs TFP), sample shape, positivity, moments, JIT compatibility.

Sumu004 avatar Jun 04 '26 22:06 Sumu004

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

Sumu004 avatar Jul 10 '26 10:07 Sumu004