All formulas

Machine learning building blocks

Softplus

ml.softplusAlso called softplus, soft plus, smooth relu, log1pexp

ζ(x)=ln⁡(1+ex)\zeta(x) = \ln\left(1 + e^{x}\right)

Smooth approximation of max(0, x). As written it overflows for x above about 709; the stable form max(x, 0) + ln(1 + e−|x|) gives the same value everywhere.

Notation

xx

input

x ∈ ℝ

ζ(x)\zeta(x)

Result: the activation

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=0x = 0

    Result

    ζ(x)=log⁡(2)\displaystyle \zeta(x) = \log{\left(2 \right)}

    ≈ 0.69314718056

  2. Given

    x=1x = 1

    Result

    ζ(x)=log⁡(1+e)\displaystyle \zeta(x) = \log{\left(1 + e \right)}

    ≈ 1.31326168752

  3. Given

    x=−1x = -1

    Result

    ζ(x)=log⁡(e−1+1)\displaystyle \zeta(x) = \log{\left(e^{-1} + 1 \right)}

    ≈ 0.313261687518

  4. Given

    x=800x = 800

    Result

    ζ(x)=log⁡(1+e800)\displaystyle \zeta(x) = \log{\left(1 + e^{800} \right)}

    ≈ 800

Common mistakes

  • Evaluates ln(1 + e×) directly

    e× overflows to inf for x above about 709, so the result is inf instead of about x.

    Fix: Use max(x, 0) + log1p(exp(−|x|)), or call torch.nn.functional.softplus / numpy.logaddexp(0, x).

Source

  • Goodfellow et al. 2016, §3.10, eq. 3.31

    Goodfellow, Ian; Bengio, Yoshua; Courville, Aaron. Deep Learning. MIT Press, 2016.

    deeplearningbook.org