Search

Search papers and lessons

Gumbel Distribution

Level 3 · 10 min read

The Gumbel distribution describes the largest of many random values, and in machine learning its shape makes adding random noise to scores pick the right option with exactly the right probability.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • ReadReady to readNot yet

TL;DR

The Gumbel distribution is a bell-like curve with a longer tail on the right. For many common distributions, it is the limiting shape of the largest of many independent random variables once they are shifted and scaled. In machine learning it has a second use: adding Gumbel noise to a list of scores and keeping the highest one picks each option with exactly its intended probability.

Builds on: Cumulative Distribution Function, Uniform Distribution, Logarithm · Leads to: Gumbel-Softmax Trick

Where it's used

Yearly maximum floods and winds. Engineers who design dams, bridges and sea walls need to know how large the worst flood in a year is likely to be. For many rivers the yearly maximum flow is often modelled with a Gumbel distribution, fitted to decades of records, and then used to estimate how often a flood of a given size is expected. This is one of the classic uses of extreme value theory, the branch of statistics that studies maxima.

Choice models in economics. When a person picks one option from several, a common model assumes each option has a fixed value plus random taste noise. If that noise is Gumbel, the probability of each choice takes the simple softmax form, which gives the standard logit choice model used to forecast demand for transport and products.

Sampling discrete choices in neural networks. A network often outputs a score for each category, and sampling a category means picking one at random with the right probabilities. Adding independent Gumbel noise to the log-probabilities and taking the largest value does this exactly. The Gumbel-Softmax Trick builds on this to make the choice differentiable. The same idea can appear in discrete variational autoencoders, where the latent variable is a category.

How it works

We use the standard Gumbel distribution, the version with location 0 and scale 1. Its cumulative distribution function is

F(x)=exp⁡(−e−x)F(x) = \exp\bigl(-e^{-x}\bigr)

Read it as: for a value xx, F(x)F(x) is the chance that a Gumbel draw is at or below xx. The goal is to generate a Gumbel draw from a uniform random number, which is easy for a computer.

  1. Start with a uniform number. Draw UU uniformly between 0 and 1. Suppose the draw is U=0.5U = 0.5. Check: a uniform draw is equally likely to land anywhere in (0,1)(0, 1), so 0.50.5 sits in the middle.

  2. Turn the CDF into an equation. We want the value xx where the CDF equals the draw: U=exp⁡(−e−x)U = \exp(-e^{-x}). Taking the natural logarithm of both sides gives log⁡U=−e−x\log U = -e^{-x}. Check: the right side is negative, and log⁡0.5\log 0.5 is also negative, so the equation is consistent.

  3. Solve for x. Multiply by −1-1: −log⁡U=e−x-\log U = e^{-x}. Take the logarithm again: log⁡(−log⁡U)=−x\log(-\log U) = -x, so x=−log⁡(−log⁡U)x = -\log(-\log U). With U=0.5U = 0.5, −log⁡0.5=0.6931-\log 0.5 = 0.6931, and −log⁡0.6931=0.3665-\log 0.6931 = 0.3665. So the Gumbel draw is about 0.3670.367. Check: F(0.367)=exp⁡(−e−0.367)=exp⁡(−0.6931)=0.5F(0.367) = \exp(-e^{-0.367}) = \exp(-0.6931) = 0.5, which is the uniform draw we started with.

  4. See what a larger uniform gives. Try U=0.9U = 0.9. Then −log⁡0.9=0.1054-\log 0.9 = 0.1054, and −log⁡0.1054=2.250-\log 0.1054 = 2.250. So the draw is about 2.252.25. Check: F(2.25)=exp⁡(−e−2.25)=exp⁡(−0.1054)=0.90F(2.25) = \exp(-e^{-2.25}) = \exp(-0.1054) = 0.90. Large uniform draws map to large Gumbel draws, and the rare values above 2 come from the top 10 percent of uniform draws.

  5. Shift and scale. A Gumbel with location μ\mu and scale β\beta is X=μ+βGX = \mu + \beta G, where GG is the standard draw. Its CDF is exp⁡(−e−(x−μ)/β)\exp\bigl(-e^{-(x-\mu)/\beta}\bigr). The location moves the curve sideways, and the scale stretches it. Check: with μ=0\mu = 0 and β=2\beta = 2, the value x=2x = 2 maps to (2−0)/2=1(2 - 0)/2 = 1 inside the exponent, the same as the standard case at x=1x = 1.

The shape comes from the double exponential. The density is largest near the mode at 0, falls off fast on the left, and falls off slowly on the right. The right tail is what makes the Gumbel useful for maxima: a single very large value can still happen, while very small values are squeezed out.

The math

Definition

Definition: Gumbel distribution

A random variable XX has a Gumbel distribution with location μ\mu and scale β>0\beta \gt 0 when its CDF is

F(x)=exp⁡ ⁣(−exp⁡ ⁣(−x−μβ))F(x) = \exp\!\left(-\exp\!\left(-\frac{x-\mu}{\beta}\right)\right)

The standard case has μ=0\mu = 0 and β=1\beta = 1.

Step 1 in symbols: the density

Differentiating the CDF gives the density for the standard case:

f(x)=e−xexp⁡(−e−x)f(x) = e^{-x}\exp\bigl(-e^{-x}\bigr)

Its derivative is f′(x)=f(x) (e−x−1)f'(x) = f(x)\,(e^{-x} - 1), which is zero when e−x=1e^{-x} = 1, so the mode is at x=0x = 0. Because the density decays like e−xe^{-x} for large xx, the right tail is longer than a normal tail with the same centre.

Step 2 in symbols: inverting the CDF

Setting U=F(x)U = F(x) and solving gives the inverse

x=μ−βlog⁡(−log⁡U)x = \mu - \beta \log\bigl(-\log U\bigr)

This is the formula used in step 3 of the walkthrough. For the standard case, U=0.5U = 0.5 gives x=−log⁡(−log⁡0.5)=0.367x = -\log(-\log 0.5) = 0.367.

Step 3 in symbols: mean and variance

For the Gumbel with location μ\mu and scale β\beta, the mean and variance are

E[X]=μ+βγ,Var⁡(X)=π2β26\mathbb{E}[X] = \mu + \beta\gamma, \qquad \operatorname{Var}(X) = \frac{\pi^2 \beta^2}{6}

where γ≈0.5772\gamma \approx 0.5772 is the Euler–Mascheroni constant. The mean is larger than the mode μ\mu, which is the statement that the right tail pulls the average to the right.

Step 4 in symbols: the Gumbel-max trick

Let the categories have probabilities p1,…,pKp_1, \dots, p_K, and let G1,…,GKG_1, \dots, G_K be independent standard Gumbel draws. Then

Pr⁡(arg⁡max⁡k (log⁡pk+Gk)=j)=pj\Pr\bigl(\arg\max_k\,(\log p_k + G_k) = j\bigr) = p_j

So taking the largest noisy log-probability is an exact way to sample a category. This is the fact behind the third use in "Where it's used".

Worked examples

Example
Example 1: one draw by hand

Let U=0.5U = 0.5 be a uniform draw, and find the standard Gumbel draw GG.

  1. Compute −log⁡U=−log⁡0.5=0.6931-\log U = -\log 0.5 = 0.6931.
  2. Compute −log⁡(0.6931)=0.3665-\log(0.6931) = 0.3665.
  3. Set G=0.3665G = 0.3665, which is about 0.3670.367.
  4. Check: exp⁡(−0.3665)=0.6931\exp(-0.3665) = 0.6931, and exp⁡(−0.6931)=0.5\exp(-0.6931) = 0.5, so F(0.3665)=0.5F(0.3665) = 0.5.

Interpretation: the uniform draw in the middle of (0,1)(0, 1) becomes a Gumbel draw slightly above 0, which is near the mode.

Example
Example 2: the standard case with a shift and scale

Let μ=0\mu = 0 and β=2\beta = 2. Find Pr⁡(X≤4)\Pr(X \le 4).

  1. Compute the standardised value: (4−0)/2=2(4 - 0) / 2 = 2.
  2. Compute exp⁡(−2)=0.1353\exp(-2) = 0.1353.
  3. Compute exp⁡(−0.1353)=0.8734\exp(-0.1353) = 0.8734.
  4. So Pr⁡(X≤4)=0.873\Pr(X \le 4) = 0.873.
  5. Check: Pr⁡(X>4)=1−0.873=0.127\Pr(X \gt 4) = 1 - 0.873 = 0.127, a small but not negligible chance.

Interpretation: a Gumbel with scale 2 puts about 87 percent of its probability at or below 4, and the remaining 13 percent sits in the right tail.

Example
Example 3: yearly flood maxima

This is an illustrative model, so the numbers are made up. The yearly maximum river flow, in cubic metres per second, is modelled as Gumbel with μ=100\mu = 100 and β=20\beta = 20. Find the chance that the yearly maximum exceeds 160.

  1. Standardise: (160−100)/20=3(160 - 100) / 20 = 3.
  2. Compute exp⁡(−3)=0.04979\exp(-3) = 0.04979.
  3. Compute exp⁡(−0.04979)=0.95143\exp(-0.04979) = 0.95143.
  4. The chance of staying at or below 160 is 0.951430.95143, so the chance of exceeding it is 1−0.95143=0.048571 - 0.95143 = 0.04857.
  5. Convert to a return period: 1/0.04857=20.61 / 0.04857 = 20.6. So a flow above 160 is expected about once every 21 years, on average.

Interpretation: a design that must survive flows of this size needs to be safe for a roughly 1-in-21-year event, and the answer depends entirely on the fitted location and scale.

Try it. Use the same model, μ=100\mu = 100 and β=20\beta = 20. What is the chance that the yearly maximum exceeds 120?

Answer: Standardise: (120−100)/20=1(120 - 100)/20 = 1. Then exp⁡(−1)=0.36788\exp(-1) = 0.36788, and exp⁡(−0.36788)=0.69220\exp(-0.36788) = 0.69220. The chance of exceeding 120 is 1−0.69220=0.30781 - 0.69220 = 0.3078, about 0.31.

Common mistakes and tradeoffs

It is tempting to think the Gumbel is just a normal distribution with a different name. In fact it is skewed: its right tail decays like e−xe^{-x}, much more slowly than the normal's e−x2/2e^{-x^2/2}. Far into the right tail, a Gumbel gives much larger probabilities than a normal with the same centre and spread.

It is tempting to think the maximum of any random values is Gumbel. In fact the limit depends on how the tail of the original distribution behaves. Many light-tailed families give a Gumbel limit for their maxima after shifting and scaling, but heavy-tailed families give different limit shapes, such as the Fréchet family. Sums of random values follow the central limit theorem instead, which gives a normal limit.

It is tempting to think the Gumbel-max trick needs any noise that looks similar. In fact the exact identity depends on the Gumbel shape. Other noise distributions in general give selection probabilities that differ from pjp_j.

It is tempting to think the Gumbel-max trick gives gradients. In fact the hard argmax has no useful gradient. This is the reason the Gumbel-Softmax Trick replaces the argmax with a softmax at a chosen temperature, which trades exactness for a gradient.

When to use the Gumbel. Use it for maxima of many similar quantities, when the data look right-skewed and the upper tail matters, and for the Gumbel-max sampling trick.

When not to use it. Do not use it for heavy-tailed maxima without checking the fit, and do not assume a Gumbel fitted to a small sample describes rare events well.

Alternatives. The Exponential Distribution is the simpler model of waiting times with a constant rate. For maxima of heavy-tailed data, the Fréchet and generalised extreme value families are the usual choices.

History

In 1928, Ronald Fisher and Leonard Tippett showed that the maximum of many independent samples can only converge, after rescaling, to one of a small number of limit shapes. One of these is the Gumbel family.

Emil Gumbel, a statistician, developed the theory of extreme values in the mid-twentieth century, and his book Statistics of Extremes (1958) helped make these methods common in hydrology and engineering.

In machine learning, the Gumbel-max trick for exact sampling from a categorical distribution later became a standard tool. The continuous relaxation, the Gumbel-Softmax Trick, let researchers train networks that make discrete choices.

Recap

  • The standard Gumbel has CDF exp⁡(−e−x)\exp(-e^{-x}), with a longer right tail than the normal.
  • A uniform draw becomes a Gumbel draw by the inverse formula x=−log⁡(−log⁡U)x = -\log(-\log U).
  • Location and scale shift and stretch the curve, with mean μ+βγ\mu + \beta\gamma and variance π2β2/6\pi^2\beta^2/6.
  • For many light-tailed distributions, the maximum of many suitably scaled samples has a Gumbel limit, which is why the family appears in flood and wind studies.
  • Adding independent Gumbel noise to log-probabilities and taking the argmax samples a category exactly, which is the base of the Gumbel-Softmax Trick.

Read next: Gumbel-Softmax Trick for how the noisy argmax becomes differentiable.

Check yourself

QuestionWhat is the CDF of the standard Gumbel distribution?Show answer

F(x)=exp⁡(−e−x)F(x) = \exp(-e^{-x}). Its value is the probability that a standard Gumbel draw is at or below xx.

QuestionA Gumbel has location μ=0\mu = 0 and scale β=2\beta = 2. What is Pr⁡(X≤4)\Pr(X \le 4)?Show answer

Standardise: (4−0)/2=2(4 - 0)/2 = 2. Then exp⁡(−exp⁡(−2))=exp⁡(−0.1353)=0.873\exp(-\exp(-2)) = \exp(-0.1353) = 0.873. So the answer is about 0.873.

QuestionWhy does the Gumbel-max trick take the argmax of noisy log-probabilities, instead of sampling from the probabilities directly?Show answer

Sampling directly needs a random draw and a search through the cumulative probabilities. The trick gives the same distribution with a single pass over the scores: adding independent Gumbel noise and taking the largest is exact, because the Gumbel shape makes the probability that each category wins equal to its probability pjp_j. It also makes the sampling step a comparison of values, which is what the later relaxation builds on.

QuestionA hydrologist says the yearly flood maximum is Gumbel, and a colleague argues the normal distribution with the same mean and spread would give the same extreme-flood probabilities. Who is right, and why?Show answer

The colleague is wrong for extreme levels. The Gumbel has a right tail that decays like e−xe^{-x}, while the normal's decays like e−x2/2e^{-x^2/2}. Far into the right tail the Gumbel gives much larger probabilities, so a normal fit would understate the risk of very large floods.

Sources