Distributions
This page lists Wren's built-in distributions.
Each distribution specifies whether it has a fast vectorised implementation of logdensityof when it occurs on the right-hand side of a tilde inside a @batch loop. If a distribution does not have a custom overload, Wren will fall back to a generic implementation using independent (semantically equal to Distributions.product_distribution). This is always correct, but may not necessarily be the most efficient implementation. In general, vectorised implementations are most useful for distributions that are used as likelihoods in models, where the log-density is evaluated over a large dataset. New implementations of vectorised log-densities are very much welcome!
Univariate
Continuous unbounded
WrenDists.Normal — Type
Normal(μ, σ)
Normal(μ)
Normal()Normal distribution with mean μ (default 0.0) and standard deviation σ (default 1.0).
Customised batched implementations: Yes
WrenDists.Laplace — Type
Laplace(μ, b)
Laplace(μ)
Laplace()Laplace distribution with location μ (default 0.0) and scale b (default 1.0).
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.Cauchy — Type
Cauchy(μ, σ)
Cauchy(μ)
Cauchy()Cauchy distribution with location μ (default 0.0) and scale σ (default 1.0).
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.Logistic — Type
Logistic(μ, θ)
Logistic(μ)
Logistic()Logistic distribution with location μ (default 0.0) and scale θ (default 1.0).
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.TDist — Type
TDist(ν, μ, σ)
TDist(ν, μ)
TDist(ν)Student's t distribution with ν degrees of freedom, location μ (default 0.0) and scale σ (default 1.0). The density is
\[p(x) = \frac{\Gamma\!\left(\frac{\nu+1}{2}\right)} {\Gamma\!\left(\frac{\nu}{2}\right)\sqrt{\nu\pi}\,\sigma} \left(1 + \frac{1}{\nu}\left(\frac{x-\mu}{\sigma}\right)^{2}\right) ^{-\frac{\nu+1}{2}}.\]
σ is a scale parameter, not a standard deviation: the variance is $σ^2 ν / (ν - 2)$ and exists only for $ν > 2$.
Customised batched implementations: Yes
WrenDists.Flat — Type
Flat()
Flat{T}()Improper flat distribution over the real line, i.e. a log-density of zero everywhere.
This is mostly useful as a prior when you want the posterior to be determined by the likelihood alone (like a parameter without a prior in Stan).
Since this isn't a proper distribution, rand can't draw from it. Instead it returns a value drawn uniformly from (-2, 2), which is the same range that Stan uses to initialise unconstrained parameters.
Since there are no parameters to take the type of samples from, it is given by T, which defaults to Float64.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
Continuous $\mathbb{R}^+$
WrenDists.LogNormal — Type
LogNormal(μ, σ)
LogNormal(μ)
LogNormal()Log-normal distribution with log-scale mean μ (default 0.0) and log-scale standard deviation σ (default 1.0).
Customised batched implementations: Yes
WrenDists.Exponential — Type
Exponential(θ)
Exponential()Exponential distribution with scale θ (default 1.0).
Customised batched implementations: Yes
WrenDists.Gamma — Type
Gamma(α, θ)
Gamma(α)
Gamma()Gamma distribution with shape α (default 1.0) and scale θ (default 1.0).
Customised batched implementations: Yes
WrenDists.InverseGamma — Type
InverseGamma(α, θ)
InverseGamma(α)
InverseGamma()Inverse gamma distribution with shape α (default 1.0) and scale θ (default 1.0). If X ~ Gamma(α, 1/θ), then 1/X ~ InverseGamma(α, θ).
Customised batched implementations: Yes
WrenDists.Weibull — Type
Weibull(α, θ)
Weibull(α)
Weibull()Weibull distribution with shape α (default 1.0) and scale θ (default 1.0).
Customised batched implementations: Yes
WrenDists.HalfNormal — Type
HalfNormal(μ, σ)
HalfNormal()Normal distribution with mean μ (default 0.0) and standard deviation σ (default 1.0), truncated to [0, ∞).
The log normalising constant, including the log probability log Φ(μ/σ) that the untruncated normal assigns to [0, ∞), is computed on construction and stored in the struct.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.HalfCauchy — Type
HalfCauchy(μ, σ)
HalfCauchy()Cauchy distribution with location μ (default 0.0) and scale σ (default 1.0), truncated to [0, ∞).
The log normalising constant, including the log probability that the untruncated Cauchy assigns to [0, ∞), is computed on construction and stored in the struct.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.HalfTDist — Type
HalfTDist(ν, μ, σ)
HalfTDist(ν, μ)
HalfTDist(ν)Student's t distribution with ν degrees of freedom, location μ (default 0) and scale σ (default 1), truncated to [0, ∞).
σ is a scale parameter, not a standard deviation.
The log normalising constant, including the log probability that the untruncated distribution assigns to [0, ∞), is computed on construction and stored in the struct. That probability needs a regularized incomplete beta integral, so the saving is largest when one HalfTDist scores many values.
Sampling inverts the distribution function with a Newton solve, so a draw takes one uniform noise value whatever μ/σ is.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.PositiveFlat — Type
PositiveFlat()
PositiveFlat{T}()Improper flat distribution over the positive real line, i.e. a log-density of zero for x >= 0 and -Inf otherwise.
Since this isn't a proper distribution, rand can't draw from it. Instead it returns exp(u) where u is drawn uniformly from (-2, 2), which is the same way that Stan initialises positive parameters. The optional type parameter T can be used to specify the sample type, e.g. PositiveFlat{Float32}().
This is like a Stan real<lower=0> parameter without a prior.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
Continuous bounded
WrenDists.Uniform — Type
Uniform(a, b)
Uniform()Continuous uniform distribution on the interval [a, b] (defaults to [0.0, 1.0]).
Customised batched implementations: Yes
WrenDists.Beta — Type
Beta(α, β)
Beta()Beta distribution with shape parameters α (default 1.0) and β (default 1.0).
Customised batched implementations: Yes
WrenDists.TruncatedFlat — Type
TruncatedFlat(lower, upper)Flat distribution on the finite interval [lower, upper], i.e. a log-density of zero inside the bounds and -Inf outside. If lower >= upper, the log-density is -Inf everywhere (rather than an error).
No normalising constant is added, so unlike Uniform(lower, upper), the log-density does not depend on the bounds.
This is like a Stan real<lower=lower, upper=upper> parameter without a prior.
Both bounds must be finite. For a flat distribution on [0, ∞), use PositiveFlat.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
Discrete
WrenDists.Bernoulli — Type
Bernoulli(p)
Bernoulli()Bernoulli distribution with success probability p (default 0.5).
Customised batched implementations: Yes
WrenDists.BernoulliLogit — Type
BernoulliLogit(logitp)
BernoulliLogit()Bernoulli distribution with success probability logistic(logitp) (default logitp = 0.0, i.e. probability 0.5).
Customised batched implementations: Yes
WrenDists.Binomial — Type
Binomial(n, p)
Binomial(n)
Binomial()Binomial distribution for n (default 1) trials with success probability p (default 0.5).
Customised batched implementations: Yes
WrenDists.BinomialLogit — Type
BinomialLogit(n, logitp)
BinomialLogit(n)
BinomialLogit()Binomial distribution for n (default 1) trials with success probability logistic(logitp) (default logitp = 0.0, i.e. probability 0.5).
Customised batched implementations: Yes
WrenDists.NegativeBinomial — Type
NegativeBinomial(r, p)
NegativeBinomial(r)
NegativeBinomial()Negative binomial distribution counting failures before r successes, with success probability p (default 0.5). The shape r (default 1.0) may be any positive number.
Customised batched implementations: Yes
WrenDists.Poisson — Type
Poisson(λ)
Poisson()Poisson distribution with rate λ (default 1.0).
Customised batched implementations: Yes
WrenDists.PoissonLog — Type
PoissonLog(logλ)
PoissonLog()Poisson distribution with rate exp(logλ) (default logλ = 0.0, i.e. rate 1.0).
Customised batched implementations: Yes
WrenDists.Categorical — Type
Categorical(p)Categorical distribution over 1:length(p) with probability vector p.
Customised batched implementations: Yes
WrenDists.Geometric — Type
Geometric(p)
Geometric()Geometric distribution with success probability p (default 0.5), counting the number of failures before the first success.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
Multivariate
WrenDists.MvNormalScale — Type
MvNormalScale(μ, L)Multivariate normal distribution with mean vector μ and scale factor L, where L can be a lower-triangular matrix, a Diagonal, or a UniformScaling.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
This differs from Distributions.jl which uses the covariance matrix Σ instead of the scale factor L. The relationship is Σ = L * L'. The intention of this is to avoid the need to compute the Cholesky factor of Σ inside the model when it is already known, which is often the case with standard deviations that are constant.
In particular, if the covariance matrix is diagonal, then L is simply the vector of standard deviations (rather than variances, as in Distributions.jl).
WrenDists.Dirichlet — Type
Dirichlet(α)Dirichlet distribution with concentration parameter vector α.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)
WrenDists.Multinomial — Type
Multinomial(n, p)Multinomial distribution for n trials with category probability vector p.
Customised batched implementations: Not yet (will fall back to a product of scalar distributions)