Skip to content

Responsibilities

Page 1102 ended with the same factor appearing in every derivative: πkN(xn)\pi_k\mathcal{N}(\mathbf{x}_n\mid\cdot) over the whole mixture density. §11.2.1 gives it a name and a meaning, and the book flags how much work it will do:

But before we do this, we introduce a quantity that will play a central role in the remainder of this chapter: responsibilities.

  • Equation 11.17’s definition, and Equation 11.19 checked entry by entry — including one place the book’s printed matrix disagrees with the arithmetic, by 0.0010.001.
  • Equation 11.24: Nk=nrnkN_k = \sum_n r_{nk}, and kNk=N\sum_k N_k = N to 7.0000000000007.000000000000.
  • The margin note rn\mathbf{r}_n follows a Boltzmann/Gibbs distribution”, verified: rn=softmax(En)\mathbf{r}_n = \mathrm{softmax}(-\mathbf{E}_n) with Enk=logπklogN(xnμk,σk2)E_{nk} = -\log\pi_k - \log\mathcal{N}(x_n\mid\mu_k,\sigma_k^2), matching to 1.1×10161.1\times10^{-16}.
  • What “soft assignment” buys on this data: at the initialisation the least-decided point is x=2x = 2 at 0.9337530.933753; at convergence it is x=0x = 0 at 0.9834690.983469.
  • The entropy of rn\mathbf{r}_n as a measure of how much softness is actually in play — mean 0.0663380.066338 at the start against a maximum of log3=1.098612\log 3 = 1.098612.
  • Shrink every variance and the responsibilities become indicator vectors — which is K-means, exactly as §11.5 says.
  • And a practical trap: Equation 11.17 typed out as written produces 2121 NaNs of 2121 entries once the variances are small; in log-space it produces the exact one-hot answer.

Intuition: a soft assignment is the only thing that can be differentiated

Section titled “Intuition: a soft assignment is the only thing that can be differentiated”

Suppose you knew which component made each point. Then fitting is trivial — split the data and fit each Gaussian to its own share, with the closed forms of Chapter 8. That is the whole difficulty: you do not know.

The obvious repair is to guess — assign each point to its most likely component and fit. That is K-means, and it works, but it throws away the fact that some points are genuinely ambiguous. Worse, it is not differentiable: nudge a parameter and a point’s label jumps discontinuously.

The responsibility is the repair that keeps the calculus. Each point contributes to every component, weighted by how plausible that component makes it. Nothing jumps, everything differentiates, and the hard assignment reappears as a limit.

diagram Where the responsibility comes from and what it becomes mermaid
rnk:=πkN(xnμk,Σk)j=1KπjN(xnμj,Σj)(11.17)r_{nk} := \frac{\pi_k\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)}{\sum_{j=1}^{K}\pi_j\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_j,\boldsymbol\Sigma_j)} \qquad \text{(11.17)}

The responsibility rnkr_{nk} of the kkth mixture component for data point xn\mathbf{x}_n is proportional to the likelihood […] Therefore, mixture components have a high responsibility for a data point when the data point could be a plausible sample from that mixture component.

rn=[rn1,,rnK]\mathbf{r}_n = [r_{n1},\ldots,r_{nK}]^\top is a normalised probability vector, krnk=1\sum_k r_{nk} = 1 with rnk0r_{nk} \geq 0 — a “soft assignment” of xn\mathbf{x}_n to the KK components.

figure Equation 11.19, and the same quantity at every other x matplotlib
Top, two seven-by-three heat maps of responsibilities, mostly bright yellow or dark purple with a few intermediate cells, labelled with their values. Bottom, a stacked area chart across the real line in three colours summing to one everywhere, with seven red triangular markers showing the data. Top, two seven-by-three heat maps of responsibilities, mostly bright yellow or dark purple with a few intermediate cells, labelled with their values. Bottom, a stacked area chart across the real line in three colours summing to one everywhere, with seven red triangular markers showing the data.
Each row of the heat maps sums to 1. The bottom panel is the converged model's responsibilities as continuous functions of x — they partition the line, and the transitions between components are smooth rather than abrupt, which is exactly what makes them differentiable.

Summing down the columns gives Equation 11.24:

Nk:=n=1Nrnk(11.24)N_k := \sum_{n=1}^{N} r_{nk} \qquad \text{(11.24)}
k=1k=1k=2k=2k=3k=3total
NkN_k at the initialisation2.0572282.0572282.0090082.0090082.9337632.9337637.000000000000\mathbf{7.000000000000}

NkN_k is a count that need not be a whole number — the effective number of points each component owns. That it sums to NN exactly is the column-sum counterpart of the rows summing to 11, and it is what makes Equation 11.42’s πk=Nk/N\pi_k = N_k/N a valid set of weights.

rn\mathbf{r}_n follows a Boltzmann/Gibbs distribution.

Write Enk:=logπklogN(xnμk,σk2)E_{nk} := -\log\pi_k - \log\mathcal{N}(x_n\mid\mu_k,\sigma_k^2). Then Equation 11.17 is exactly

rnk=eEnkjeEnj=softmax(En)kr_{nk} = \frac{e^{-E_{nk}}}{\sum_j e^{-E_{nj}}} = \mathrm{softmax}(-\mathbf{E}_n)_k

Measured, maxsoftmax(E)r=1.1×1016\max\lvert\mathrm{softmax}(-\mathbf{E}) - \mathbf{r}\rvert = 1.1\times10^{-16}.

figure The same numbers, as energies and as probabilities matplotlib
Left, three lines of energy against data point, crossing each other so that a different one is lowest in each of three regions. Right, grouped bars of responsibility with a small dark dot sitting exactly on top of every bar. Left, three lines of energy against data point, crossing each other so that a different one is lowest in each of three regions. Right, grouped bars of responsibility with a small dark dot sitting exactly on top of every bar.
On the left the lowest energy wins — but softly, because the gap matters, not just the order. At x = -1 the first two energies are 6.5176 and 3.7128, a gap of 2.8, giving 0.057 against 0.943. The dots on the right are the softmax of the negated energies; they land on the bars to 1.1e-16.

On the book’s seven points, soft assignment is barely being used:

least-decided pointits maxkrnk\max_k r_{nk}points below 0.90.9mean entropy
at the initialisationx=2x = 20.9337530.93375300 of 770.0663380.066338
at convergencex=0x = 00.9834690.98346900 of 770.0138650.013865

against a maximum possible entropy of log3=1.098612\log 3 = 1.098612. Seven well-separated points in one dimension do not need much softness — but the algorithm does, because a hard assignment is not differentiable, and because the book’s own Figure 11.10(b) shows the opposite case: “the responsibilities of these two clusters for those points are around 0.50.5.”

Turn the temperature down and you get K-means

Section titled “Turn the temperature down and you get K-means”

Scaling every variance by tt and letting t0t \to 0:

ttmean maxkrnk\max_k r_{nk}mean entropypoints above 0.990.99
10210^{2}0.5134580.5134580.9430420.94304200
10110^{1}0.7935310.7935310.5144620.51446211
10010^{0}0.9974090.9974090.0138650.01386566
10110^{-1}1.0000001.0000000.0000000.00000077
10610^{-6}1.000000\mathbf{1.000000}0.000000\mathbf{0.000000}7\mathbf{7}
figure The same formula, and the same formula written differently matplotlib
Left, a blue curve rising from about 0.5 to 1 and an amber curve falling from near 1 to 0 as the variance scale decreases, with dotted guide lines at one and one third. Right, a red curve that is flat at zero and then jumps to 21, against a blue dashed line that stays at zero throughout. Left, a blue curve rising from about 0.5 to 1 and an amber curve falling from near 1 to 0 as the variance scale decreases, with dotted guide lines at one and one third. Right, a red curve that is flat at zero and then jumps to 21, against a blue dashed line that stays at zero throughout.
Left: at large variances every component is equally plausible and the responsibilities approach 1/K; at small variances they become indicator vectors, which is K-means. Right: the naive form of Equation 11.17 computes zero over zero once the densities underflow, returning NaN for all 21 entries, while the log-space form returns the exact one-hot answer.

§11.5 states the relationship: “If we treat the means in the GMM as cluster centers and ignore the covariances (or set them to I\mathbf{I}), we arrive at K-means. […] K-means makes a ‘hard’ assignment of data points to cluster centers, whereas a GMM makes a ‘soft’ assignment via the responsibilities.”

On this data, run from the book’s own starting means, the two do not land in the same place:

centrescluster sizeswithin-cluster SS
GMM at convergence2.750036, 0.504119, 3.644573-2.750036,\ -0.504119,\ 3.6445731.982478, 1.999703, 3.0178191.982478,\ 1.999703,\ 3.017819
K-means from [4,0,8][-4, 0, 8]2.166667, 1.000000, 4.500000-2.166667,\ 1.000000,\ 4.5000003,2,23, 2, 24.666667\mathbf{4.666667}
K-means handed the GMM’s answer2.750000, 0.500000, 3.666667-2.750000,\ -0.500000,\ 3.6666672,2,32, 2, 35.2916675.291667

Two things worth separating. From the same start the two algorithms disagree by 1.5041191.504119 — they split the seven points differently, 3 ⁣ ⁣2 ⁣ ⁣23\!-\!2\!-\!2 against effectively 2 ⁣ ⁣2 ⁣ ⁣32\!-\!2\!-\!3. And the GMM’s partition is not even the better K-means answer: its within-cluster sum of squares is 5.2916675.291667 against 4.6666674.666667.

The reason is in the last row of the GMM’s parameters: its variances are 0.06250.0625, 0.2505810.250581 and 1.6289411.628941 — a factor of 26.0626.06 apart. K-means has no variances, so it cannot prefer a tight cluster of two over a loose cluster of three. Only if you hand K-means the GMM’s own answer does it stay there, and then the centres agree to 0.0220940.022094 and the counts differ only by being integers.

pch.quizTag Are responsibilities clear?
  1. What is r_nk, in one sentence?

    pch.quizShowAnswer

    B — The share of x_n that component k is credited with — its weighted density over the whole mixture's density at that point — Equation 11.17. Each row sums to one, so it is a probability vector over components — a soft assignment. Section 11.4.3 later identifies it as a genuine posterior, the probability that the k-th component generated the n-th point.

  2. The book's margin note calls r_n a Boltzmann distribution. Is that exact?

    pch.quizShowAnswer

    B — It is exact: r_n is the softmax of minus the energies -log pi_k - log N(x_n | k), matching to 1.1e-16 — And the framing pays: the ratio of two responsibilities is the exponential of their energy gap, the mixture weight enters as a uniform offset, and scaling all the variances by t is exactly a temperature. The last of those is the K-means limit.

  3. What is N_k, and why need it not be a whole number?

    pch.quizShowAnswer

    B — The column sum of the responsibilities — an effective count, fractional because the assignment is soft, summing to N exactly — Measured at the book's initialisation: 2.057228, 2.009008 and 2.933763, summing to 7.000000000000. K-means from the same start gives integer sizes 3, 2 and 2 — a different split entirely, because it has no variances with which to prefer a tight cluster over a loose one.

  4. What goes wrong if you code Equation 11.17 exactly as printed?

    pch.quizShowAnswer

    B — Numerator and denominator both underflow to zero, giving NaN — all 21 entries of a 7-by-3 matrix once the variances are small — The fix is to work in log-space: add the log weight to the log density, subtract the row's logsumexp, exponentiate. Where both forms work they agree to 2.2e-16. This is not exotic — in D dimensions the log-density scales with D, so 784-pixel images hit it at ordinary parameter values.

Exercise 1 – Check Equation 11.19 against the arithmetic

Section titled “Exercise 1 – Check Equation 11.19 against the arithmetic”

Exercise 2 – The margin note, as arithmetic

Section titled “Exercise 2 – The margin note, as arithmetic”

Exercise 3 – How much softness is actually used

Section titled “Exercise 3 – How much softness is actually used”

Exercise 5 – Soft counts against hard counts

Section titled “Exercise 5 – Soft counts against hard counts”
  • The responsibility is the factor that appeared in every derivative on the previous page, given a name: component k’s weighted density at a point, over the whole mixture’s density there.
  • Each row is a probability vector, so responsibilities are a soft assignment of a point to the components.
  • Summing down a column gives N_k, the effective number of points a component owns — fractional, and summing to N exactly.
  • The book’s printed responsibility matrix disagrees with the arithmetic at one entry, by 0.001; the computed value at x equal to zero is 0.000150, not 0.001.
  • The margin note is exact, not a metaphor: the responsibility vector is the softmax of minus the energies, matching to 1.1e-16.
  • So the ratio of two responsibilities is the exponential of their energy gap, the mixture weights enter as a uniform offset, and the variances act as a temperature.
  • On the book’s seven points the softness is barely used — mean entropy 0.014 at convergence against a possible 1.099 — because the clusters are well separated.
  • Shrinking every variance drives the responsibilities to indicator vectors, which is K-means. Section 11.5 says exactly this.
  • But from the same starting means they do not agree: centres 1.504119 apart, splitting the points 3-2-2 against effectively 2-2-3, because K-means has no variances to weigh a tight cluster against a loose one.
  • Equation 11.17 typed out as written divides a vanishing number by a vanishing number, returning NaN for all 21 entries once the variances are small.
  • In log-space it returns the exact answer, and where both work they agree to 2.2e-16.
  • A hard assignment is not a rounding of a soft one — it is a different algorithm, and the soft version is the one that can be differentiated.

Next: Updating the Means — §11.2.2, the first of three updates, and the one the book draws a picture for.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading