Product Distributions

Product distributions are joint distributions of multiple independent distributions. It is recommended to use product_distribution to construct product distributions. Depending on the type of the argument, it may construct a different distribution type.

Multivariate products

Distributions.product_distributionMethod
product_distribution(dists::AbstractArray{<:Distribution{<:ArrayLikeVariate{M}},N})

Create a distribution of M + N-dimensional arrays as a product distribution of independent M-dimensional distributions by stacking them.

The function falls back to constructing a ProductDistribution distribution but specialized methods can be defined.

source
Distributions.product_distributionMethod
product_distribution(dists::AbstractVector{<:Normal})

Create a multivariate normal distribution by stacking the univariate normal distributions.

The resulting distribution of type MvNormal has a diagonal covariance matrix.

source
Distributions.ProductDistributionType
ProductDistribution <: Distribution{<:ValueSupport,<:ArrayLikeVariate}

A distribution of M + N-dimensional arrays, constructed from an N-dimensional array of independent M-dimensional distributions by stacking them.

Users should use product_distribution to construct a product distribution of independent distributions instead of constructing a ProductDistribution directly.

source
Distributions.ProductType
Product <: MultivariateDistribution

An N dimensional MultivariateDistribution constructed from a vector of N independent UnivariateDistributions.

Product(Uniform.(rand(10), 1)) # A 10-dimensional Product from 10 independent `Uniform` distributions.
Note

Product is deprecated and will be removed in the next breaking release. Use product_distribution instead.

source

NamedTuple-variate products

Distributions.product_distributionMethod
product_distribution(dists::NamedTuple{K,Tuple{Vararg{Distribution}}}) where {K}

Create a distribution of NamedTuples as a product distribution of independent named distributions.

The function falls back to constructing a ProductNamedTupleDistribution distribution but specialized methods can be defined.

source
Distributions.ProductNamedTupleDistributionType
ProductNamedTupleDistribution{Tnames,Tdists,S<:ValueSupport,eltypes} <:
    Distribution{NamedTupleVariate{Tnames},S}

A distribution of NamedTuples, constructed from a NamedTuple of independent named distributions.

Users should use product_distribution to construct a product distribution of independent distributions instead of constructing a ProductNamedTupleDistribution directly.

Examples

julia> d = product_distribution((x=Normal(), y=Dirichlet([2, 4])))
ProductNamedTupleDistribution{(:x, :y)}(
x: Normal{Float64}(μ=0.0, σ=1.0)
y: Dirichlet{Int64, Vector{Int64}, Float64}(alpha=[2, 4])
)


julia> nt = rand(d)
(x = 1.5155385995160346, y = [0.533531876438439, 0.466468123561561])

julia> pdf(d, nt)
0.13702825691074877

julia> pdf(d, reverse(nt))  # order of fields does not matter
0.13702825691074877

julia> mode(d)  # mode of marginals
(x = 0.0, y = [0.25, 0.75])

julia> mean(d)  # mean of marginals
(x = 0.0, y = [0.3333333333333333, 0.6666666666666666])

julia> var(d)  # var of marginals
(x = 1.0, y = [0.031746031746031744, 0.031746031746031744])
source

Index