Bayesian Learning and Free Energy

SLT Lecture 4A

Kai Ogden

Last time

Near a local minimum w^*, write K(w)=L(w)-L(w^*)\geq0.

The density of states satisfies v(t)=\int_{B(w^*)}\delta\big(t-K(w)\big)\,\mathrm dw \sim c t^{\lambda-1}(-\log t)^{\mu-1}.

The sublevel volume satisfies V(\epsilon)=\int_0^\epsilon v(t)\,\mathrm dt \sim\frac{c}{\lambda}\epsilon^\lambda(-\log\epsilon)^{\mu-1}.

Bayesian Learning

Statistical learning

Data D_n=(X_1,\ldots,X_n) are IID from an underlying true distribution q. A statistical model is a family of distributions with densities \{p_w:w\in\mathcal W\subseteq\R^d\}.

The goal of statistical learning is to figure out which p_w are a good approximation to q. To quantify this define population and empirical negative log likelihoods:

L(w)=-\E_q[\log p_w(X)],\qquad L_n(w)=-\frac1n\sum_{i=1}^n\log p_w(X_i).

L_n(w)=-\frac1n\log\prod_{i=1}^n p_w(X_i)=-\frac1n\log p_w(D_n). Minimising L_n is maximising the likelihood p_w(D_n): the probability the model assigns to the data we observed.

Neural networks as statistical models

Add Gaussian noise \epsilon\sim\mathcal N(0,\sigma^2I_k) to a network f_w(x)\in\R^k: y=f_w(x)+\epsilon \quad\Longrightarrow\quad p_w(y\mid x)=\mathcal N\bigl(y\mid f_w(x),\sigma^2I_k\bigr).

Then L_n(w)=\frac{1}{2\sigma^2}\cdot\frac1n\sum_{i=1}^n\|y_i-f_w(x_i)\|^2+\text{const}, so minimising negative log likelihood (NLL) is minimising MSE.

Similarly the population NLL is

L(w)=\frac{1}{2\sigma^2}\E_{(x,y)\sim q}\|y-f_w(x)\|^2+\text{const}.

Regular and singular minima

Lecture 3 classified the minima of a loss landscape by their degeneracy. We now apply the same definitions to the population negative log likelihood L.

At a local minimum w^*, let \mathcal W_0=\{w:L(w)=L(w^*)\} near w^*. We say that w^* is:

  • Regular if the Hessian \nabla^2L(w^*) is positive definite Quadratic bowl with an isolated regular minimum.
  • Minimally singular if \mathcal W_0 is a positive-dimensional smooth submanifold and the Hessian is positive definite in the normal direction Smooth quadratic valley with a curve of minima.
  • Strictly singular otherwise Crossing valleys with a strictly singular minimum at their intersection.

KL divergence

For densities q and p on the same space, the Kullback–Leibler divergence is \operatorname{KL}(q\|p)=\int q(x)\log\frac{q(x)}{p(x)}\,\mathrm dx =\E_{x\sim q}\!\left[\log\frac{q(x)}{p(x)}\right].

It measures how far p is from q:

  • Nonnegative: \operatorname{KL}(q\|p)\geq0
  • Zero only at equality: \operatorname{KL}(q\|p)=0 if and only if p=q almost everywhere.
  • Small KL means close distributions: for every event A, |q(A)-p(A)|\leq\sqrt{\tfrac12\operatorname{KL}(q\|p)}

It is not a metric: in general \operatorname{KL}(q\|p)\neq\operatorname{KL}(p\|q), and there is no triangle inequality.

KL divergence is excess loss

Take p=p_w and split the logarithm: \begin{aligned} \operatorname{KL}(q\|p_w)&= \E_{q}[\log \frac{q(x)}{p(x)}] \\ &=\E_{q}[\log q(x)]-\E_{q}[\log p_w(x)]\\ &= -S + L(w). \end{aligned}

S = -\E_q[\log q(x)] is the entropy of q. It is independent of w so minimising KL divergence minimises L

The model is realisable if p_{w^*}=q for some w^*.

As in Lecture 3, at a chosen minimum we write K(w):=L(w)-L(w^*),\qquad K_n(w):=L_n(w)-L_n(w^*).

In the realisable case K(w)=\operatorname{KL}(q\|p_w).

Bayes’ rule

Let \varphi(w) be a prior probability density on \mathcal W and D_n = (X_1, \dots, X_n) \sim q^n. Define the posterior distribution as:

\pi_n(w)=\frac{p_w(D_n)\varphi(w)}{Z_n}, \qquad p_w(D_n)=\prod_{i=1}^n p_w(X_i)=e^{-nL_n(w)} Where Z_n = \int_{\mathcal W}p_w(D_n)\varphi(w) \mathrm dw is the evidence or partition function and normalises the posterior.

This is the probability the model assigns to the observed data, averaged over the prior. It measures how well the model as a whole explains D_n.

The Free Energy is defined as F_n=-\log Z_n.

Free energy of a region

For a region U\subseteq\mathcal W, define local partition function and local free energy as Z_n(U)=\int_U e^{-nL_n(w)}\varphi(w)\,\mathrm dw, \qquad F_n(U)=-\log Z_n(U).

Then \pi_n(U):= \int_U \pi_n(w) \mathrm dw = \int_U \frac{e^{-nL_n(w)}\varphi(w)}{Z_n} \mathrm dw = \frac{Z_n(U)}{Z_n}.

For regions with positive posterior mass, \boxed{\log\frac{\pi_n(U)}{\pi_n(V)}=F_n(V)-F_n(U).}

Smaller local free energy means larger posterior mass.

Posterior mass across parameter space

After Bayesian inference on D_n=\{X_1,\dots,X_n\}:

Parameter space partitioned into three regions: U1 in blue, U2 in red and U3 in gold.

Free energy

\textcolor{#8ed8ff}{F_n(U_1)}<\textcolor{#ff7979}{F_n(U_2)}<\textcolor{#e5c27b}{F_n(U_3)}

Posterior mass

\textcolor{#8ed8ff}{\pi_n(U_1)}>\textcolor{#ff7979}{\pi_n(U_2)}>\textcolor{#e5c27b}{\pi_n(U_3)}

The Free Energy Formula

The Bayesian information criterion (BIC)

Suppose L has a unique minimum w^*, and it is regular. For a model with d parameters, as n\to\infty, F_n=\underbrace{nL_n(w^*)}_{\text{fit to the data}} +\underbrace{\frac d2\log n}_{\text{complexity penalty}}+O_p(1). Truncated at this order, we call this expansion the BIC

Lower free energy means higher evidence, so BIC is used to compare different models:

  • more parameters can fit the data better,
  • but they pay a larger penalty \frac d2\log n.

Internal model selection

Treat two regions U,V of one model as two models. Bayesian inference compares them automatically: \log\frac{\pi_n(U)}{\pi_n(V)}=F_n(V)-F_n(U).

When U and V each contain a regular minimum, w_U^* and w_V^*, the BIC gives \log\frac{\pi_n(U)}{\pi_n(V)}\approx n\bigl(L_n(w_V^*)-L_n(w_U^*)\bigr), so Bayesian inference prefers the region with lower loss. If the losses are equal, the \frac d2\log n penalties in the BIC cancel and we lower order terms.

However, degeneracies might violate the assumptions of the BIC.

How does the BIC generalise under weaker assumptions?

Watanabe’s free energy formula

Let U be a neighbourhood of a minimum w^* with LLC \lambda and multiplicity \mu. Under some technical assumptions, as n\to\infty, \boxed{F_n(U)=\underbrace{nL_n(w^*)}_{\text{fit}} +\underbrace{\lambda\log n -(\mu-1)\log\log n+O_p(1)}_{\text{complexity}}. }

  • Regular minimum: \lambda=\frac d2 and \mu=1, recovering the BIC.
  • Singular minimum: \lambda\leq\frac d2, so degenerate regions pay a smaller penalty.

The LLC replaces the parameter count in the BIC. We prove the formula at the end of the lecture.

Internal model selection

Consider two regions U,V of parameter space with the same minimum population loss, with LLCs \lambda_U,\lambda_V and multiplicities \mu_U,\mu_V.

At large n, the empirical losses at their minima are approximately equal so

\log\frac{\pi_n(U)}{\pi_n(V)} =(\lambda_V-\lambda_U)\log n -(\mu_V-\mu_U)\log\log n+O_p(1).

If \lambda_U<\lambda_V, the posterior favours U with probability tending to 1.

If \lambda_U=\lambda_V but \mu_U>\mu_V, the posterior favours U.

Bayesian Phase Transitions

Phase transition example

Suppose U is more degenerate but fits less well: \Delta L=L_U-L_V>0,\qquad \Delta\lambda=\lambda_V-\lambda_U>0.

Ignoring multiplicity and constants, \log\frac{\pi_n(U)}{\pi_n(V)} \approx -n\Delta L+\Delta\lambda\log n.

  • \Delta\lambda\log n>n\Delta L \implies \pi_n(U) > \pi_n(V)
  • \Delta\lambda\log n<n\Delta L \implies \pi_n(U) < \pi_n(V)

The posterior masses are equal for some n^* where \frac{n^*}{\log n^*}=\frac{\Delta\lambda}{\Delta L}.

Loss L(w) for a one-dimensional parameter w: U has a wide, flat local minimum at L_U, while V has a sharp global minimum at the lower loss L_V. The vertical gap is Delta L.

Free energies cross at n^*

A posterior phase transition

Proving the Free Energy Formula

Separating fit from geometry

Fix a neighbourhood U of a minimum w^*. Suppress U for now, and write K_n(w)=L_n(w)-L_n(w^*),\qquad K(w)=L(w)-L(w^*).

Factoring out the minimum-loss term gives F_n=nL_n(w^*)-\log\int_U e^{-nK_n(w)}\varphi(w)\,\mathrm dw Define the population counterpart: F(n)=nL(w^*)-\log\int_U e^{-nK(w)}\varphi(w)\,\mathrm dw.

The stochastic part

Watanabe’s stochastic analysis gives, under some technical assumptions, \boxed{F_n-nL_n(w^*)=F(n)-nL(w^*)+R_n,} R_n\to R,\qquad\text{so }R_n=O_p(1).

We will study F(n) - nL(w^*) = -\log \underbrace{\int_U e^{-nK(w)}\varphi(w)\mathrm dw}_{Y(n)}

Evidence is a Laplace transform

Include the prior in the density of states: v_\varphi(t)=\int_U\delta\bigl(t-K(w)\bigr)\varphi(w)\,\mathrm dw.

Then \begin{aligned} Y(n)&=\int_U e^{-nK(w)}\varphi(w)\,\mathrm dw\\ &=\int_U\left(\int_0^\infty e^{-nt}\,\delta\bigl(t-K(w)\bigr)\,\mathrm dt\right)\varphi(w)\,\mathrm dw\\ &=\int_0^\infty e^{-nt}\left(\int_U\delta\bigl(t-K(w)\bigr)\varphi(w)\,\mathrm dw\right)\mathrm dt\\ &=\int_0^\infty e^{-nt}\,v_\varphi(t)\,\mathrm dt \end{aligned}

Only small loss matters

Fix 0<\delta<1 small enough that the small-t form of v_\varphi holds on (0,\delta]. Split the integral at \delta: Y(n)=\int_0^\delta e^{-nt}\,v_\varphi(t)\,\mathrm dt+\int_\delta^\infty e^{-nt}\,v_\varphi(t)\,\mathrm dt.

On the tail e^{-nt}\leq e^{-n\delta}, so 0\leq\int_\delta^\infty e^{-nt}\,v_\varphi(t)\,\mathrm dt \leq e^{-n\delta}\int_U\varphi(w)\,\mathrm dw.

\boxed{Y(n)=\int_0^\delta e^{-nt}\,v_\varphi(t)\,\mathrm dt+O\bigl(e^{-n\delta}\bigr).}

The tail is exponentially small.

Large n equivalent to small t

Substitute s=nt, so \mathrm dt=\mathrm ds/n: Y(n)=\frac1n\int_0^{n\delta} e^{-s}\,v_\varphi\!\left(\frac sn\right)\mathrm ds+O\bigl(e^{-n\delta}\bigr).

For large n asymptotics of Y we require small t asymptotics of v_\varphi(t): \;v_\varphi(t)\sim a\,t^{\lambda-1}(-\log t)^{\mu-1} \qquad \text{as }t\to0

Since t=s/n\leq\delta throughout, substituting this leading order asymptotics gives \begin{aligned} Y(n)&\sim\frac an\int_0^{n\delta} e^{-s}\left(\frac sn\right)^{\lambda-1} (\log n-\log s)^{\mu-1}\,\mathrm ds\\ &=a\,n^{-\lambda}\int_0^{n\delta} e^{-s}s^{\lambda-1}(\log n-\log s)^{\mu-1}\,\mathrm ds. \end{aligned}

Asymptotics of \text{ } Y

Y(n)\sim a n^{-\lambda}\int_0^{n\delta} e^{-s}s^{\lambda-1}(\log n-\log s)^{\mu-1}\,\mathrm ds.

By the binomial theorem the leading term has (\log n)^{\mu-1}. Extending n\delta to \infty again only costs O\bigl(e^{-n\delta/2}\bigr):

Y(n)\sim a n^{-\lambda}(\log n)^{\mu-1} \underbrace{\int_0^\infty e^{-s}s^{\lambda-1}\,\mathrm ds}_{\Gamma(\lambda)}.

Therefore \boxed{Y(n)\sim C\,n^{-\lambda}(\log n)^{\mu-1}, \qquad C=a\Gamma(\lambda)>0.}

Completing the proof

Recall F(n)=nL(w^*)-\log Y(n).

Substituting Y(n)\sim Cn^{-\lambda}(\log n)^{\mu-1} gives \begin{aligned} F(n)&=nL(w^*)-\log\!\left[Cn^{-\lambda}(\log n)^{\mu-1}\right]+O(1)\\ &=nL(w^*)+\lambda\log n-(\mu-1)\log\log n+O(1). \end{aligned}

Restore stochastics F_n-nL_n(w^*)=F(n)-nL(w^*)+O_p(1): \boxed{F_n=nL_n(w^*)+\lambda\log n -(\mu-1)\log\log n+O_p(1)} as n\to\infty.

Summary

Watanabe’s free energy formula: F_n(U)=nL_n(w^*)+\lambda\log n-(\mu-1)\log\log n+O_p(1).

  • The LLC replaces \frac d2 in the BIC as the complexity penalty.
  • Comparing regional free energies gives internal model selection; competition between fit and complexity gives Bayesian phase transitions.
  • Proof: the evidence is a Laplace transform of the density of states, so v_\varphi(t)\sim a t^{\lambda-1}(-\log t)^{\mu-1} gives Y(n)\sim C n^{-\lambda}(\log n)^{\mu-1}.