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_distribution
— Methodproduct_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.
Distributions.product_distribution
— Methodproduct_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.
Distributions.ProductDistribution
— TypeProductDistribution <: 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.
Distributions.Product
— TypeProduct <: MultivariateDistribution
An N dimensional MultivariateDistribution
constructed from a vector of N independent UnivariateDistribution
s.
Product(Uniform.(rand(10), 1)) # A 10-dimensional Product from 10 independent `Uniform` distributions.
Product
is deprecated and will be removed in the next breaking release. Use product_distribution
instead.
NamedTuple-variate products
Distributions.product_distribution
— Methodproduct_distribution(dists::NamedTuple{K,Tuple{Vararg{Distribution}}}) where {K}
Create a distribution of NamedTuple
s as a product distribution of independent named distributions.
The function falls back to constructing a ProductNamedTupleDistribution
distribution but specialized methods can be defined.
Distributions.ProductNamedTupleDistribution
— TypeProductNamedTupleDistribution{Tnames,Tdists,S<:ValueSupport,eltypes} <:
Distribution{NamedTupleVariate{Tnames},S}
A distribution of NamedTuple
s, 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])