fair_probs = torch.tensor([0.5, 0.5])
Multinomial(100, fair_probs).sample()Dive into Deep Learning · §1.6
Probability and Statistics: Reasoning Under Uncertainty in Machine Learning
aleatoric vs. epistemic uncertainty · distributions & conditioning · Bayes’ theorem · expectation & covariance · \sigma/\sqrt{n} error bars
Motivation
Taxonomy of Uncertainty
From Models to Data
Drawing realizations from a distribution P is called sampling. For n independent tosses of a fair coin with P = (0.5, 0.5), the count vector follows a multinomial distribution:
tensor([48., 52.])
tensor([[0.5000, 0.5000],
[0.4500, 0.5500],
[0.5000, 0.5000],
[0.4900, 0.5100],
[0.5800, 0.4200]])
Asymptotic Consistency
cumsum illustrates the Law of Large Numbers (LLN): \hat{p}_n = \frac{1}{n}\sum_{i=1}^n X_i \xrightarrow{n \to \infty} p = 0.5The missing piece: The LLN guarantees eventual convergence as n \to \infty, but does not tell us how fast estimation error shrinks at finite n.
Rate of Convergence
Foundations of Probability
Die roll (\mathcal{S} = \{1,\ldots,6\}): For \mathcal{A} = \{2, 4, 6\} (even) and \mathcal{B} = \{5, 6\} (\ge 5), \mathcal{A} \cap \mathcal{B} = \{6\}, so P(\mathcal{A} \cup \mathcal{B}) = \frac{3}{6} + \frac{2}{6} - \frac{1}{6} = \frac{2}{3}.
Random Variables & Distributions
Sum Rule & Product Rule
sum(axis=1)): P(X = x) = \sum_y P(X = x, Y = y)Inverse Probability
Graphical Structure & Conditioning
First Moment
Second Central Moment
Co-Movement & 1/√n Scaling
Statistical Significance
def fraction_as_far(heads, n, num_experiments=1000):
"""Fraction of fair-coin experiments at least as far from n/2 as heads."""
counts = (torch.rand(num_experiments, n) < 0.5).sum(dim=1)
far = (counts - n / 2).abs() >= abs(heads - n / 2)
return far.to(torch.float32).mean()
fraction_as_far(56, 100), fraction_as_far(5600, 10000)(tensor(0.2820), tensor(0.))
ML Evaluation & Error Bars
Each test prediction is Bernoulli with \mathrm{SE}(\hat{p}_n) = \sqrt{p(1-p)/n}:
Bayes’ Theorem in Practice
Two-Stage Screening & Monte Carlo
Check Your Understanding
Test your intuition on three practical machine learning design problems:
Answers:
Key Takeaways
| Concept / Rule | Mathematical Form | Scaling / Behavior | Primary Deep Learning Role |
|---|---|---|---|
| Marginalization (Sum Rule) | P(X) = \sum_y P(X, Y) | Collapses one axis (sum(axis=...)) |
Averaging over latent variables & ensembles |
| Chain Rule (Product Rule) | P(X, Y) = P(Y \mid X)\,P(X) | Exact factorization of any joint P(\mathbf{x}) | Autoregressive LLMs \prod_t P(x_t \mid x_{<t}) |
| Bayes’ Theorem | P(H \mid D) = \frac{P(D \mid H)P(H)}{P(D)} | Posterior \propto likelihood \times prior | MAP estimation, anomaly & medical screening |
| Linearity of Expectation | \mathbb{E}[aX + bY] = a\mathbb{E}[X] + b\mathbb{E}[Y] | Holds even when X, Y are dependent | Unbiased minibatch SGD gradient estimates |
| Standard Error of a Mean | \mathrm{SE}(\bar{X}_n) = \sigma / \sqrt{n} | 4\times data \to \frac{1}{2} error; 100\times data \to \frac{1}{10} error | Test-set sizing & paired model comparisons |
| Aleatoric vs. Epistemic | Data noise vs. parameter ignorance | Aleatoric: irreducible; Epistemic: \propto 1/\sqrt{n} | Softmax calibration vs. active data collection |