Truncated Distributions
The package provides the truncated
function which creates the most appropriate distribution to represent a truncated version of a given distribution.
A truncated distribution can be constructed using the following signature:
Distributions.truncated
— Functiontruncated(d::UnivariateDistribution, l::Real, u::Real)
Truncate a univariate distribution d
to the interval [l, u]
.
The lower bound l
can be finite or -Inf
and the upper bound u
can be finite or Inf
. The function throws an error if l > u
.
The function falls back to constructing a Truncated
wrapper.
Implementation
To implement a specialized truncated form for distributions of type D
, the method truncate(d::D, l::T, u::T) where {T <: Real}
should be implemented.
In the general case, this will create a Truncated{typeof(d)}
structure, defined as follows:
Distributions.Truncated
— TypeTruncated
Generic wrapper for a truncated distribution.
Many functions, including those for the evaluation of pdf and sampling, are defined for all truncated univariate distributions:
maximum(::UnivariateDistribution)
minimum(::UnivariateDistribution)
insupport(::UnivariateDistribution, x::Any)
pdf(::UnivariateDistribution, ::Real)
logpdf(::UnivariateDistribution, ::Real)
cdf(::UnivariateDistribution, ::Real)
logcdf(::UnivariateDistribution, ::Real)
logdiffcdf(::UnivariateDistribution, ::T, ::T) where {T <: Real}
ccdf(::UnivariateDistribution, ::Real)
logccdf(::UnivariateDistribution, ::Real)
quantile(::UnivariateDistribution, ::Real)
cquantile(::UnivariateDistribution, ::Real)
invlogcdf(::UnivariateDistribution, ::Real)
invlogccdf(::UnivariateDistribution, ::Real)
rand(::UnivariateDistribution)
rand!(::UnivariateDistribution, ::AbstractArray)
median(::UnivariateDistribution)
Functions to compute statistics, such as mean
, mode
, var
, std
, and entropy
, are not available for generic truncated distributions. Generally, there are no easy ways to compute such quantities due to the complications incurred by truncation. However, these methods are supported for truncated normal distributions Truncated{<:Normal}
.
Distributions.TruncatedNormal
— FunctionTruncatedNormal(mu, sigma, l, u)
The truncated normal distribution is a particularly important one in the family of truncated distributions. We provide additional support for this type with TruncatedNormal
which calls Truncated(Normal(mu, sigma), l, u)
. Unlike the general case, truncated normal distributions support mean
, mode
, modes
, var
, std
, and entropy
.