Chapter 6 · Probability & Distributions¶
End-of-chapter exercises. Each has a definitions box, explanation, worked steps, and the answer.
6.1 · Marginal and conditional distributions¶
Consider the following bivariate distribution \(p(x,y)\) of two discrete random variables \(X\) and \(Y\).
| \(x_1\) | \(x_2\) | \(x_3\) | \(x_4\) | \(x_5\) | |
|---|---|---|---|---|---|
| \(y_1\) | 0.01 | 0.02 | 0.03 | 0.1 | 0.1 |
| \(y_2\) | 0.05 | 0.1 | 0.05 | 0.07 | 0.2 |
| \(y_3\) | 0.1 | 0.05 | 0.03 | 0.05 | 0.04 |
Compute (a) the marginal distributions \(p(x)\) and \(p(y)\), and (b) the conditional distributions \(p(x \mid Y = y_1)\) and \(p(y \mid X = x_3)\).
Topics & Definitions
- Joint distribution — \(p(x_i, y_j)\) gives the probability that \(X = x_i\) and \(Y = y_j\) occur together. Every cell of the table is one joint probability, and all fifteen cells sum to \(1\).
- Marginal distribution (sum rule) — to recover the distribution of one variable alone, sum the joint over every value of the other:
Summing over \(y\) collapses the table to a single row of \(x\) probabilities, and summing over \(x\) collapses it to a single column of \(y\) probabilities. The table here is already normalised, so a column or row total is the probability directly, with no further division.
- Conditional distribution — conditioning fixes one variable and renormalises the surviving slice so it is a valid distribution again:
Because the divisor is the exact total of the slice, each conditional sums to \(1\) by construction. This gives a free correctness check on every conditional computed.
Marginals of \(X\) (column sums)
Check: \(0.16 + 0.17 + 0.11 + 0.22 + 0.34 = 1\).
Marginals of \(Y\) (row sums)
Check: \(0.26 + 0.47 + 0.27 = 1\). Both marginals summing to \(1\) confirms the joint table is normalised and the arithmetic holds in both directions.
Conditional \(p(x \mid Y = y_1)\)
Fix \(Y = y_1\), take that row, divide every entry by \(p(y_1) = 0.26\):
Check: numerators over the common denominator \(26\) give \(1 + 2 + 3 + 10 + 10 = 26\), so the conditional sums to \(1\).
Conditional \(p(y \mid X = x_3)\)
Fix \(X = x_3\), take that column, divide every entry by \(p(x_3) = 0.11\):
Check: \(3 + 5 + 3 = 11\), so the conditional sums to \(1\).
Answer
a) Marginal of \(X\): \(p(x) = (0.16,\ 0.17,\ 0.11,\ 0.22,\ 0.34)\) for \(x_1\) through \(x_5\).
Marginal of \(Y\): \(p(y) = (0.26,\ 0.47,\ 0.27)\) for \(y_1\) through \(y_3\).
b) \(p(x \mid Y = y_1) = \left(\tfrac{1}{26},\ \tfrac{1}{13},\ \tfrac{3}{26},\ \tfrac{5}{13},\ \tfrac{5}{13}\right)\)
\(p(y \mid X = x_3) = \left(\tfrac{3}{11},\ \tfrac{5}{11},\ \tfrac{3}{11}\right)\)
6.2 · Marginals of a Gaussian mixture¶
Consider a mixture of two Gaussian distributions,
Compute (a) the marginal distributions for each dimension, (b) the mean, mode and median of each marginal, and (c) the mean and mode of the two-dimensional distribution.
Part a
Compute the marginal distributions for each dimension.
Topics & Definitions
- Mixture distribution — a weighted sum of component densities, \(p(\boldsymbol{x}) = \sum_k \pi_k\, p_k(\boldsymbol{x})\), with weights \(\pi_k \ge 0\) summing to \(1\). Here \(\pi_1 = 0.4\) and \(\pi_2 = 0.6\).
- Marginalising a Gaussian is just deleting — for \(\mathcal{N}(\boldsymbol{\mu}, \Sigma)\), the marginal of one coordinate is \(\mathcal{N}(\mu_i, \Sigma_{ii})\): keep that entry of the mean and the matching diagonal entry of the covariance, and discard every row and column belonging to the variable being integrated out. No integration is actually performed.
- Off-diagonal entries drop out — the covariance \(\Sigma_{12} = 2.0\) describes how the two coordinates vary together, which is information about the pair. Once one coordinate is marginalised away there is no pair left, so that entry plays no part in the answer.
- Marginal of a mixture is the mixture of the marginals — integration is linear, so it passes through the weighted sum:
The weights \(0.4\) and \(0.6\) are therefore unchanged by marginalising. Only the components simplify.
Marginal of the first dimension
Take the first entry of each mean and the top-left entry of each covariance.
Component 1: \(\mu_1 = 10\) and \(\Sigma_{11} = 1\), giving \(\mathcal{N}(10,\ 1)\).
Component 2: \(\mu_1 = 0\) and \(\Sigma_{11} = 8.4\), giving \(\mathcal{N}(0,\ 8.4)\).
Reattaching the weights:
Marginal of the second dimension
Take the second entry of each mean and the bottom-right entry of each covariance.
Component 1: \(\mu_2 = 2\) and \(\Sigma_{22} = 1\), giving \(\mathcal{N}(2,\ 1)\).
Component 2: \(\mu_2 = 0\) and \(\Sigma_{22} = 1.7\), giving \(\mathcal{N}(0,\ 1.7)\).
Reattaching the weights:
Part a answer
Each marginal is again a mixture of two univariate Gaussians, with the original weights:
The variances quoted are \(\Sigma_{11}\) and \(\Sigma_{22}\) respectively, so the standard deviations are \(\sqrt{8.4} \approx 2.898\) and \(\sqrt{1.7} \approx 1.304\) for the second component.
Spotted a mistake or a step that doesn't make sense? Open an issue and I'll fix it.
Finding these useful? A star on GitHub helps other learners find them.