Search

Search papers and lessons

Dirichlet Distribution

Level 3 · 9 min read

The Dirichlet distribution is a probability distribution over lists of proportions that add up to 1, such as the shares of a pie, and it is the standard prior for unknown proportions.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Probability
  • Sign in to see your progress

TL;DR

Sometimes the unknown is not a single number but a list of shares: the fraction of voters for each party, the fraction of a document about each topic, or the fraction of a population in each category. The Dirichlet distribution is a probability distribution over such lists. Every draw is a set of non-negative numbers that add up to 1, so it describes a random pie.

Its settings are one positive number per slice. Large settings make the pie close to evenly split. Small settings make it likely that one slice takes almost everything. Because it matches counts so cleanly, it is the standard prior for unknown proportions in Bayesian statistics.

Where you'll see it: as the prior over topic mixtures in topic models, as the prior over category probabilities in classification and counting problems, and inside samplers for random probability vectors.

Intuition

Start from a question you already know

Suppose you ask 200 people which of four brands they prefer, and 80 choose brand A, 50 choose B, 40 choose C and 30 choose D. You want to estimate each brand's share of the market. The answers are counts, but what you want is a set of proportions that add up to 1.

Before any survey, you may have a rough feeling about the shares, but you are not sure. A distribution over proportions lets you write that feeling down as a starting belief (a prior), then update it with the counts using Bayes' Rule. The Dirichlet distribution is the natural starting belief for that job.

A random pie

Picture a pie cut into slices. A draw from a Dirichlet distribution gives you the size of each slice. The slices always add up to the whole pie, so the total is fixed at 1, and no slice can be negative.

The settings α1,…,αK\alpha_1, \dots, \alpha_K, one per slice, control the shape. Think of them as pseudo-counts: how many imaginary observations you have already seen for each slice. If all settings are equal and large, the pie is almost always close to evenly split. If one setting is large and the rest are small, that slice tends to dominate.

00.20.40.60.8100.511.522.53share of the first slice, xdensity
  • α = (1, 1)
  • α = (3, 3)
  • α = (2, 5)
With two slices the Dirichlet is a Beta distribution. Equal settings give a flat curve (1, 1) or a bump in the middle (3, 3). Unequal settings move the mass: with (2, 5) the first share is probably small.

The plot shows the two-slice case, where the first slice is xx and the second is 1−x1 - x. The curves are densities, so the area under each one is 1.

The math

Definition

Definition: Dirichlet distribution

Let α1,…,αK>0\alpha_1, \dots, \alpha_K \gt 0 and α0=α1+⋯+αK\alpha_0 = \alpha_1 + \cdots + \alpha_K. A random vector x=(x1,…,xK)\mathbf{x} = (x_1, \dots, x_K) is Dirichlet distributed, written x∼Dir(α)\mathbf{x} \sim \mathrm{Dir}(\boldsymbol{\alpha}), if xk≥0x_k \ge 0, ∑kxk=1\sum_k x_k = 1, and its density over the first K−1K-1 coordinates is

p(x)=Γ(α0)Γ(α1)⋯Γ(αK)∏k=1Kxkαk−1.p(\mathbf{x}) = \frac{\Gamma(\alpha_0)}{\Gamma(\alpha_1)\cdots\Gamma(\alpha_K)} \prod_{k=1}^{K} x_k^{\alpha_k - 1}.

Here xkx_k is the share of slice kk. The vector α\boldsymbol{\alpha} collects the settings. The symbol Γ\Gamma is the Gamma Function, which extends factorials to non-integers: Γ(n)=(n−1)!\Gamma(n) = (n-1)! for a whole number nn. The fraction in front is a normalising constant, the number that makes the total probability equal 1. The product ∏kxkαk−1\prod_k x_k^{\alpha_k - 1} is larger where the shares match the large settings, which is why large settings pull the pie towards a particular shape.

Two checks make the definition concrete. When K=2K = 2, write x1=xx_1 = x and x2=1−xx_2 = 1 - x. The density becomes Γ(α1+α2)Γ(α1)Γ(α2)xα1−1(1−x)α2−1\frac{\Gamma(\alpha_1 + \alpha_2)}{\Gamma(\alpha_1)\Gamma(\alpha_2)} x^{\alpha_1 - 1}(1-x)^{\alpha_2 - 1}, which is the Beta distribution. When α=(1,1)\boldsymbol{\alpha} = (1, 1), both gamma terms are Γ(1)=1\Gamma(1) = 1 and Γ(2)=1\Gamma(2) = 1, so the density is 11 everywhere: every split is equally likely.

Key results

Mean. Each share has expected value

E[xk]=αkα0.\mathbb{E}[x_k] = \frac{\alpha_k}{\alpha_0}.

The settings act as relative sizes, and α0\alpha_0 sets how many pseudo-observations the prior is worth.

Variance (see Mean and Variance).

Var(xk)=αk(α0−αk)α02(α0+1).\mathrm{Var}(x_k) = \frac{\alpha_k(\alpha_0 - \alpha_k)}{\alpha_0^2(\alpha_0 + 1)}.

The variance shrinks as α0\alpha_0 grows. A large α0\alpha_0 concentrates the pie near its mean.

Conjugacy. Suppose the shares are the unknown probabilities of KK categories, and you observe counts n1,…,nKn_1, \dots, n_K with total NN. A prior Dir(α)\mathrm{Dir}(\boldsymbol{\alpha}) combined with these counts gives a posterior

Dir(α1+n1,…,αK+nK).\mathrm{Dir}(\alpha_1 + n_1, \dots, \alpha_K + n_K).

The posterior is again Dirichlet, so updating is just adding counts to the settings. This is called a conjugate prior: the prior and posterior belong to the same family. The posterior mean is

E[xk∣data]=αk+nkα0+N.\mathbb{E}[x_k \mid \text{data}] = \frac{\alpha_k + n_k}{\alpha_0 + N}.

Sampling through gammas. If G1,…,GKG_1, \dots, G_K are independent Gamma random variables with shape αk\alpha_k and scale 1 (see Gamma Distribution), then (G1,…,GK)/∑jGj(G_1, \dots, G_K)/\sum_j G_j is Dirichlet with settings α\boldsymbol{\alpha}. This gives the standard recipe for drawing a random pie on a computer.

Algorithm
Draw one Dirichlet sample
  1. For each kk, draw GkG_k from a Gamma distribution with shape αk\alpha_k and scale 1.
  2. Compute the total T=∑kGkT = \sum_k G_k.
  3. Return the vector (G1/T,…,GK/T)(G_1 / T, \dots, G_K / T).

Worked examples

Example
Example 1: two slices, all settings 1 (tiny)

Take K=2K = 2 and α=(1,1)\boldsymbol{\alpha} = (1, 1).

  1. The normalising constant is Γ(2)Γ(1)Γ(1)=11⋅1=1\frac{\Gamma(2)}{\Gamma(1)\Gamma(1)} = \frac{1}{1 \cdot 1} = 1.
  2. The product of powers is x0(1−x)0=1x^0 (1-x)^0 = 1.
  3. So the density is 11 on [0,1][0, 1]. Every share of the first slice is equally likely.
  4. Interpretation: with no prior evidence at all, the Dirichlet with all settings 1 is a flat, uninformative belief.
Example
Example 2: updating a prior with counts (standard)

Start with a prior Dir(1,1,1)\mathrm{Dir}(1, 1, 1) over three categories, which is flat, and observe counts (5,2,3)(5, 2, 3) out of N=10N = 10.

  1. The posterior is Dir(1+5,1+2,1+3)=Dir(6,3,4)\mathrm{Dir}(1 + 5, 1 + 2, 1 + 3) = \mathrm{Dir}(6, 3, 4).
  2. Total posterior setting: α0=6+3+4=13\alpha_0 = 6 + 3 + 4 = 13.
  3. Posterior means: 613≈0.462\frac{6}{13} \approx 0.462, 313≈0.231\frac{3}{13} \approx 0.231, 413≈0.308\frac{4}{13} \approx 0.308.
  4. Check: 0.462+0.231+0.308=1.0010.462 + 0.231 + 0.308 = 1.001, which is 1 up to rounding.
  5. Interpretation: the observed shares 0.5, 0.2 and 0.3 are pulled slightly towards the flat prior, because the prior counts three pseudo-observations, one per category.
Example
Example 3: a market survey with a stronger prior (realistic, illustrative)

Four brands are compared using a prior Dir(2,2,2,2)\mathrm{Dir}(2, 2, 2, 2), which says the shares are probably near equal but not certain. The survey of 200 people gives counts (80,50,40,30)(80, 50, 40, 30).

  1. Posterior settings: (2+80,2+50,2+40,2+30)=(82,52,42,32)(2 + 80, 2 + 50, 2 + 40, 2 + 30) = (82, 52, 42, 32).
  2. Total posterior setting: α0=82+52+42+32=208\alpha_0 = 82 + 52 + 42 + 32 = 208.
  3. Posterior means: brand A 82208≈0.394\frac{82}{208} \approx 0.394, brand B 52208=0.250\frac{52}{208} = 0.250, brand C 42208≈0.202\frac{42}{208} \approx 0.202, brand D 32208≈0.154\frac{32}{208} \approx 0.154.
  4. Posterior variance for brand A: 82(208−82)2082⋅209=103329042176≈0.00114\frac{82(208 - 82)}{208^2 \cdot 209} = \frac{10332}{9042176} \approx 0.00114, so its standard deviation is about 0.0340.034.
  5. Interpretation: the best estimate for brand A's share is about 39 percent, with a spread of roughly 3 to 4 percentage points. The prior of 8 pseudo-observations pulls the raw 40 percent down only a little, because the survey has 200 real answers.

Tradeoffs and failure modes

The Dirichlet is the simplest natural model for shares, but it has limits.

SituationProblemBetter choice
Shares you expect to be correlated (two topics that appear together)A Dirichlet forces every pair of shares to be negatively correlatedA logistic-normal model, which allows positive correlation
Very small settings, such as 0.01Draws land almost always at a corner with one slice near 1Choose settings near 1, or check the draws visually
Many categories with a very uneven spreadOne setting cannot capture both the many small and the few large shares wellA hierarchical prior, or a model over the groups first
Shares that change over timeA single Dirichlet has no time dynamicsA dynamic model on the log-scale of shares

The settings are easy to misread. The ratio αk/α0\alpha_k / \alpha_0 is the mean share, while α0\alpha_0 controls how tightly the draws cluster. Two priors with the same means can behave very differently if their total settings differ.

History

Peter Gustav Lejeune Dirichlet, a German mathematician of the 19th century, studied the multiple integrals that now carry his name, and the distribution is named after those integrals. Its use as a probability model came later, when Bayesian statistics adopted it as the standard prior for proportions, since its conjugacy made the update a matter of adding counts.

It became widely known in machine learning after Blei, Ng and Jordan used it as the prior over topic mixtures in Latent Dirichlet Allocation in 2003. That model made the Dirichlet a standard building block in text analysis and beyond.

Recap

A Dirichlet distribution describes random lists of shares that add up to 1. Its settings act as pseudo-counts, so the mean share is αk/α0\alpha_k / \alpha_0. Because it is conjugate to counts, updating the prior with data just adds the counts to the settings. With two slices it reduces to the Beta distribution, and mixture models use it to treat the shares as mixing weights.

Check yourself

QuestionRecall. What two properties must every draw from a Dirichlet distribution have?Show answer

Every share must be non-negative, and the shares must add up to 1. These are what make a draw a valid random pie.

QuestionComputation. A prior is Dir(2,2)\mathrm{Dir}(2, 2) and the data are 7 successes in the first slice and 3 in the second. What is the posterior mean of the first share?Show answer

The posterior is Dir(2+7,2+3)=Dir(9,5)\mathrm{Dir}(2 + 7, 2 + 3) = \mathrm{Dir}(9, 5). The posterior mean of the first share is 99+5=914≈0.643\frac{9}{9 + 5} = \frac{9}{14} \approx 0.643.

QuestionWhy. Why does a large total setting α0\alpha_0 make the draws cluster tightly around the mean?Show answer

The variance formula αk(α0−αk)α02(α0+1)\frac{\alpha_k(\alpha_0 - \alpha_k)}{\alpha_0^2(\alpha_0 + 1)} has α02\alpha_0^2 in the denominator, so it shrinks as α0\alpha_0 grows. A large total means many pseudo-observations, so the random shares are pinned close to αk/α0\alpha_k / \alpha_0.

QuestionApplied. A document in a topic model is believed to mix three topics roughly equally, with a total prior weight of 3. Which prior would you choose, and what is the mean topic share?Show answer

Choose Dir(1,1,1)\mathrm{Dir}(1, 1, 1). Its total weight is 3, its mean share for each topic is 13≈0.333\frac{1}{3} \approx 0.333, and it is flat over all possible splits, so it does not favour any particular mix. If the belief were stronger, one would keep the mean at 1/31/3 but raise the total weight, for example to Dir(10,10,10)\mathrm{Dir}(10, 10, 10), which concentrates the draws around it.

Sources