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 , 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.
- α = (1, 1)
- α = (3, 3)
- α = (2, 5)
The plot shows the two-slice case, where the first slice is and the second is . The curves are densities, so the area under each one is 1.
The math
Definition
Let and . A random vector is Dirichlet distributed, written , if , , and its density over the first coordinates is
Here is the share of slice . The vector collects the settings. The symbol is the Gamma Function, which extends factorials to non-integers: for a whole number . The fraction in front is a normalising constant, the number that makes the total probability equal 1. The product 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 , write and . The density becomes , which is the Beta distribution. When , both gamma terms are and , so the density is everywhere: every split is equally likely.
Key results
Mean. Each share has expected value
The settings act as relative sizes, and sets how many pseudo-observations the prior is worth.
Variance (see Mean and Variance).
The variance shrinks as grows. A large concentrates the pie near its mean.
Conjugacy. Suppose the shares are the unknown probabilities of categories, and you observe counts with total . A prior combined with these counts gives a posterior
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
Sampling through gammas. If are independent Gamma random variables with shape and scale 1 (see Gamma Distribution), then is Dirichlet with settings . This gives the standard recipe for drawing a random pie on a computer.
- For each , draw from a Gamma distribution with shape and scale 1.
- Compute the total .
- Return the vector .
Worked examples
Take and .
- The normalising constant is .
- The product of powers is .
- So the density is on . Every share of the first slice is equally likely.
- Interpretation: with no prior evidence at all, the Dirichlet with all settings 1 is a flat, uninformative belief.
Start with a prior over three categories, which is flat, and observe counts out of .
- The posterior is .
- Total posterior setting: .
- Posterior means: , , .
- Check: , which is 1 up to rounding.
- 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.
Four brands are compared using a prior , which says the shares are probably near equal but not certain. The survey of 200 people gives counts .
- Posterior settings: .
- Total posterior setting: .
- Posterior means: brand A , brand B , brand C , brand D .
- Posterior variance for brand A: , so its standard deviation is about .
- 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.
| Situation | Problem | Better choice |
|---|---|---|
| Shares you expect to be correlated (two topics that appear together) | A Dirichlet forces every pair of shares to be negatively correlated | A logistic-normal model, which allows positive correlation |
| Very small settings, such as 0.01 | Draws land almost always at a corner with one slice near 1 | Choose settings near 1, or check the draws visually |
| Many categories with a very uneven spread | One setting cannot capture both the many small and the few large shares well | A hierarchical prior, or a model over the groups first |
| Shares that change over time | A single Dirichlet has no time dynamics | A dynamic model on the log-scale of shares |
The settings are easy to misread. The ratio is the mean share, while 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 . 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 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 . The posterior mean of the first share is .
QuestionWhy. Why does a large total setting make the draws cluster tightly around the mean?Show answer
The variance formula has in the denominator, so it shrinks as grows. A large total means many pseudo-observations, so the random shares are pinned close to .
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 . Its total weight is 3, its mean share for each topic is , 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 but raise the total weight, for example to , which concentrates the draws around it.