integration of softplus function

303 Views Asked by At

The softplus function $f(x)=\ln(1+e^x)$ is a good approximation for $\max\{x,0\}$. However, calculating the integration of $f(x)=\ln(1+e^x)$ seems to be quite difficult. Is there any tractable way to do that? For example, we need to compute $$ \int_{a}^{b}\ln(1+e^x) d x $$.

1

There are 1 best solutions below

0
On

No analytical solution

It has no analytical function. The integrand is

$$F_0(x) = \ln(1+\exp(x))$$

is the only analytical solution to the complete Fermi-Dirac integral $F_j(x) = \frac{1}{\Gamma(j+1)} \int_0^\infty \frac{t^j}{e^{t-x} + 1}\,dt$ defined recursively by

$$F_{j}(x) = \int_{-\infty}^{x} F_{j-1}(t) dt$$ or equivalently $\frac{dF_{j}(x)}{dx} = F_{j-1}(x)$ for all $j > -1$. A generation of physicists has tried to find more useful expressions for larger $j$. You may want to do an approximation instead.

Good Approximation

You can easily see that

$$\ln(1+\exp(x)) = \max(x,0) + \ln(1+\exp(-|x|))$$

The first term is easily determined but requires case decisions (see below).

The second integrand can be approximated by $\ln(1+\exp(-|x|)) \approx \left(\log2\right)\exp\left(-\alpha\left|x\right|\right)$ with $\alpha\approx0.85$.

Thus, we could use

$$\int_{a}^{b}\ln\left(1+e^{x}\right)dx\approx\int_{a}^{b}\max(x,0)+\ln(1+\exp(-|x|))\thinspace dx=I(a,b)$$

and obtain

$$I(a,b) =\int_{a}^{b}x+\ln(2)e^{-\alpha x}\thinspace dx=\left.x-\frac{\ln(2)}{\alpha}e^{-\alpha x}\right|_{a}^{b}\thinspace dx\\ =(b-a)+\frac{\ln(2)}{\alpha}\left(e^{-\alpha a}-e^{-\alpha b}\right)$$

for $b\geq a\geq0$ and

$$I(a,b) =\int_{a}^{b}\ln(2)e^{+\alpha x}\thinspace dx=\left.\frac{\ln(2)}{\alpha}e^{+\alpha x}\right|_{a}^{b}\thinspace dx=\frac{\ln(2)}{\alpha}\left(e^{-\alpha b}-e^{-\alpha a}\right)$$

for $0\geq b\geq a$. For $b\geq0\geq a$, we can use the terms above to obtain

$$I(a,b)=I(a,0)+I(0,b).$$

Ping again if you need something more accurate.