# Product of univariate distributions

**URL:** https://discourse.julialang.org/t/product-of-univariate-distributions/1350
**Category:** Statistics
**Created:** [January 8, 2017, 2:27am UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350 "2017-01-08T02:27:59Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![nbren12](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@nbren12](https://discourse.julialang.org/u/nbren12)
#### Post date: [January 8, 2017, 2:27am UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/1 "2017-01-08T02:27:59Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [January 8, 2017, 2:28am UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/2 "2017-01-08T02:28:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nbren12](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@nbren12](https://discourse.julialang.org/u/nbren12)
#### Post date: [January 8, 2017, 3:01am UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/3 "2017-01-08T03:01:57Z")

</div>

Ok. Understood. Thanks.

---

<div class="post-metadata">

### Author: ![gragusa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gragusa/32/3547_2.png) [@gragusa](https://discourse.julialang.org/u/gragusa)
#### Post date: [January 8, 2017, 1:55pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/4 "2017-01-08T13:55:11Z")

</div>

I have a small package implementing this that I use for MC where the product distribution is the prior. [BayesianTools.jl](https://github.com/gragusa/BayesianTools.jl). There is no documentation at the moment, but the test directory has the basic use cases.

---

<div class="post-metadata">

### Author: ![nbren12](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@nbren12](https://discourse.julialang.org/u/nbren12)
#### Post date: [January 8, 2017, 3:16pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/5 "2017-01-08T15:16:03Z")

</div>

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

-Noah

---

<div class="post-metadata">

### Author: ![gragusa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gragusa/32/3547_2.png) [@gragusa](https://discourse.julialang.org/u/gragusa)
#### Post date: [January 10, 2017, 4:42pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/6 "2017-01-10T16:42:41Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [January 10, 2017, 4:51pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/7 "2017-01-10T16:51:42Z")

</div>

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

```julia
n = 3 # dimension
x = rand(n)

```

?

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [January 10, 2017, 5:06pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/8 "2017-01-10T17:06:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nbren12](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@nbren12](https://discourse.julialang.org/u/nbren12)
#### Post date: [January 10, 2017, 5:59pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/9 "2017-01-10T17:59:00Z")

</div>

@dpsanders

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

---

<div class="post-metadata">

### Author: ![nbren12](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@nbren12](https://discourse.julialang.org/u/nbren12)
#### Post date: [January 10, 2017, 6:09pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/10 "2017-01-10T18:09:20Z")

</div>

Thanks! I will definitely take a closer look

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [January 10, 2017, 6:21pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/11 "2017-01-10T18:21:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [January 10, 2017, 6:35pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/12 "2017-01-10T18:35:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gragusa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gragusa/32/3547_2.png) [@gragusa](https://discourse.julialang.org/u/gragusa)
#### Post date: [January 10, 2017, 7:10pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/13 "2017-01-10T19:10:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [February 18, 2018, 6:27pm UTC](https://discourse.julialang.org/t/product-of-univariate-distributions/1350/14 "2018-02-18T18:27:27Z")

</div>

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