# Product of univariate distributions

#1

In Distributions.jl is it possible to create a cartesian product distribution, given two univariate random variables? I want to do this to make a multivariate uniform distribution supported over [0,1]\times[0,1]

#2

There’s no tooling for this at the moment, but there are several issues describing it. It’s pretty easy to use the existing distributions code as a template to create a new distribution.

#3

Ok. Understood. Thanks.

#4

I have a small package implementing this that I use for MC where the product distribution is the prior. BayesianTools.jl. There is no documentation at the moment, but the test directory has the basic use cases.

#5

yes! this seems like exactly what I need. Thanks. I just wanted to make a
multi-dimensional uniform distribution for MC.

-Noah

#6

@nbren12 Since you were interested in this, I put some effort to update the package, include more thorough testing, and add a brief documentation. Let me know if this is useful to you and how can be improved.

#7

Isn’t sampling from a multi-dimensional uniform distribution just given by

n = 3  # dimension
x = rand(n)


?

#8

I guess you might want different ranges in different dimensions though.

#9

@dpsanders

Distributions.jl does more than just sampling. It stores the pdf and other info which are necessary for doing things like Bayesian statistics.

#10

Thanks! I will definitely take a closer look

#11

Right, but everything is very trivial in the particular case of uniform distributions.
Certainly for non-uniform distributions, something more would be useful – maybe it could be refactored out of BayesianTools.jl into a separate package or part of Distributions.jl? cc @gragusa

#12

We’ve got some issues about this product idea for Distributions. The main difficulty is whether you want to support arrays or tuples. I prefer tuples because you can handle heterogeneous types, but that creates other issues.

#13

Yes I struggle with this myself. I just went for tuples because it seemed more natural and handle heterogeneity (alternatively you could go with generated functions, but it seems overkill to me). I just put this together because I needed it and I am not claiming that this is the best implementation — I just find this useful for the MCMC stuff I do.

@dpsanders happy to factor out whathever it is relevant

#14

I am interested in learning if there has been any progress on product distributions in Distributions.jl or BayesianTools.ProductDistributionsl is still the way to go?