3
$\begingroup$

I am trying to find the derivative of the logarithm of a Gaussian pdf with mean $\mu$ and standard deviation $\sigma$ defined over $x \in \mathbb{R}$, but I am not certain whether my derivation is correct. Could you please verify whether this is fine, and if not, tell me where the error lies? I would start with the Gaussian pdf:

$$p(x)=\frac{1}{\sqrt{2 \pi \sigma^2}}exp\left(-\frac{(x-\mu)^2}{2 \sigma^2}\right)$$

Then apply the log and the derivative operator to both sides:

$$\frac{d}{dx}log\left(p(x)\right)=\frac{d}{dx}log\left(\frac{1}{\sqrt{2 \pi \sigma^2}}exp\left(-\frac{(x-\mu)^2}{2 \sigma^2}\right)\right)$$

Here we can split the innermost argument on the RHS into two separate logarithms:

$$\frac{d}{dx}log\left(p(x)\right)=\frac{d}{dx}log\left(\frac{1}{\sqrt{2 \pi \sigma^2}}\right)+\frac{d}{dx}log\left(exp\left(-\frac{(x-\mu)^2}{2 \sigma^2}\right)\right)$$

Recognizing that the first RHS term is constant, its derivative becomes zero. In the second RHS term, the $log$ and $exp$ cancel out.

$$\frac{d}{dx}log\left(p(x)\right)=\frac{d}{dx}\left(-\frac{(x-\mu)^2}{2 \sigma^2}\right)$$

We can expand the numerator of the term in the RHS brackets:

$$\frac{d}{dx}log\left(p(x)\right)=\frac{d}{dx}\left(-\frac{x^2-2x\mu-\mu^2}{2 \sigma^2}\right)$$

Which yields, after derivation:

$$\frac{d}{dx}log\left(p(x)\right)=-\frac{2x-2\mu}{2 \sigma^2}$$

which can be simplified to:

$$\frac{d}{dx}log\left(p(x)\right)=-\frac{x-\mu}{\sigma^2}$$

Is this correct? Or did I make any errors?

$\endgroup$
2
  • 4
    $\begingroup$ Looks correct to me! $\endgroup$ Commented Apr 11, 2020 at 7:41
  • $\begingroup$ Tip: use \log. $\endgroup$
    – K.defaoite
    Commented Jul 6, 2020 at 21:11

1 Answer 1

2
$\begingroup$

let c=$\frac{1}{\sqrt{2\pi\sigma^2}}$, then

$$p(x) = c.\exp(-\frac{(x-\mu)^2}{2\sigma^2})$$

We take the $\log$ of p(x)

$$log(p(x)) = \log(c) -\frac{(x-\mu)^2}{2\sigma^2}$$

we differentiate p(x)

$$\frac{dp(x)}{p(x)} = \frac{dc}{c} -\frac{2}{2\sigma^2}(x-\mu)dx$$

we get

$$\frac{dp(x)}{dx} = -p(x)\frac{1}{\sigma^2}(x-\mu)$$

we rewrite it in the original form

$$p'(x) = \frac{-1}{\sqrt{2\pi\sigma^2}}\frac{(x-\mu)}{\sigma^2}\exp(-\frac{(x-\mu)^2}{2\sigma^2})$$

$\endgroup$
1
  • $\begingroup$ Nice work. Tip: use \exp. $\endgroup$
    – K.defaoite
    Commented Jul 6, 2020 at 21:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .