Allow Product
to represent independent multivariate distributions
#1562
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR extends
Product
to build a multivariate distribution out of a list of independent multivariate or univariate distributions.All of the existing functionality of
Product
that represents the joint distribution of independent univariate distributions is conceptually unchanged for the joint distribution of independent multivariate distributions.Functions like
mean
,cov
,pdf
etc. can all be assembled out of the independent components in much the same way as in the univariate case.This PR implements this idea while leaving the previous functionality of
Product
unchanged.In particular,
Product
type has been extended to allow for a vector of both univariate and multivariate distributions with the sameValueSupport
. Distributions with mixed variate types may now have types likeProduct{Continuous, ContinuousDistribution, Vector{ContinuousDistribution}}
,Product
of univariate distributions have been extended to allow for the multivariate case, andProduct
distributions out of multivariate distributions is identical to that out of univariate distributions. In particular, continuous and discrete distributions cannot be mixed,Notes
SparseArrays.SparseMatricCSC
s so as not to introduce aBlockDiagonals.jl
dependency.eltype()
--- namely,eltype(ContinuousDistribution)
returnsAny
rather thanFloat64
(and same in the discrete case), as I believe it should. I've put in a workaround, but let me know if this behaviour is expected.