5
$\begingroup$

I need to divide a Gaussian Mixture by it's widest component. When I do this, the exponents of the output end up a mess of terms in need of simplification, but Simplify[] doesn't do it. How can I make this work?

gauMix[x_, means_, vars_] := 
  (1/Length[vars])*Total[(E^-(((x -means)^2)/(2*vars)))/Sqrt[2*Pi*vars]];
means = {-2, 2, 5};
vars = {1, 2, 2};
widest = Flatten[Position[vars, _?(# == Max[vars] &)]];
h[x_, v_] := 
  gauMix[x, means, vars + v]/gauMix[x, {Mean[means[[widest]]]},{vars[[Min[widest]]] + v}];
Expand[h[x, v]]

$$\frac{\sqrt{v+2} \exp \left(\frac{\left(x-\frac{7}{2}\right)^2}{2 (v+2)}-\frac{(x+2)^2}{2 (v+1)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} \exp \left(\frac{\left(x-\frac{7}{2}\right)^2}{2 (v+2)}-\frac{(x-5)^2}{2 (v+2)}\right)+\frac{1}{3} \exp \left(\frac{\left(x-\frac{7}{2}\right)^2}{2 (v+2)}-\frac{(x-2)^2}{2 (v+2)}\right)$$

I would like to see, the exponents individually Simplify[]'d and Together[]'d into something like this:

$$\frac{\sqrt{v+2} \exp \left(\frac{-44 v x+33 v-4 x^2-60 x+17}{8 (v+1) (v+2)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} e^{\frac{33-12 x}{8 v+16}}+\frac{1}{3} e^{\frac{3 (4 x-17)}{8 (v+2)}}$$

$\endgroup$
5
  • $\begingroup$ h[x, v] // Simplify ? $\endgroup$ Commented Feb 21, 2015 at 0:34
  • $\begingroup$ $\frac{1}{3} e^{\frac{(7-2 x)^2}{8 (v+2)}} \left(e^{-\frac{(x-5)^2}{2 (v+2)}}+e^{-\frac{(x-2)^2}{2 (v+2)}}+\frac{e^{-\frac{(x+2)^2}{2 (v+1)}}}{\sqrt{\frac{v+1}{v+2}}}\right)$ $\endgroup$ Commented Feb 21, 2015 at 0:36
  • $\begingroup$ @belisarius No, that's just dividing back out the wide gaussian that I just multiplied in. What I want is for each of those exponents to get individually simplified. For example, in the 2nd and 3rd terms, the x^2 term of the exponent polynomials will cancel out. $\endgroup$ Commented Feb 21, 2015 at 0:41
  • $\begingroup$ perhaps you should write down the expected result $\endgroup$ Commented Feb 21, 2015 at 0:46
  • $\begingroup$ @belisarius Okay, I did that. $\endgroup$ Commented Feb 21, 2015 at 1:16

2 Answers 2

12
$\begingroup$

Explicitly replacing the exponents with simplifications:

expr /. {Exp[x_] :> Exp[Together@FullSimplify[x]]}

This results in:

$$ \frac{\sqrt{v+2} \exp \left(\frac{-44 v x+33 v-4 x^2-60 x+17}{8 (v+1) (v+2)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} e^{\frac{3 (4 x-17)}{8 (v+2)}}+\frac{1}{3} e^{-\frac{3 (4 x-11)}{8 (v+2)}} $$

$\endgroup$
3
  • $\begingroup$ P.S. A simpler way to find the parameters of the widest gaussian: Mean@MaximalBy[Transpose[{means, vars}], Last]. You can apply Sequence to put it into your function without extracting the parts separately. $\endgroup$ Commented Feb 21, 2015 at 2:28
  • $\begingroup$ I didn't really understand you PS comment, but thank you for this answer. $\endgroup$ Commented Apr 10, 2016 at 7:38
  • $\begingroup$ Genius and simple trick! How didn't I think of that? Kudos !! $\endgroup$
    – Massimo
    Commented Sep 14, 2021 at 10:48
-1
$\begingroup$
gauMix[x_, means_, vars_] := (1/Length[vars])*
   Total[(E^-(((x - means)^2)/(2*vars)))/Sqrt[2*Pi*vars]];
means = {-2, 2, 5};
vars = {1, 2, 2};
widest = Flatten[Position[vars, _?(# == Max[vars] &)]];
h[x_, v_] := 
  gauMix[x, means, vars + v]/
   gauMix[x, {Mean[means[[widest]]]}, {vars[[Min[widest]]] + v}];
Simplify[Expand[h[x, v]] /. E^(a__ /b__ + c__ /b__) -> E^((a + c)/b)]

$ \frac{1}{3} e^{\frac{8 x^2-44 x+65}{4 v+8}}+\frac{1}{3} e^{\frac{(x-5)^2+\left(x-\frac{7}{2}\right)^2}{v+2}}+\frac{e^{\frac{1}{2} \left(\frac{\left(x-\frac{7}{2}\right)^2}{v+2}-\frac{(x+2)^2}{v+1}\right)}}{3 \sqrt{\frac{v+1}{v+2}}} $

$\endgroup$
1
  • 1
    $\begingroup$ This gives wrong results. The x^2 terms should be cancelling out of the exponents of two of the terms. $\endgroup$ Commented Feb 21, 2015 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.