y=ln(1+ex)y = \ln(1+e^x)

Graph of the Softplus Function y=ln(1+ex)y = \ln(1 + e^x)

y=ln(1+ex)y = \ln(1 + e^x) is called the softplus function. Since ex>0e^x > 0 gives 1+ex>11 + e^x > 1, the logarithm is always positive, so the domain is all real numbers and the range is y>0y > 0. The inside 1+ex1 + e^x increases monotonically and ln\ln is increasing, so the whole function increases monotonically.

Two asymptotes

The behavior on the left and on the right could hardly be more different.

SideApproximationAsymptote
xx \to -\inftyln(1+0)=0\ln(1 + 0) = 0y=0y = 0, the xx-axis
x+x \to +\inftyln(ex)=x\ln(e^x) = xy=xy = x

Flat toward 00 on the left and tending to the line of slope 11 on the right, it is a smoothly bent shape.

The derivative is the sigmoid

The derivative is exactly the logistic, or sigmoid, function.

y=ex1+ex=11+exy' = \frac{e^x}{1 + e^x} = \frac{1}{1 + e^{-x}}

Its value lies between 00 and 11, tending to 00 as xx \to -\infty and to 11 as x+x \to +\infty. The second derivative is positive, so the graph is convex throughout.

Values

xxyyGap from xx
1-10.3130.3131.3131.313
000.6930.6930.6930.693
111.3131.3130.3130.313
555.0075.0070.0070.007

For large xx the output is almost equal to xx. The gap is exactly ln(1+ex)\ln(1 + e^{-x}), and the values appear in swapped order down the two columns because yxy - x equals the value at x-x.

Relation to ReLU

The ReLU max(0,x)\max(0, x), common in machine learning, has a corner at the origin where it is not differentiable; softplus is a smooth approximation that rounds that corner off, staying rounded near the origin while nearly coinciding with ReLU far away. It is used as an activation function in neural networks, and to parametrize quantities that must stay positive, such as a variance or a population count. That its derivative is the sigmoid, equivalently that softplus is the antiderivative of the sigmoid, also simplifies gradient computations.

A trick for numerical work

Computing ln(1+ex)\ln(1 + e^x) directly overflows when xx is large, because exe^x does. Implementations commonly rewrite it in the following form for numerical stability.

max(0,x)+ln ⁣(1+ex)\max(0, x) + \ln\!\left( 1 + e^{-|x|} \right)

The exponent is never positive, so nothing overflows.