I have two multivariate normal distributions like such:
using Distributions, LinearAlgebra
g1 = MvNormal([1,2], [2 1; 1 2])
A = [3 1; 1 3]
B = [[A [0;0]]; transpose([0,0,1])]
g2 = MvNormal([1,2,3], B)
I would like to combine them into a new distribution of the concatenation of both variables, assuming they are independent. The function product_distribution seems like it should do the trick:
g3 = product_distribution(g1, g2)
But that results in an error:
ERROR: all distributions must be of the same size
Which I really don't understand, and makes me think this function's purpose is not what I thought it was, but I can't find any other that would be more appropriate.
To be clear, the desired output should be equivalent to:
m3 = vcat(mean(g1), mean(g2))
s3 = hvcat( (2,2), cov(g1), zeros(2,3), zeros(3,2), cov(g2))
g3 = MvNormal(m3, s3)
(Although perhaps a sparse matrix or some other optimised diagonal block matrix type would be more appropriate, but I really don't care in this case.)
Couldn't find a clean answer, but the issue has come up before. The best I can suggest so far:
giving: