[Math] Integral (Tanh and Normal)

calculusfourier transformhyperbolic-functionsnormal distribution

I am trying to evaluate the following: The expectation of the hyperbolic tangent of an arbitrary normal random variable.

$\mathbb{E}[\mathrm{tanh}(\phi)]; \phi \sim N(\mu, \sigma^2)$

Equivalently:

$\int_{-\infty}^{\infty} \mathrm{tanh}(\phi)\frac{1}{\sqrt{2\pi\sigma^2}}\exp(-\frac{1}{2\sigma^2}(\phi-\mu)^2) d\phi$

I've resorted to Wolfram Alpha, and I can sometimes (!) get it to evaluate the integral for $\sigma^2 = 1$. It gives:

$\exp(\mu) – 1$ for negative $\mu$ and $1-\exp(-\mu)$ for positive mu.

I have no idea how it got this, but it seems plausible as I've done some simulations (i.e. lots of draws from the normal distribution and then the mean of the tanh of the draws) and the formula it gives for the $\sigma^2 = 1$ case seems pretty close.

I cannot get it to evalute anything with a different variance. Mathematica also seems unwilling to compute the integral or the Fourier transform (which I thought might be a way forward) but this is tricker than the ones I know how to deal with.

Thanks!

Best Answer

As a challenge for myself, I tried to do the maths. Unfortunately, I am not quite the math guru and I did not manage to find a solution (yet). Considering that my effort could help you on the way, I decided to share my non-result nevertheless:

$$\begin{align} \int_{-\infty}^{+\infty} \mathrm{tanh}(x)\cdot \frac{1}{\sqrt{2 \pi \sigma^2}} e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x & = \frac{1}{\sqrt{2 \pi \sigma^2}} \int_{-\infty}^{+\infty} \frac{e^x - e^{-x}}{e^x + e^{-x}} \cdot e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x \\ & = \frac{1}{\sqrt{2 \pi \sigma^2}} \left( \int_{-\infty}^{+\infty} \frac{e^x}{e^x + e^{-x}} \cdot e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x - \int_{-\infty}^{+\infty} \frac{e^{-x}}{e^x + e^{-x}} \cdot e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x \right) \\ & = \frac{1}{\sqrt{2 \pi \sigma^2}} \left( \int_{-\infty}^{+\infty} \frac{1}{1 + e^{-2x}} \cdot e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x - \int_{-\infty}^{+\infty} \frac{1}{e^{2x} + 1} \cdot e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x \right) \\ \end{align}$$

Using the substitution $u = \frac{x-\mu}{\sqrt{2 \sigma^2}}$ and integration by parts where $\int \frac{1}{1 + e^{ax+b}} \mathrm{d}x = -\frac{1}{a} \ln\left(e^{-ax-b} + 1\right)$ , I managed to get to

$$\begin{align} \int_{-\infty}^{+\infty} \frac{1}{1 + e^{-2x}} e^{-\frac{(x-\mu)^2}{2 \sigma^2}} \mathrm{d}x & = \sqrt{2 \sigma^2}\int_{-\infty}^{+\infty} \frac{1}{1 + e^{-2(\sqrt{2 \sigma^2} u + \mu)}} e^{-u^2} \mathrm{d}u \\ & = \int_{-\infty}^{+\infty} \ln\left(e^{2(\sqrt{2 \sigma^2} u + \mu)} + 1\right) \; u e^{-u^2} \mathrm{d}u \end{align}$$

This is where I got to the point that my inspiration ran out and I considered I spent enough time on the problem. This expression is also still not simple enough for wolfram alpha to handle (unless you simplify to something like $\int_{-\infty}^{\infty} \ln\left(e^{2x} + 1\right)\;xe^{-x^2} \mathrm{d}x$).

BTW: If anyone would be able to finish this answer (or provide another approach), I would also be interested in the solution.

Related Question