MathalyseResearch

Learn AI · Chapter 3 · Probability and Information Theory

Useful Properties of Common Functions

Meet the sigmoid, which turns any score into a probability, and the softplus, which turns any score into a positive scale. Watch the sigmoid saturate, then check the identities that tie the two functions together.

Book §3.10, pages 67–70Equations 3.30–3.41About 35 minutes
Section 1

The logistic sigmoid

How to use this page

Click any colored symbol, in an equation or in a sentence, and it explains itself. Then move the sliders and make the guesses before you read on.

the sigmoid, the main object the softplus slopes and derivatives , , score, probability, sharpness

A network ends with a raw score . It can be −40 or 12, and it is not yet a probability. This section turns any score into a probability between 0 and 1.

The book’s tool for this is the logistic sigmoid, . Equation 3.30 defines it:

(3.30)
Click any coloured symbol to see what it means.

Think of a dimmer switch. Turned far in either direction, the lamp is already fully off or fully on, so the brightness barely changes. Only near the middle does a small turn change the light. The score is the knob, and the probability is the brightness.

The book uses the sigmoid to produce the Bernoulli parameter (Section 3.9). Its range is the open interval (0, 1), exactly the range must lie in.

Predict first The score is . What probability does the sigmoid give for outcome 1?

Pick one guess. The answer appears here.

Figure 3.3, rebuilt

sigmoidchosen scoreBernoulli probabilities

Read the formula from the inside. When is very large and positive, is nearly 0, so the value is nearly 1. When is very large and negative, is huge, so the value is nearly 0. At the value is exactly one half.

Challenge +8 XP

Drag the score until the probability of outcome 1 is between 0.99 and 0.995.

Score 0 gives a fair coin. Positive scores favor outcome 1, negative scores favor outcome 0, and the two bars always add up to 1. The readout also gives the odds, the ratio of to . The odds equal , so the score is the logarithm of the odds.

A second way to write the same function

The book also writes the sigmoid as Equation 3.33:

(3.33)
Click any coloured symbol to see what it means.

Since is 1, the denominator is . Read the form with as a two-way contest. The score competes with a reference score of 0, and each takes a share in proportion to its exponential.

Going deeper: where the odds come from (added here)

Divide the top and bottom of Equation 3.33 by to recover Equation 3.30. The same denominator appears in , so the odds equal . The odds are therefore the exponential of the score. This derivation is added here and is not printed in the book.

Going deeper: the softmax reading (added here)

The form with is a two-way softmax, which turns two scores into two probabilities that add up to 1. The book introduces the softmax later, in Chapter 6. Nothing in this section depends on it.

Section 2

Saturation

Drag the score away from 0 and watch the tangent line flatten. The book calls this saturation: the sigmoid becomes very flat and insensitive to small changes in its input when the score is very positive or very negative.

The slope is the derivative. The book gives it in Equation 3.34, in a form that is easy to remember:

(3.34)
Click any coloured symbol to see what it means.

The slope is the value times its complement, . It is largest when , which is at , where the slope equals 1/4. Far from 0 it shrinks to almost nothing.

Predict first The score is . What is the slope of the sigmoid there?

Pick one guess. The answer appears here.

How flat is flat?

sigmoidtangent lineproduct of slopes

A parameter changes in proportion to the slope of the function it passes through during training. A unit on a flat part passes back almost no signal, and a chain of units multiplies their slopes. This paragraph is added here as an illustration, and the book does not state it. At score 0 each unit scales the signal by at most 1/4, so ten units scale it by about 10−6.

Challenge +8 XP

Move the score until the slope is smaller than 0.01.

Challenge +8 XP

Set 10 chained sigmoids and find a score where the product of their slopes is between 10−7 and 10−6.

Why flatness matters when sigmoids are stacked

Saturation is not a defect of the sigmoid as a probability model. It becomes a problem only when the sigmoid is a hidden unit in a deep stack, where a small slope at every layer shrinks the signal layer after layer. Later chapters return to this trade-off.

Section 3

The softplus function

Pick a sharpness and watch a smooth curve close in on a sharp corner. The second function of the section is the softplus, Equation 3.31, which the book attributes to Dugas and colleagues (2001):

(3.31)
Click any coloured symbol to see what it means.

Its range is (0, ∞). That makes it useful for a scale. The book notes that the softplus can produce the precision or the standard deviation of a normal distribution, because a network can output any real score and the softplus turns it into a positive value.

The name explains the shape. Softplus is a softened version of the positive part, Equation 3.32:

(3.32)
Click any coloured symbol to see what it means.

The positive part passes positive numbers unchanged and sets negative numbers to 0, so it has a sharp corner at 0. The softplus follows it far from 0 and rounds the corner. At the softplus equals log 2, about 0.693.

Predict first What is the softplus at ?

Pick one guess. The answer appears here.

Figure 3.4, and how soft is soft

softpluspositive part, dashed

At sharpness 1 this is the book’s Figure 3.4. The sharpness is an addition made here: the demo draws the family . Raising pulls the curve onto the corner.

Challenge +8 XP

Set the sharpness so that the largest gap between the softplus and the positive part is below 0.1.

The largest gap sits at the corner, where . There the gap equals log 2 divided by , so a sharper curve has a smaller gap.

A numerical warning (added here, not in the book)

The formula fails for large on a computer. The exponential of 710 is larger than the largest number double precision can store, so the direct formula loses its answer. A stable form avoids exponentiating a positive number: .

Predict first At what argument does the direct formula first overflow?

Pick one guess. The answer appears here.

Break the direct formula

The stable form is always safe to use.

Challenge +8 XP

Drag the argument far enough that the direct formula is lost, so that its readout says the answer is lost.

Section 4

Identities for sigmoid and softplus

Pick an identity, move the derivation step, and read the proof one line at a time. The book says the following properties are useful enough that you may wish to memorize them. The book states them without proof, so the proofs here are added and are easier to remember once derived.

(3.35)
Click any coloured symbol to see what it means.
(3.36)
Click any coloured symbol to see what it means.
(3.37)
Click any coloured symbol to see what it means.

Equation 3.34, the slope of the sigmoid, was shown in Section 2. Equation 3.35 says the sigmoid of a negated score is the complement. Equation 3.36 says the log of a sigmoid is a negative softplus. Equation 3.37 says the slope of the softplus is the sigmoid.

Predict first What is the slope of the softplus at , using Equation 3.37?

Pick one guess. The answer appears here.

Derive and check

Challenge +8 XP

Open the Eq. 3.37 tab and set the test value so that the measured slope of the softplus is 0.25, to within 0.002.

Going deeper: why the sigmoid slope has this form (added here)

Differentiate with the chain rule. The factor appears once as the derivative of the denominator and once in the numerator. The step that gives Equation 3.34 its simple form rewrites the product with .

Section 5

Inverse functions

Start at a score, push it through the sigmoid, then push the result back. Do you return to where you started? Both functions can be undone. The inverse of the sigmoid takes a probability and returns the score that produced it, Equation 3.38. The inverse of the softplus takes a positive number and returns the score, Equation 3.39.

(3.38)
Click any coloured symbol to see what it means.
(3.39)
Click any coloured symbol to see what it means.

The letter in these two equations is the argument of the inverse. It is a probability in (0, 1) for the first and a positive number for the second. The book uses the letter for both, and here it is not a score.

The book notes that is called the logit in statistics, a term that is more rarely used in machine learning. The logit is the logarithm of the odds that Section 1 introduced.

Predict first What is the logit of 0.75, which is ?

Pick one guess. The answer appears here.

Round trips

forward functioninverse functionround trip

The two curves in each tab are mirror images across the dotted diagonal. Apply the forward function, then the inverse, and you return to the score, up to arithmetic precision. Equation 3.38 needs , so the logit tab cannot take a probability of 0 or 1.

Going deeper: solving for the inverses (added here)

For Equation 3.38, start from . Then , so , and taking the logarithm of the reciprocal gives .

For Equation 3.39, start from . Exponentiate to get , so . Both derivations are added here.

Section 6

Integral and the positive part

Shade the area under the sigmoid from far left up to a point, then compare it with the softplus at the same point.

The softplus is the accumulated area under the sigmoid. Equation 3.40 writes that as an integral, and the book states it without proof:

(3.40)
Click any coloured symbol to see what it means.

Predict first What is the area under the sigmoid from minus infinity up to ?

Pick one guess. The answer appears here.

Area and parts

sigmoid, shaded areasoftplus at xsoftplus at minus xpositive and negative parts, dashed
Challenge +8 XP

Move the upper limit until the shaded area is 0.5, to within 0.02.

Equation 3.37 gives the slope of the softplus as the sigmoid. Integrate that slope from far left up to , and the result is the softplus at , because the softplus is 0 at the far left. That is why the area equals the softplus.

The book uses Equation 3.41 to justify the name. The positive part is , and the negative part is = max(0, −). A number is recovered from its two parts, so .

Click any coloured symbol to see what it means.

The softplus has a smooth counterpart for the negative part, and the same relation holds for it:

(3.41)
Click any coloured symbol to see what it means.
Going deeper: why the softplus identity holds (added here)

Factor out of the logarithm: . Rearrange to get Equation 3.41. The same step shows that the softplus is a smooth version of the positive part, because and differ by at most log 2.

What to take away
  • The sigmoid maps any score into (0, 1) and produces a Bernoulli parameter. Its inverse is the logit, the logarithm of the odds.
  • It saturates: its slope is at most 1/4 and falls to 0 in both tails, so a signal passes through a stack of saturated sigmoids weakly.
  • The softplus maps any score into (0, ∞) and is a smooth version of . It suits a positive scale.
  • The two are tied together: , , with the complement, and .
  • The direct exponentials overflow for large scores, so implementations use the stable forms.
Final quiz

Check yourself

Questions that mix the whole module. Each one is scored, and the score feeds your mastery of this module.

Source: Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, MIT Press, 2016, Section 3.10 (pages 67–70), free to read at deeplearningbook.org. Where the book prints equation numbers, the numbers here follow the book. The order of ideas follows the book. The explanations and all demos were written for this page.