I'm working my way through a nice e-book on Kalman filters, translating to Mathematica as I go and I've hit an interesting problem. In this section: https://nbviewer.jupyter.org/github/rlabbe/Kalman-and-Bayesian-Filters-in-Python/blob/master/03-Gaussians.ipynb#Computational-Properties-of-Gaussians - the author gives a formula to compute a product of Gaussian PDFs that is also Gaussian. Googling around will tell you that the product of two Gaussian PDFs is not itself Gaussian, but is proportional to a Gaussian with mean and standard deviation as in the image below (see proof here: http://www.tina-vision.net/docs/memos/2003-003.pdf for source) -- I have implemented his function and it works fine, but I'm curious if TransformedDistribution can be used to arrive at the same distribution.
To make it concrete
d1 = NormalDistribution[m1, s1];
d2 = NormalDistribution[m2, s2];
(* Works perfectly *)
TransformedDistribution[
x + y, {x \[Distributed] d1, y \[Distributed] d2}]
(* Not a Normally Distributed *)
TransformedDistribution[
x*y, {x \[Distributed] d1, y \[Distributed] d2}]
(* This doesn't work, but I'm wondering if there is something like \
this that would produce the normal distribution cited in the question \
*)
TransformedDistribution[
Normalize[x*y, Total], {x \[Distributed] d1, y \[Distributed] d2}]
Edit to add example multiplication using the proposed function.
MultiplyGaussian[g1_, g2_] :=
Module[{mean1, var1, mean2, var2, mean, variance},
{mean1, var1} = g1 /. NormalDistribution[m_, s_] :> {m, s^2};
{mean2, var2} = g2 /. NormalDistribution[m_, s_] :> {m, s^2};
mean = (var1*mean2 + var2*mean1) / (var1 + var2);
variance = (var1 * var2) / (var1 + var2);
NormalDistribution[mean, Sqrt[variance]]
]
z1 = NormalDistribution[3, 0.7];
z2 = NormalDistribution[4.5, 1];
Plot[{Legended[PDF[z1, x], "N(3,0.7)"],
Legended[PDF[z2, x], "N(4.5,2)"] ,
Legended[PDF[MultiplyGaussian[z1, z2], x], "Product"]}, {x, 1, 10}]