Type Hierarchy

Type Hierarchy

All samplers and distributions provided in this package are organized into a type hierarchy described as follows.

Sampleable

The root of this type hierarchy is Sampleable. The abstract type Sampleable subsumes any types of objects from which one can draw samples, which particularly includes samplers and distributions. Formally, Sampleable is defined as

abstract type Sampleable{F<:VariateForm,S<:ValueSupport} end

It has two type parameters that define the kind of samples that can be drawn therefrom.

VariateForm

F <: VariateForm specifies the form of the variate, which can be one of the following:

TypeA single sampleMultiple samples
Univariatea scalar numberA numeric array of arbitrary shape, each element being a sample
Multivariatea numeric vectorA matrix, each column being a sample
Matrixvariatea numeric matrixAn array of matrices, each element being a sample matrix

ValueSupport

S <: ValueSupport specifies the support of sample elements, which can be either of the following:

TypeElement typeDescriptions
DiscreteIntSamples take discrete values
ContinuousFloat64Samples take continuous real values

Multiple samples are often organized into an array, depending on the variate form.

The basic functionalities that a sampleable object provides is to retrieve information about the samples it generates and to draw samples. Particularly, the following functions are provided for sampleable objects:

length(::Sampleable)
size(::Sampleable)
nsamples(::Type{Sampleable}, x::Any)
eltype(::Sampleable)
rand(::Sampleable)
rand!(::Sampleable, ::AbstractArray)

Distributions

We use Distribution, a subtype of Sampleable as defined below, to capture probabilistic distributions. In addition to being sampleable, a distribution typically comes with an explicit way to combine its domain, probability density functions, among many other quantities.

abstract type Distribution{F<:VariateForm,S<:ValueSupport} <: Sampleable{F,S} end

To simplify the use in practice, we introduce a series of type alias as follows:

const UnivariateDistribution{S<:ValueSupport}   = Distribution{Univariate,S}
const MultivariateDistribution{S<:ValueSupport} = Distribution{Multivariate,S}
const MatrixDistribution{S<:ValueSupport}       = Distribution{Matrixvariate,S}
const NonMatrixDistribution = Union{UnivariateDistribution, MultivariateDistribution}

const DiscreteDistribution{F<:VariateForm}   = Distribution{F,Discrete}
const ContinuousDistribution{F<:VariateForm} = Distribution{F,Continuous}

const DiscreteUnivariateDistribution     = Distribution{Univariate,    Discrete}
const ContinuousUnivariateDistribution   = Distribution{Univariate,    Continuous}
const DiscreteMultivariateDistribution   = Distribution{Multivariate,  Discrete}
const ContinuousMultivariateDistribution = Distribution{Multivariate,  Continuous}
const DiscreteMatrixDistribution         = Distribution{Matrixvariate, Discrete}
const ContinuousMatrixDistribution       = Distribution{Matrixvariate, Continuous}

All methods applicable to Sampleable also applies to Distribution. The API for distributions of different variate forms are different (refer to univariates, multivariates, and matrix for details).