# Truncated Distributions

The package provides the `Truncated`

type to represented truncated distributions, which is defined as below:

```
struct Truncated{D<:UnivariateDistribution,S<:ValueSupport} <: Distribution{Univariate,S}
untruncated::D # the original distribution (untruncated)
lower::Float64 # lower bound
upper::Float64 # upper bound
lcdf::Float64 # cdf of lower bound
ucdf::Float64 # cdf of upper bound
tp::Float64 # the probability of the truncated part, i.e. ucdf - lcdf
logtp::Float64 # log(tp), i.e. log(ucdf - lcdf)
end
```

A truncated distribution can be constructed using the constructor `Truncated`

as follows:

`Distributions.Truncated`

โ Type.`Truncated(d, l, u):`

Construct a truncated distribution.

**Arguments**

`d::UnivariateDistribution`

: The original distribution.`l::Real`

: The lower bound of the truncation, which can be a finite value or`-Inf`

.`u::Real`

: The upper bound of the truncation, which can be a finite value of`Inf`

.

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)`

`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.

`Distributions.TruncatedNormal`

โ Function.`TruncatedNormal(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`

.