GMM E-step (responsibilities)
Background
A Gaussian Mixture Model assumes the data was generated by Gaussian components mixed with weights . EM alternates two steps to fit it; this is the E-step, which computes each point's responsibility — the posterior probability that component generated point — given the current parameters. These soft assignments are GMM's generalisation of k-means' hard assignments.
Problem statement
Implement gmm_e_step(X, weights, means, covariances) that returns the responsibility matrix:
using the multivariate normal density:
Input
X—np.ndarrayof shape(N, D): the data points.weights—np.ndarrayof shape(K,): mixing weights (sum to 1).means—np.ndarrayof shape(K, D): the component means.covariances—np.ndarrayof shape(K, D, D): the component covariance matrices.
Output
Returns an np.ndarray of shape (N, K): each row is a probability distribution over the components (its entries sum to 1).
Examples
Example 1
Input: X = [[0,0],[5,5]], weights = [0.5,0.5],
means = [[0,0],[5,5]], covariances = [I, I]
Output: ~[[1, 0], [0, 1]]
Explanation: the first point sits on component 0's mean and is far from component 1, so almost all its responsibility goes to component 0; the second point is the mirror image.
Constraints
- Use the full multivariate-normal density with each component's own covariance.
- Each output row must sum to — normalise the weighted densities across components.
- Shapes:
Xis(N, D); the output is(N, K). - Tests compare with
atol=1e-6.
Notes
- The E-step yields soft assignments; the M-step (not asked here) re-estimates from these responsibilities, and alternating the two is the EM algorithm.
- As the covariances shrink toward zero the responsibilities harden to 0/1 and GMM collapses to k-means.
This problem ships 4 hidden tests. They run in your browser via Pyodide — no backend, no submission queue. Press ▶ Run tests to execute.
- •Responsibilities form a valid distribution per point
- •A point at a component mean is assigned almost entirely to it
- •Equidistant point with equal components splits 50/50
- •Higher mixing weight shifts responsibility toward that component