January 22, 2026
Suppose we have a model where we are trying to learn a set of unknowns, \(\boldsymbol \theta\), given a model class, likelihood, and training data.
What is the difference between the MLE and MAP estimator of the unknowns?
When are these two estimators equivalent to one another?
How does the MLE estimator fit with respect to the data? What about the MAP estimate with a non-degenerate prior?
We showed that Ridge regression as you have seen it previously is actually the MAP estimate assuming a prior structure on coefficients.
What was that prior structure?
How does that prior structure relate to the hyperparameter in Ridge regression?
What did we mean by the idea that our prior wasn’t really on the coefficients but on functional form?
We can express Bayesian Linear Regression with Normal Priors as a learning problem:
\[ P(\boldsymbol \beta | \mathbf X , \mathbf y) = \frac{\mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I)}{P(\mathbf y | \mathbf X)} \]
Since \(\boldsymbol \beta\) is a continuous parameter vector, the posterior is over a continuous quantity. Therefore, the more common written version of the denominator is:
\[ P(\boldsymbol \beta | \mathbf X , \mathbf y) = \frac{\mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I)}{\int \limits_{\boldsymbol \beta} \mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I) d \boldsymbol \beta} \]
Looks complicated (and it kinda is)
What is the marginal probability that I would see our observed vector \(\mathbf y\) given \(\mathbf X\) weighted by my prior over \(\boldsymbol \beta\)?
From the past two lectures:
Likelihood = probabilistic loss
Priors = probabilistic regularization
MAP = posterior mode/penalized point estimate
We can sum all of this up using (part of) Bayes’ theorem:
\[ P(\theta | \mathbf X) \propto P(\mathbf X | \theta) P(\theta) \]
\[ \hat{\bbeta} = \min_\bbeta[-\log P(\mathbf y | \bbeta, \mathbf X) - \log P(\bbeta)] \]
If:
\[ P(\bbeta) = \prod \limits_{j = 1}^P \mathcal N(\beta | 0 , \tau^2) \]
Then:
\[ \hat{\bbeta} = \min_\bbeta[-\log P(\mathbf y | \bbeta, \mathbf X) - \lambda \sum \limits_{j = 1}^P \beta_j^2] \]
Our L2 penalty is a normal prior on coefficients
Regularization strength is the prior variance
The probabilistic framework gives us something that hand wavy heuristics cannot:
Assumptions are explicit, consequences are easy to track
Explains why regularization works the way it does in a way other than “having a small coefficient budget is good and bias/variance tradeoff”
Creates explicit methods for understanding the geometry of the hypothesis space. See the prior distribution over functions by drawing from the prior and the learned distributions over functions (functional uncertainty) by taking draws from a posterior.
This is neat and all
But I really haven’t shown you anything that Bayes’ can do that you couldn’t already do
Aside from being a really cool area of statistical theory that opens up a lot of other things and the things that we’re going to be talking about this semester
Bayesian Methods are going to give us a way to unify the procedures we use to optimize to the penalized likelihood given a model and the procedures we use to choose the best model across models.
It creates a one stop shop
And it’s going to solve the generalization problem with an analytical solution
When we do statistical learning, we have some data and we would like to learn a function of the data that will achieve some goal in a generalizable way
For prediction: Have low prediction error for unseen feature/outcome pairs
For generation: Produce high clarity and realism images of frogs that were not in the original training data
But, MAP/MLE with a L2 penalty gives us:
\[ \hat{\btheta} = \min_\btheta \log P(\mathbf y | \btheta) + \lambda \|\btheta\|^2 \]
A solution conditional on choices of:
Model structure
Prior parameters/hyperparameter values
What part of the standard ML recipe are we currently missing?
In statistical learning, what methods do we use to choose values for hyperparameters and select between models?
Cross validation!
Train/validation splits
K-fold
LOOCV
All kinda sides of the same coin…
The standard ML recipe:
Choose a set of models that you want to test (separate hyperparameters inclusive)
For each model, find \(\hat{\btheta}\) conditional on the observed training data
Generate an estimate of the true model risk
Compare across everything and select the one with the lowest true model risk
CV methods provide good estimates of the true risk for a model class!
(Back of your mind question for now)
Can you think of cases where CV methods may not be viable?
Model class:
\[ \hat{\bbeta}_{\lambda} = \| y - \mathbf X \bbeta \|^2 + \lambda \|\boldsymbol \beta\|^2 \]
Across models:
Choose \(\lambda\) to minimize generalization score
Define the LOOCV score for a model class as:
\[ \text{LOOCV}(\lambda) = \frac{1}{N} \sum \limits_{i = 1}^N - \log P(y_i | \mathbf x_i, \hat{\bbeta}_{-i}) - \log P (\bbeta_{-i}) \]
where
\[ \hat{\bbeta}_{-i} = \min_\bbeta P(\mathbf y_{-i} | \mathbf X_{-i}, \bbeta) P(\bbeta) \]
CV works really well in a lot of settings!
Each fold removes one subset of data points (or no folds if single holdout)
Slightly different training sets. slightly different parameter estimates
Good models don’t have any folds where the prediction is unusually bad because we left it out! Minimize this behavior.
Average predictive loss does this because averages are sensitive to extreme values
Cross validation methods create a valid score that can be used to assess the generalizability of models
Statistical theory shows that this quantity converges to the true risk with large enough N
Variance increasing in number of folds; Bias decreasing in number of folds
Decades of work show that this does what we want it to do!
If we can use validation sets/CV to choose models from a pool of potential models, we should!
When do you think that CV methods are going to be unviable or fail?
First situation: the hyperparameter tuning space explodes
Have any of y’all worked with XGBoost before?
If we have legit like 1 million parameters to tune and we want to choose the best ones w.r.t generalization error, CV is going to be untenable:
Run the model with each combo in the grid
Evaluate with K-fold or single heldout set
Repeat 1 bajillion times
We can’t sit there for all eternity doing this!
Second situation: evaluating the predictive outcome \(N_{valid}\) times is prohibitively expensive
Training Llama 405B parameter model required 16,000 H100 GPUs for months and cost 100 million + in compute at current Google cloud rates for a single final run.
A heldout set would decrease model performance drastically while refitting over multiple hyperparameter sets would be impossible - by the time it finished (estimated by Gemini to be around 1.25 years for 5-fold CV over just one hyperparameter setting), the hardware would already be obsolete!
The two stage approach can be so computationally costly that we can’t afford to do it!
The third:
In some cases, we don’t even know what we would iterate over to create a CV score!
Frog generative model:
What is the score? Goal: good pictures that don’t exist.
Prompt Engineering:
Tune the prompt to give the best answer in the general case.
We need something else for modern problems!
Let’s set up a slightly different CV scheme
Sequential Validation
Assume that our data points are iid/exchangeable (e.g. order doesn’t matter) and that we have placed a prior structure on our unknowns
Step 1: Predict \(y_1\) using the prior only
\[ P(y_1 | \mathbf x_1) = \int \limits_{\bbeta} P(y_1 | \mathbf x_1, \bbeta) P(\bbeta) d\bbeta \]
We integrate over the prior to account for our prior structural contraints on the model
If it helps, you can think of this process as taking the average likelihood that we observe over a discrete set of possible values of \(\boldsymbol \beta\) (our prior could be discrete and uniform!)
Step 2: Predict \(y_2\) using \(y_1\) and the prior
\[ P(y_2 | y_1, \mathbf x_1, \mathbf x_2) = \int \limits_{\bbeta} P(y_2 | y_1, \mathbf x_1, \mathbf x_2, \bbeta) P(\bbeta) d\bbeta \]
Steps 3 - N: Continue sequentially until all of the data are observed
\[ P(y_i | y_{<i}, \mathbf x_i, \mathbf x_{<i}) = \int \limits_{\bbeta} P(y_i | y_{<i}, \mathbf x_i, \mathbf x_{<i}, \bbeta) P(\bbeta) d\bbeta \]
This method yields a sequence of predictive likelihoods.
And these predictive likelihoods are going to look pretty familiar…
Before we define exactly where we’re going to go with this, I’m going to show this process for Ridge regression.
The integral over the coefficients is the hard part here
Where we’re going to go is going to eliminate the need for this integral (sorta)
Ridge regression is nice because this distribution has a closed form solution:
\[ P(y_i | y_{<i}, \mathbf x_{<i}, \mathbf x_i) = \mathcal N\left(y_i | \mathbf x_i^T \hat{\bbeta}_R, \hat{\sigma^2}_{MLE} + \mathbf x_i^T \boldsymbol \Sigma_{<i} \mathbf x_i\right) \]
where
\[ \boldsymbol \Sigma_{<i} = \left( \frac{1}{\sigma^2} \mathbf X_{<i}^T \mathbf X_{<i} + \frac{1}{\tau^2} \mathbf I\right)^{-1} \]
Sequential cross validation is pretty much the same as LOOCV!
The score (the average over all steps) measures how quickly the model learns - the faster we get to low loss, the lower the average
How effectively it uses past information - is it over sensitive to new data (bad fit)? Under sensitive (bad fit)?
How well it predicts genuinely unseen data.
It responds a little differently to the effect of sample size than LOOCV
We aren’t always respecting training size \(N\)
Different definition
A model that generalizes well:
Performs reasonably well early
Improves and data accumulates
Does not require seeing all data before behaving sensibly
Does not oscillate between good predictions and bad predictions - it hits a loss and sorta stabilizes
Okay… That still seems like CV with extra steps.
And you’d be right.
Probability theory to the rescue.
Our sequential score:
\[ \sum_{i = 1}^N \log P(y_i | y_{-i}, \mathbf x_{-i}, \mathbf x_i) \]
The chain rule of probability says:
\[ P(A,B,C) = P(A | B, C) P(B | C) P(C) \]
\[ \log P(A,B,C) = \log P(A | B, C) + \log P(B | C) + \log P(C) \]
\[ \log P(y_1 | -) + \log P(y_2 | y_1,-) + ... + \log P(y_N | y_{<N}, -) \]
Our sequential score:
\[ \sum_{i = 1}^N \log P(y_i | y_{-i}, \mathbf x_{-i}, \mathbf x_i) \]
is equivalent to:
\[ P(\mathbf y | \mathbf X) \]
Recognize this?
Bayes’ Theorem:
\[ P(\boldsymbol \beta | \mathbf X , \mathbf y) = \frac{\mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I)}{P(\mathbf y | \mathbf X)} \]
In its more useful form:
\[ P(\boldsymbol \beta | \mathbf X , \mathbf y) = \frac{\mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I)}{\int \limits_{\boldsymbol \beta} \mathcal N_N(\mathbf y | \mathbf X \boldsymbol \beta, \hat{\sigma}^2 \mathbf I) \mathcal N_P(\boldsymbol \beta | \mathbf 0 , \tau^2 \mathbf I) d \boldsymbol \beta} \]
The broader formulation
We see data \(\mathcal D\) and have some unknowns. Some will be optimized conditional on hyperparameters (e.g. MAP estimates), others will be hyperparameters.
Let \(\btheta\) be the set of parameters that will be estimated via MAP and let \(\mathbf M\) be the collection of model parameters (think ridge parameters, K in KNN, depth of a tree, tuning rates, etc.)
\[ P(\btheta | \mathcal D, \mathbf M) = \frac{P(\mathcal D | \btheta, \mathbf M)P(\btheta)}{P(\mathcal D|\mathbf M)} \]
The denominator of this Bayes’ theorem formula is equivalent to how well this model generalizes
In our current formulation, we’re thinking of likelihoods, so we want to make this denominator as big as possible
This can seem like a kinda tricky concept, but remember that \(P(\mathcal D)\) is a probability
There’s a really subtle logic going on here related to the prior.
By integrating over the prior, we are saying:
My MAP estimate was this, but I have some uncertainty about the estimates as a function of my prior and lack of data
Models with tight posteriors (confident about parameters) → predictions don’t change much → more concentrated probability mass → higher marginal likelihood
Models with diffuse posteriors (uncertain about parameters) → predictions spread out → probability mass diluted across many possible datasets → lower marginal likelihood
This integration marginalizes out our parameter uncertainty to evaluate: “How probable is this exact dataset across all plausible parameter values my prior allows?”
For Ridge, the denominator is of the form:
\[ P(\mathbf y | \mathbf X, \lambda) \]
To make this tractable, we’ll need to find this using the marginalized integral form:
\[ P(\mathbf y | \mathbf X, \lambda) = \int \limits_\bbeta P(\mathbf y | \mathbf X, \lambda, \bbeta) P(\bbeta) d\bbeta \]
We’ve actually already seen this! In our sequential CV section, we said that this had a particular form. When we roll everything up (e.g. add the log conditionals):
\[ \log P(\mathbf y | \mathbf X, \lambda) = -\frac{N}{2}\log(2\pi) - \frac{1}{2}\log|\mathbf K| - \frac{1}{2}\mathbf y^T \mathbf K^{-1} \mathbf y \]
where
\[ \mathbf K = \hat{\sigma}^2_{MLE} \mathbf I + \frac{1}{\lambda}\mathbf X \mathbf X^T \]
and \(| \mathbf K |\) is the determinant of \(\mathbf K\).
If we can compute this quantity directly, then the learning problem turns into a two step optimization problem:
\[ \hat{\lambda} = \max_\lambda P(\mathbf y | \mathbf X, \lambda) \]
equivalently
\[ \hat{\lambda} = \min_\lambda - \log P(\mathbf y | \mathbf X, \lambda) \]
Then:
\[ \hat{\bbeta} = \min_\bbeta P(\mathbf y | \mathbf X, \hat{\lambda}, \bbeta) P(\bbeta) \]
Or treat it as a single optimization problem that can happen in one single go:
\[ \{\mathbf M, \btheta \} = \max_{\mathbf M} \int \limits_{\btheta} P(\mathcal D | \btheta , \mathbf M) P(\btheta) d \btheta \]
It’s the golden goose of probabilistic machine learning!
Fit the model parameters and the hyperparameters in one single swoop
No CV, no inflated compute time
Just raw generalization
Why is this the first you’re hearing of this?
In what scenarios do you think that this integral is easy to solve?
This
Integral
Is
Hard
To
Compute
Consider what we’re actually computing:
\[ P(\mathcal D | \mathbf M) = \int \limits_{\btheta} P(\mathcal D | \btheta, \mathbf M) P(\btheta) d\btheta \]
This integral lives in parameter space, not data space!
The curse of dimensionality: volume of space grows exponentially with dimensions
Tractable cases (where we can compute it analytically):
Intractable cases (where we need approximations):
Variational Autoencoders (VAEs) are a perfect example of where classical Bayesian methods fail
The generative model: \[ p(\mathbf x, \mathbf z) = p(\mathbf x | \mathbf z) p(\mathbf z) \]
To train this model, we need the marginal likelihood: \[ p(\mathbf x) = \int p(\mathbf x | \mathbf z) p(\mathbf z) \, d\mathbf z \]
This integral is intractable! The decoder is a complex neural network, and \(\mathbf z\) is high-dimensional.
Key idea: If we can’t compute \(p(\mathbf z | \mathbf x)\), let’s approximate it with \(q_\phi(\mathbf z | \mathbf x)\)
The Evidence Lower Bound (ELBO) decomposition: \[ \log p(\mathbf x) = \mathcal L(\theta, \phi; \mathbf x) + D_{KL}(q_\phi(\mathbf z | \mathbf x) \, \| \, p(\mathbf z | \mathbf x)) \]
where the ELBO is: \[ \mathcal L(\theta, \phi; \mathbf x) = \mathbb{E}_{q_\phi(\mathbf z | \mathbf x)}[\log p(\mathbf x | \mathbf z)] - D_{KL}(q_\phi(\mathbf z | \mathbf x) \, \| \, p(\mathbf z)) \]
Why this works:
Diffusion models take a different approach to the intractability problem
The generative process works in reverse:
The same intractable integral appears - we can’t compute \(p(\mathbf x_0)\) directly!
Key insight: Replace one hard integral with a sequence of tractable ones
Instead of: \[ p(\mathbf x_0) = \int p(\mathbf x_0 | \mathbf z) p(\mathbf z) \, d\mathbf z \quad \text{(intractable)} \]
We have: \[ p_\theta(\mathbf x_0) = \int p(\mathbf x_T) \prod_{t=1}^T p_\theta(\mathbf x_{t-1} | \mathbf x_t) \, d\mathbf x_{1:T} \]
Why this helps:
Before we dive into neural networks, we need to understand why they work through a probabilistic lens
Deep learning didn’t appear from nowhere - it emerged from decades of Bayesian thinking:
Neural networks have vastly more parameters than data points:
From the Bayesian perspective:
\[ P(\btheta | \mathcal D) \propto P(\mathcal D | \btheta) P(\btheta) \]
Without a prior \(P(\btheta)\), the posterior is completely flat - any parameters that fit the data are equally plausible!
Dropout → Approximate Bayesian model averaging:
Convolutional Neural Networks (CNNs) → Structured priors:
Attention & Latent Representations → Probabilistic inference:
I think this all needed to come first.
Next class: