feat(distributions): add LogNormal distribution#331
Open
Sumu004 wants to merge 1 commit into
Open
Conversation
Adds distrax.LogNormal(loc, scale) — the Log-Normal distribution on
(0, ∞), where log(X) ~ Normal(loc, scale).
The Log-Normal arises naturally wherever multiplicative noise is
present: financial returns, rainfall intensity, protein expression
levels, and many Bayesian model priors.
Implements:
- log_prob(x) = Normal(mu, sigma).log_prob(log x) − log x
- mean() = exp(μ + σ²/2)
- variance() = (exp(σ²)−1) * exp(2μ+σ²)
- mode() = exp(μ − σ²)
- median() = exp(μ)
- entropy() = μ + ½ + log(σ) + ½ log(2π) (exact closed form)
- kl_divergence(other): delegates to the underlying Normal KL when
other is also LogNormal (analytic, equals Normal KL in log-space)
Adds distrax.LogNormal to the public __init__.py and 17 tests covering
log_prob against both TFP and scipy, mean/variance/mode/median/entropy
against TFP, KL divergence, sample shape/positivity/moments, and JIT.
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.
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
log_prob(x)Normal(μ,σ).log_prob(log x) − log xmean()exp(μ + σ²/2)variance()(exp(σ²)−1) · exp(2μ+σ²)mode()exp(μ − σ²)median()exp(μ)entropy()μ + ½ + log(σ) + ½ log(2π)(exact)kl_divergencesample()exp(Normal(μ,σ).sample())— reparameterizableTests
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.