Dirichlet processes
A mixture whose number of clusters is inferred from the data rather than fixed in advance: the Dirichlet distribution and the limit $K \to \infty$, the Chinese restaurant process, the expected number of clusters $\approx \alpha \log(1 + n/\alpha)$, stick-breaking, the definition of a Dirichlet process, DP mixtures and collapsed Gibbs sampling.
A mixture with unknown $K$
The topic Gaussian processes put a prior on functions, and the model grew with the data: every new input added a new value to the prior. For clustering we need the same trick one level up, a prior over partitions of the data.
Recall the two-component Gaussian mixture of the topic EM and Bayesian PCA. EM fitted it well, but we had to choose before seeing the data. In practice one fits several and compares them by BIC or by evidence (the topic Bayesian model selection). Can the number of clusters instead be inferred together with everything else, and grow when more data arrive?
The first tool is the Dirichlet distribution, the multi-outcome version of the Beta. A vector on the simplex (, ) has the density
Three facts are enough for this topic:
- the mean is , and with the Dirichlet is exactly ;
- aggregation: merging components adds their parameters, e.g. ;
- conjugacy with categorical labels: after counts the posterior is .
Now a finite Bayesian mixture with symmetric weights:
Here is the base distribution of cluster parameters and the likelihood of one cluster; with Gaussian this is the mixture from EM with priors added. Integrating out gives the posterior predictive of the next label, the posterior mean of :
With and this is the coin from the topic The Bayesian approach: three heads give .
Letting $K$ go to infinity
Let the number of components go to infinity while stays fixed. Look at the predictive rule from the previous block.
An occupied cluster with points gets
Any single empty cluster gets . But there are empty clusters, where is the number of occupied ones, and together they get
So in the limit the next point either joins one of the existing clusters or opens a new one, and has disappeared from the rule. The labels themselves lose meaning: "cluster number 7" is one of infinitely many interchangeable empty slots. What remains is which points share a cluster, a partition of the data.
The division by matters. With weights the total parameter would be , the new-cluster probability would tend to , and every point would sit alone.
A word on . In the topics Bayesian linear regression and The relevance vector machine the letter was a prior precision, an inverse variance. Here it is something else: the concentration parameter, the total weight of the Dirichlet. It is not an inverse variance of anything. It works like a prior sample size: with new clusters open often, with rarely.
The Chinese restaurant process
The limiting rule has a name and a story, the Chinese restaurant process (CRP). A restaurant has infinitely many tables. Customers are data points, tables are clusters.
- The first customer sits at the first table.
- Customer sits at an occupied table with probability , or at a new table with probability .
Popular tables attract more customers: the rich-get-richer effect. A few large clusters and a tail of small ones is the typical picture.
The probability of a whole seating is a product of these choices. Take and four customers who sit A, A, B, B:
In general each table contributes when it opens and then as it fills, while the denominators multiply to . For tables with sizes :
For A, A, B, B: , as before.
The formula depends only on the table sizes, not on the order of arrival. The CRP is exchangeable: shuffling the customers does not change the probability of a partition. Hence any customer can be treated as the last one to arrive, and that is exactly what a Gibbs sampler will need.
How many clusters
How many tables does the restaurant have after customers? Customer opens a new table with probability , whatever the earlier customers did. So the number of tables is a sum of independent indicators, and
The approximation replaces the sum by an integral; the gap stays below one. For :
| exact | ||
|---|---|---|
A simulation of 5,000 restaurants with gives tables on average.
The growth is logarithmic: doubling the data adds about clusters. With , going from to moves from to , an increase of . Compare the Gaussian process, which keeps one value per data point.
In practice is set by inverting this formula from a rough guess of the number of clusters, or given a Gamma prior and sampled together with the labels. It strongly affects the number of clusters and only weakly the predictions.
Stick-breaking
The CRP describes partitions; the mixing weights themselves have been integrated out. Stick-breaking builds them explicitly.
Take a stick of length one. Break off a random fraction ; that piece is . From what is left, break off a fraction ; that is . Continue forever:
Here is a point mass at , so is a random discrete distribution: countably many atoms with weights .
Why . Watch the first table in the CRP. After the first customer it has weight and "everything else" has weight ; each new customer joins the first table with probability and otherwise adds to the rest. This is a Pólya urn, and the long-run share of the first table is . A simulation of 2,000 restaurants with and 500 customers gives a mean share of against .
Since , the first piece has . Small means large first pieces and few clusters; large means many small pieces. The fractions are independent, so the expected mass still unbroken after pieces is
This gives truncation: stop after pieces and give the last one the remainder. The error is bounded by the leftover mass. With and the expected leftover is ; with it is still . Truncated stick-breaking is what variational inference for DP mixtures uses, for example BayesianGaussianMixture in scikit-learn.
What a Dirichlet process is
The built by stick-breaking is a draw from a Dirichlet process. The formal definition says what its masses on sets look like. if for every partition of the parameter space
The definitions for coarse and fine partitions agree thanks to the aggregation property. Taking the partition gives , hence
So is the mean of the random distribution, and says how tightly concentrates around it. With , the standard deviation of is at and at ; a stick-breaking simulation agrees. Yet even with a smooth , every draw is discrete almost surely, so repeated draws from it coincide. Those coincidences are the clusters.
The analogy with the previous topic:
| Gaussian process | Dirichlet process | |
|---|---|---|
| indexed by | inputs | sets |
| a draw is | a function | a distribution |
| finite marginals | Gaussian | Dirichlet |
| specified by | mean , kernel | base , concentration |
Posterior. Observe . Every partition is a Dirichlet–categorical update, so the posterior is again a Dirichlet process:
The new base mixes the prior with weight and the observed values with weight . Its mean predicts : a fresh draw from with probability , otherwise a copy of one of the old . That is the Chinese restaurant once more.
DP mixtures and collapsed Gibbs
A Dirichlet process mixture puts a DP under the cluster parameters:
Because is discrete, many coincide, and points with equal form a cluster. Integrating out gives an equivalent model: labels from the CRP, for each table, . This is the limit of the finite mixture from the first block, an infinite Gaussian mixture when is Gaussian.
Collapsed Gibbs sampling (see the topic Gibbs sampling and Metropolis–Hastings). With a conjugate the cluster parameters can be integrated out, and the sampler works on the labels only. By exchangeability, treat point as the last customer: remove it, then reseat it with
The first factor is the CRP prior; counts cluster without . The second is a posterior predictive: given the other points of cluster , or given nothing for a new cluster. If removing empties a cluster, that cluster disappears.
For 1-D Gaussian clusters with known variance and , the predictive is the Normal-mean update from the topic Conjugate priors and the exponential family. For a cluster with points and sum :
A new cluster uses . Example: , , , ; cluster A has 4 points with mean , cluster B has 2 points with mean ; reseat .
| option | CRP factor | predictive | density at | weight | probability |
|---|---|---|---|---|---|
| A | |||||
| B | |||||
| new |
B wins although it is half the size of A: the point is close to it. One sweep reseats every point in turn.
Where it breaks and what comes next
Three caveats are worth knowing before using DP mixtures in practice.
- Slow mixing. Gibbs moves one point at a time. Merging two halves of a true cluster requires passing through improbable intermediate states, so a split cluster can stay split for many sweeps. Split–merge moves, which propose to move whole groups at once, help.
- A rigid prior. One number sets both the expected number of clusters and the rich-get-richer size pattern. Power-law cluster sizes call for the Pitman–Yor process, which adds a discount parameter and grows faster than .
- Inconsistency for the number of clusters. Even when the data come from a finite mixture, the posterior of a DP mixture does not concentrate on the true number of components. Miller and Harrison showed this for data from one standard normal modelled by a DP mixture of unit-variance normals: the posterior probability of one cluster tends to zero. A small extra cluster costs little in the prior and changes the density almost nowhere. So DP mixtures are a good tool for density estimation and a poor one for counting clusters.
So far every data point had one cluster. A text document is different: it mixes several topics, and the same topics recur across documents. That is a mixture of mixtures, with a Dirichlet prior on each document's topic proportions. The next topic, Latent Dirichlet allocation, builds exactly this model with a fixed number of topics; its nonparametric version, the hierarchical Dirichlet process, lets all documents share the atoms of one DP.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.