Probability theory provides a framework for modeling uncertainty in data, predictions, and model parameters
Supervised Learning:
Unsupervised Learning:
Building blocks:
The three axioms (Kolmogorov):
A random variable $X: \Omega \to \mathbb{R}$ is a measurable function that assigns a numerical value to each outcome.
Discrete Random Variable
Takes on a finite or countably infinite set of values.
Examples:
Continuous Random Variable
Takes on any value within an interval or the entire real line.
Probability Mass Function (discrete $X$)
$p_X: \mathbb{R} \to [0,1]$ gives the probability of each value:
Probability Density Function (continuous $X$)
$p_X: \mathbb{R} \to [0, \infty)$ describes probability density:
Key insight: A PDF can exceed 1 (it is a density, not a probability), but its integral over any region is always $\leq 1$.
Big P — probability of an event (a set or inequality); returns a number in $[0,1]$ $P(A),\ P(\Omega) = 1,\ P(a \leq X \leq b),\ P(X \in A)$
Small p — PMF (discrete) or PDF (continuous) of a random variable evaluated at a value; densities can exceed 1 $p_X(x),\ p_{X,Y}(x,y)$
Subscripts — identify which random variable(s) the distribution refers to; the arguments are the values they take. Often dropped when unambiguous: $p(x) \equiv p_X(x)$ $p_X(x),\ p_{X,Y}(x,y),\ p_{X|Y}(x \mid y)$
Conditional — $\mid$ reads "given"; a comma on the right of $\mid$ conditions on multiple variables at once $p_{X|Y}(x \mid y),\ p_{Y|X,\Theta}(y \mid x, \boldsymbol{\theta})$
Sample space & events — $\Omega$ sample space, $\omega \in \Omega$ outcome, $\mathcal{F}$ $\sigma$-algebra of events, $A \in \mathcal{F}$ event
Common objects — $\mathbb{E}[\cdot]$ expectation, $\mathcal{N}(\mu, \sigma^2)$ normal distribution, $\mathcal{D}$ dataset, $\boldsymbol{\theta} \in \Theta$ parameters $\mathbb{E}[X],\ X \sim \mathcal{N}(0, 1),\ \mathcal{D} = \lbrace(\mathbf{x}_i, y_i)\rbrace_{i=1}^{N}$
The expected value is the probability-weighted average of all possible values:
Discrete
Continuous
Expectation of a function: $\mathbb{E}[g(X)] = \sum_{x} g(x)\, p_X(x)$ (or the integral for continuous $X$)
For random variables $X$ and $Y$:
Joint — probability of the combined outcomes
Marginal — integrate the other variable out
Conditional — a renormalized slice of the joint
Independence — one variable tells nothing about the other
From the definition of conditional probability, $p_{X,Y}(x,y) = p_{X|Y}(x|y)\, p_Y(y) = p_{Y|X}(y|x)\, p_X(x)$, rearranging gives:
A smart speaker classifies an event $y \in \{\text{doorbell}, \text{dog bark}, \text{glass breaking}\}$ after observing a high-frequency burst.
Prior $p_Y(y)$ — how common:
Likelihood $p_{X|Y}(x|y)$ — burst given event:
Evidence $p_X(x) = 0.26$
Glass breaking has the highest likelihood (0.9), but doorbell has the highest posterior (0.69) — the prior matters!
Bayesian Decision Rule — pick $\hat{y}$ minimizing expected loss:
With 0-1 loss, minimizing expected loss $\Leftrightarrow$ maximizing the posterior — MAP:
Assuming a uniform prior, MAP reduces to Maximum Likelihood (ML):
Hierarchy: Bayesian Decision $\xrightarrow{\text{0-1 loss}}$ MAP (prior + likelihood) $\xrightarrow{\text{uniform prior}}$ ML (likelihood only). For our example, ML would predict glass breaking; MAP predicts doorbell.
The same principle applies to two very different questions:
Classification / Prediction (inference)
Parameter Learning / Training
Parameters $\boldsymbol{\theta}$ define the model — e.g. weights & biases of an MLP (recall Lecture 2). Applying Bayes to $\boldsymbol{\theta}$ and dropping the (constant) evidence $p_\mathcal{D}(\mathcal{D})$:
Idea: choose parameters that make the observed data most likely.
Assuming the data $\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^n$ is i.i.d., the likelihood factorizes:
Why the log? Products become sums (easy gradients), it prevents numerical underflow, and $\log$ is monotonic so the $\arg\max$ is unchanged.
Audio classifier, $y_i \in \{0,1\}$ (glass breaking or not), model $p(y=1|\mathbf{x}, \mathbf{w}) = \sigma(\mathbf{w}^\top \mathbf{x})$.
Per-example likelihood (Bernoulli trick): $p(y_i|\mathbf{x}_i, \mathbf{w}) = \sigma(\mathbf{w}^\top \mathbf{x}_i)^{y_i} (1-\sigma(\mathbf{w}^\top \mathbf{x}_i))^{1-y_i}$
Taking the log over the i.i.d. dataset gives the log-likelihood:
This is exactly the (negative) binary cross-entropy loss! No closed form → optimize with gradient descent.
Loss functions are not arbitrary — cross-entropy is MLE for a Bernoulli/categorical model, just as MSE is MLE for a Gaussian model (we will reuse this for the VAE).
Add a Gaussian prior on the weights, $p_W(\mathbf{w}) = \mathcal{N}(\mathbf{0}, \lambda^{-1}\mathbf{I})$, so $\log p_W(\mathbf{w}) = -\tfrac{\lambda}{2}\|\mathbf{w}\|^2 + \text{const}$. The MAP objective is log-likelihood $+$ log-prior:
Bayes' Theorem: $p_{Y|X}(y|x) = \dfrac{p_{X|Y}(x|y)\, p_Y(y)}{p_X(x)}$ — connects posterior, likelihood, prior, evidence.
Decision (what to predict): Bayesian $\to$ MAP (0-1 loss) $\to$ ML (uniform prior).
Estimation (how to learn): MAP $\to$ MLE (uniform prior); regularization $=$ a prior on $\boldsymbol{\theta}$.
Key: the same framework governs both inference and training — and it derives our loss functions (cross-entropy, MSE).
So far everything was supervised. What if we have no labels and want to model the data itself? → Latent variable models.
Supervised
Labeled data $\mathcal{D} = \{(\mathbf{x}_i, \mathbf{y}_i)\}_{i=1}^n$
Model the conditional $p_{Y|X,\Theta}(\mathbf{y}|\mathbf{x}, \boldsymbol{\theta})$:
Unsupervised
Unlabeled data $\mathcal{D} = \{\mathbf{x}_i\}_{i=1}^n$
Model the data distribution $p_{X|\Theta}(\mathbf{x}|\boldsymbol{\theta})$ directly:
Goal of unsupervised learning: discover hidden structure in the data — clusters, factors of variation, a generative process.
Modeling $p(\mathbf{x})$ directly is often hard. Instead, introduce a latent (hidden) variable $\mathbf{z}$ capturing underlying factors: each observation $\mathbf{x}$ is generated from $\mathbf{z}$ via $p_{X|Z,\Theta}(\mathbf{x}|\mathbf{z}, \boldsymbol{\theta})$.
The marginal likelihood integrates the latents out:
We then fit $\boldsymbol{\theta}$ by MLE on this marginal:
The integral $\int p_{X,Z|\Theta}(\mathbf{x},\mathbf{z}|\boldsymbol{\theta})\,d\mathbf{z}$ is usually intractable for continuous $\mathbf{z}$.
Simplify: let $\mathbf{z}$ be discrete, $z \in \{1, \ldots, K\}$ (a cluster assignment). The integral becomes a tractable sum:
Gaussian Mixture Model: Gaussian components with mixing weights $\pi_k$:
Here $p_{Z|\Theta}(\mathbf{z}|\boldsymbol{\theta}) \to \pi_k$ and $p_{X|Z,\Theta}(\mathbf{x}|\mathbf{z}, \boldsymbol{\theta}) \to \mathcal{N}(\mathbf{x}|\boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k)$.
MLE objective — maximize the log-likelihood:
The problem: the log-of-a-sum prevents a closed-form solution. Setting $\partial \mathcal{L}/\partial \boldsymbol{\mu}_k = 0$ yields a circular dependency:
$\boldsymbol{\mu}_k$ appears on both sides — the solution depends on $\gamma_{ik}$, which depends on $\boldsymbol{\mu}_k$.
Single Gaussian (no sum inside the log) → clean closed form:
Key insight: If we knew the cluster assignments $z_i$, each cluster would reduce to a single-Gaussian problem — $\boldsymbol{\mu}_k$ is just the mean of its points. But we don't know $z_i$; that's what we're trying to learn.
This chicken-and-egg structure is exactly what the EM algorithm resolves.
Chicken-and-egg: knowing $\boldsymbol{\theta}$ lets us compute assignments $z_i$; knowing $z_i$ lets us estimate $\boldsymbol{\theta}$. EM alternates between the two:
The E-step returns the full posterior over $z$ (soft assignments), not a single MAP guess. If it used hard assignments instead, EM would reduce to K-means.
E-Step — responsibilities (posterior that point $i$ belongs to cluster $k$):
M-Step — update with weighted statistics ($N_k = \sum_i \gamma_{ik}$):
Probability & estimation: Bayes' theorem unifies inference (Bayesian → MAP → ML) and training (MAP → MLE); loss functions and regularization fall out of it.
Latent variable models: introduce hidden $\mathbf{z}$ to model $p(\mathbf{x}) = \int p(\mathbf{x},\mathbf{z}|\boldsymbol{\theta})\,d\mathbf{z}$; the log-of-sum blocks closed-form MLE.
EM: alternate soft assignments (E) and weighted MLE (M) — the GMM works because $\mathbf{z}$ is discrete and the posterior is tractable.
Next lecture: Why does EM actually work? The ELBO answers that — and generalizes to neural-network models where the posterior is intractable: the Variational Autoencoder.