# A short 'derivation' of Watanabe's Free Energy Formula

*Epistemic status: I wrote the post mostly for myself, in the process of understanding the theory behind Singular Learning Theory, based on the* [*SLT low lecture series*](https://youtube.com/playlist?list=PL4vaU_gO_6LIf5CHU3Z3CT39fha55pe16&si=q9YW_U-Uq5YlhDa_)*. This is a proof sketch with the thoroughness level of an experimental physics lecture: enough to get the intuitions but consult someone else for details.*

Background: Statistical Learning Theory
=======================================

In the framework of statistical learning theory, we aim to establish a model that can predict an outcome $y$ given an input $x$ with a certain level of confidence. This prediction is typically governed by a set of parameters $w$ , which need to be learned from the data. Let us begin by defining the primary components of this framework.

The Probabilistic Model
-----------------------

  
The probabilistic model  $p(y|x,w)$ represents the likelihood of observing the outcome  $y$ given the input $x$ and the parameters $w$. This model is parametric, meaning that the form of the probability distribution is predefined, and the specific behavior of the model is determined by the parameters $w$.

The True Distribution
---------------------

  
The true distribution $q(y|x)$  is the actual distribution from which the data points are sampled. In practice, this distribution is not known and  $p(y|x,w)$ attempts to approximate it through the learning process.

The Parameters
--------------

The parameters $w$  are the weights or coefficients within our model that determine its behavior. The goal of learning is to find the values of $w$ that make $p(y|x,w)$ as close as possible to the true distribution $q(y|x)$.

The Data
--------

The data $D = \{x_i, y_i\}$  consist of pairs of input values $x_i$  and their corresponding outcomes $y_i$. These data points are used to train the model, adjusting the parameters $w$ to fit the observed outcomes.

The Negative Log-Likelihood
---------------------------

The negative log-likelihood is a measure of how well our model $p(y|x,w)$ fits the data $D$ . It is defined as the negative sum of the logarithms of the model probabilities assigned to the true outcomes $y_i$:

$\begin{equation}NLL(w) = -\sum_{i=1}^{N} \log p(y_i | x_i, w),\end{equation}$

where $N$ is the number of data points in $D$. Minimizing the negative log-likelihood is equivalent to maximizing the likelihood of the data under the model, which is a central objective in the training of probabilistic models.

Prior over the Parameters
-------------------------

In a Bayesian framework, we incorporate our prior beliefs about the parameters $w$  before observing the data through a prior distribution $\varphi(w)$. This prior distribution encapsulates our assumptions about the values that $w$ can take based on prior knowledge or intuition. For instance, a common choice is a Gaussian distribution, which encodes a preference for smaller (in magnitude) parameter values, promoting smoother model functions.

Posterior Distribution
----------------------

Once we have observed the data  $D$, we can update our belief about the parameters $w$ using Bayes' theorem. The updated belief is captured by the posterior distribution, which combines the likelihood of the data given the parameters with our prior beliefs about the parameters. The posterior distribution is defined as:

$\begin{equation}P(w|D) = \frac{1}{Z_n} \exp(-NLL(w)) \Phi(w),\end{equation}$

where  $NLL(w)$ is the negative log-likelihood of the parameters given the data, $\Phi(w)$ is the prior over the parameters, and $Z_n$ is the normalization constant, also known as the partition function. The partition function ensures that the posterior distribution is a valid probability distribution by integrating (or summing) over all possible values of $w$:

$\begin{equation}Z_n = \int \exp(-NLL(w)) \varphi(w) dw.\end{equation}$

The posterior distribution reflects how likely different parameter values are after taking into account the observed data and our prior beliefs.

  
Free Energy
==============

  
This formulation looks like the Boltzmann distribution from statistical physics. This distribution also describes a probability: the probability that a system can be found in a particular microstate is $e^{-E}$ with $E$ being the energy (here assuming, that the temperature is 1). This formalism can be expanded to macrostates, when changing the Energy to Free Energy, taking into account that microstates that have many realizations are more likely.  
We can do a similar step with the Posterior of our model weights, by considering neighborhoods around local minima as macrostates. This opens up the question of what the correct formula for the Free Energy of these macrostates are, so we can make predictions about the behavior of learning machines.  
First, let us consider the case of large datasets. In that case, we can replace the negative Log-Likelihood with n times its average:

$\begin{align*}NLL(w) &= -\sum_{i=1}^{N} \log p(y_i | x_i, w) \ &\approx n \int \log(p(y| x, w)) q(y |x) q(x) dx\ & = n \left( \int \log(\frac{p(y| x, w)}{q(y |x)}) q(y |x) q(x) dx - \int \log(q(y |x)) q(y |x) q(x) dx\right)\ & = n<KL(p_w|q)-S(q)>_{q(x)}\end{align*}$  
  
We see that we can compose the negative Log likelihood into the number of data points n, the expected Kullback–Leibler divergence of the model with the true distribution, and the expected entropy of the true distribution. As we see here, the expected entropy term does not contribute to the posterior of the parameters:  
$\begin{align}   P(w|n) &= \frac{1}{Z_n} \exp(-NLL(w)) \Phi(w) \          &= \frac{\exp((-NLL(w)) \Phi(w)}{\int \exp(-NLL(w)) \Phi(w) dw} \          &= \frac{\exp(-n \langle KL(p_w\|q) - S(q) \rangle_{q(x)})\Phi(w)}{\int \exp(-n \langle KL(p_w\|q) - S(q) \rangle_{q(x)}) \Phi(w) dw}\          &= \frac{\exp(-n \langle KL(p_w\|q)  \rangle_{q(x)})\Phi(w)}{\int \exp(-n \langle KL(p_w\|q)  \rangle_{q(x)}) \Phi(w) dw}\end{align}$  
The macrostates, aka the regions in parameter space we are now interested in analyzing are the vicinities of local minima in the Loss landscape. Let us assume we decompose our parameter space into macrostates $W = \cup _\alpha W_\alpha$.  
$\begin{align}   P(w \in W_\alpha) &= \int _{w \in W_\alpha} p(w|n) dw \nonumber \    &=\frac{\int _{w \in W_\alpha}\frac{1}{Z_n} \exp(-\mathcal{L}(w)) \Phi(w) dw}{\sum_\alpha \int _{w \in W_\alpha}\frac{1}{Z_n} \exp(-\mathcal{L}(w)) \Phi(w) dw} \nonumber \    &=\frac{\int _{w \in W_\alpha}\exp(-n \langle KL(p_w\|q)  \rangle_{q(x)}) \Phi(w) dw}{\sum_\alpha \int _{w \in W_\alpha} \exp(-n \langle KL(p_w\|q)  \rangle_{q(x)}) \Phi(w) dw} \nonumber \    &= \frac{\exp{-F(W_\alpha,n)}}{\sum_\alpha\exp{-F(W_\alpha,n)}} \nonumber \    F(W_\alpha,n)& = - \log(\int _{w \in W_\alpha} \exp(-n \langle KL(p_w\|q)  \rangle_{q(x)}) \Phi(w) dw) \nonumber \\\end{align}$

We call this $F$ the free energy of this area, as it serves the same function as the Free Energy in statistical physics. We have constructed $W_\alpha$ such that it only contains one minimum of the expected Kulberg Leibler divergence (from here on  we abbreviate $KL(p_w\|q)  \rangle_{q(x)}$ as $K(\omega)$). These minima don't have to be points but can be different sets  within $W_\alpha$.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/925736bacbcb279aa87c1db5abf667893d6200340d4e404c.png)

Examples of sets where  $K$ has a minimum. a): A point b): A submanifold. c): An algebraic set with Singularity.

 Since we assume, that $K(\omega)$ is smooth, it can locally be approximated by its Taylor series at any point. How the leading order terms of the Taylor series look at its minimum depends on the geometry of the minimum. Let's look at an example of how that might look like from the figure above. In a) we have a simple minimum point, so the Taylor series of $K$ at this point might look like $x^2+y^2$, going up in each direction. In b) our minimum is a one-dimensional submanifold, and so the Taylor expansion of $K$ will look like $x^0+y^2$, increasing in one dimension, but staying flat when going along another. The situation in c) looks almost the same, except in the center, where the line crosses itself. There the Taylor expansion will look like $x^2\cdot y^2$, locally staying flat in either direction. Points like these, where the directions you can go in while staying on the set suddenly change, are called singularities.  
Let us now calculate the Free Energy around a point $\omega^*$, where $K$ has a minimum. In general the leading order term of the $K$ at a minimum looks like this:  
$\begin{align*} K(\omega^* +x) = K_{min} + a\prod_{i} x_i^{2 k_i} := K_{min} + a \vec{x}^{2\vec{k}} \end{align*}$  
Here $K_{min}$ is the value of the KL-divergence at its minimum.  
To get it into this form, we have to make a change of coordinates for $x$ (for example when we are at a singularity where the different parts of the minimum come in from an angle). A process called blowup guarantees us, that we are always able to find such coordinates. Since we are at a minimum, we know that all leading order exponents are even.  
Let's also approximate our prior over the weights  $\Phi(w^* +x)$ on this point in the same basis as its leading order term:  
$\begin{align*}   \Phi(\omega) = b\prod_{i} x_i^{h_i} := b \vec{x}^{\vec{h}}\end{align*}$  
For large $n$, the Free Energy at any point far away from the minima gets exponentially suppressed. To see how much the minimal point $\omega^*$ contributes to the integral we can integrate it in its vicinity. Here we choose to integrate from 0 to 1. 

Why not from $-1$ to $1$?[^uzzvy7qpglm]  
$\begin{align*}   F(\omega^*,n)= -log(\int _{0}^1 \exp(-n(K_{min} +a \vec{x}^{2\vec{k}}) (  b \vec{x}^{\vec{h}} d \vec{x})\end{align*}$  
The first thing we can do is pull out the $K_{min}$ term as it does not depend on $x$.  
$\begin{align*}   F(\omega^*,n)=n K_{min} - log(\int _{0}^1 \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x})\end{align*}$  
To solve the remaining integral, we first do a Laplace and then a Mellin transform, as this brings the integral into a form, that is easier to solve.  
$\begin{align*}  \mathcal{L}\left(\int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right) &= \int_0^{\infty}\left( \int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right)e^{-nt}dt\   &= \int _{0}^{1} \delta(t-a \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}}d \vec{x}\   \mathcal{M}\left(\mathcal{L}\left(\int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right)\right) & = \int_0^{\infty}\left(\int _{0}^{1} \delta(t-a \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}}d \vec{x} \right)t^{z}dt\   & = \int _{0}^{1} (a \vec{x}^{2\vec{k}})^{z}  b \vec{x}^{\vec{h}}d \vec{x}\   &= a^zb \prod_i\int _{0}^{1} x_i^{2zk_i+h_i}\   &= a^zb\frac{1}{\prod_i(2zk_i+h_i+1)}\end{align*}$

Next, we group the dimensions $i$ along, such that within each group $I_\alpha$, the value $\lambda_\alpha = \frac{h_i + 1}{2k_i}$ is the same. Later in the derivation, it will turn out, that only the biggest $\lambda$ will contribute for large $n$.   
$\begin{align*}    \mathcal{M}\left(\mathcal{L}\left(\int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right)\right)&= a^zb\frac{1}{\prod_\alpha \prod_{i \in I_\alpha}2k_i(z+\lambda_i)}\end{align*}$  
Now we go backward, and reverse the Mellin and the Laplace transform:  
$\begin{align*}   \mathcal{L}\left(\int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right)&= \int_{-i \infty}^{+i \infty} \frac{a^zb}{2 \pi i}\frac{1}{\prod_\alpha \prod_{i \in I_\alpha}2k_i(z+\lambda_i)}t^{-z-1}dz\   &=\frac{b}{2 \pi it}\int_{-i \infty}^{+i \infty} \frac{e^{z \log(\frac{a}{t})}}{\prod_\alpha \prod_{i \in I_\alpha}2k_i(z+\lambda_i)}dz\\\end{align*}$  
We can solve this integral with the Residue Theorem, closing the integral path over the negative half of the if $a>t$. Since all $\lambda_\alpha$ have to be positive, when we close the integral over the negative half, we enclose no residues and the integral comes out as zero. Otherwise each unique $\lambda_i$, which appears $m$ times, being a residual of degree $m$:  
$\begin{align*}   \mathcal{L}\left(\int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}\right) &= \frac{b}{2 \pi it}\sum_\alpha\frac{1}{m_\alpha-1}\left(\frac{d}{dz}\right)^{m_\alpha-1}e^{z \log\left(\frac{a}{t}\right)}\bigg|_{z = -\lambda_\alpha} \   &=    \begin{cases}        \frac{b}{2 \pi it}\sum_\alpha\frac{\log\left(\frac{a}{t}\right)^{m_\alpha-1}}{m_\alpha-1}e^{-\lambda_\alpha \log\left(\frac{a}{t}\right)}, & \text{if } a > t, \       0, & \text{if } a \leq t.   \end{cases}\end{align*}$  
When we now reverse the Laplace transform, we only have to integrate up to $a$.  
$\begin{align*}   \int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x} &=    \int_0^a \frac{b}{2 \pi i}\sum_\alpha a^{-\lambda_\alpha}\frac{\log\left(\frac{a}{t}\right)^{m_\alpha-1}}{m_\alpha-1} t^{\lambda_\alpha-1} e^{-nt} dt \bigg| \tau = \frac{n}{a}t\   &=\frac{b}{2 \pi i} \sum_\alpha \frac{a^{-\lambda_\alpha}}{m_\alpha-1}\int_0^n \log\left({\frac{n}{\tau}}\right)^{m_\alpha-1}\left(\frac{a \tau}{n}\right)^{\lambda_\alpha-1}e^{-\tau a}\frac{a}{n}d\tau\   &=\frac{b}{2 \pi i} \sum_\alpha \frac{n^{-\lambda_\alpha}}{m_\alpha-1}\int_0^n \tau^{\lambda_\alpha-1}e^{-\tau a}\left(\log(n)-\log(\tau)\right)^{m_\alpha-1}d\tau\   &=\frac{b}{2 \pi i} \sum_\alpha \frac{n^{-\lambda_\alpha}}{m_\alpha-1}\int_0^n \tau^{\lambda_\alpha-1}e^{-\tau a}\sum_{j=0}^{m_\alpha-1}\binom{m_\alpha-1}{j}\log(n)^{m_\alpha-1-j}\left(-\log(\tau)^{j}\right)d\tau\   &=\frac{b}{2 \pi i} \sum_\alpha \frac{n^{-\lambda_\alpha}}{m_\alpha-1}\sum_{j=0}^{m_\alpha-1}\binom{m_\alpha-1}{j}\log(n)^{m_\alpha-1-j}\int_0^n \tau^{\lambda_\alpha-1}e^{-\tau a}\left(-\log(\tau)^{j}\right)d\tau\\\end{align*}$  
This integral now is asymptotically going towards some number as $n$ goes to infinity. So we can pick out the term that is the highest order in $n$ as the one with the smallest $\lambda_\alpha$ and $j = 0$.  
$\begin{align*}   \int _{0}^{1} \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x} \propto n^{-\lambda_{\alpha*}}\log(n)^{m_{\alpha*}-1} + O(n^{-\lambda_{\alpha*}}\log(n)^{m_{\alpha*}-2})\end{align*}$$$  
We can combine this into the Formula for Free Energy.  
$\begin{align*}   F(\omega^*,n)=n K_{min} +\lambda log(n)-(m-1)\log\left(\log(n)\right) \end{align*}$  
This expression tells us now, how much mass of the posterior distribution is centered around certain points in parameter space. The leading order term consists of the KL divergence between the training distribution and the distribution of our model. Intuitively, this corresponds to our training loss. In the second term the $\lambda$ inversely scales with the multiplicity of the minimum. Intuitively it corresponds to symmetries in the algorithm that the Network implements. The third term scales with the number of parameters that have a minimum of the same multiplicity. Intuitively this gives a set of parameters an extra advantage when multiple parameter sets implement algorithms that independently lead to minimal loss.

  
 

[^uzzvy7qpglm]: I would have expected, that we integrate the whole vicinity:\(\begin{align*}   F(\omega^*,n)= -log(\int _{-1}^1 \exp(-n(K_{min} +a \vec{x}^{2\vec{k}}) (  b \vec{x}^{\vec{h}} d \vec{x})\end{align*}\)This, however, makes the derivation quite ugly:\(\begin{align*}  \mathcal{L}(\int _{-1}^1 \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}) &= \int_0^{\infty}( \int _{-1}^1 \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x})e^{-nt}dt\\   &= \int _{-1}^1 \delta(t-a \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}}d \vec{x}\\   \mathcal{M}(\mathcal{L}(\int _{-1}^1 \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x})) & = \int_0^{\infty}(\int _{-1}^1 \delta(t-a \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}}d \vec{x} )t^{z}dt\\   & = \int _{-1}^1 (a \vec{x}^{2\vec{k}})^{z}  b \vec{x}^{\vec{h}}d \vec{x}\\   &= a^zb \prod_i\int _{-1}^1 x_i^{2zk_i+h_i}\\   &= \frac{a^zb}{\prod_i(2zk_i+h_i + 1)}\prod_i(1^{2zk_i+h_i}-(-1)^{2zk_i+h_i})\\\end{align*}\)\(\begin{align*}      \mathcal{L}(\int _{-1}^1 \exp(-na \vec{x}^{2\vec{k}})  b \vec{x}^{\vec{h}} d \vec{x}) &=   \frac{b}{2\pi i}\oint\frac{a^z t ^{-z-1}}{\prod_i(2zk_i+h_i + 1)}\prod_i(1-(-1)^{2zk_i+h_i}) dz\\   &=\frac{b}{2 \pi it}\int_{-i \infty}^{+i \infty} \frac{e^{z \log(\frac{a}{t})}}{\prod_\alpha \prod_{i \in I_\alpha}2k_i(z+\lambda_i)}\prod_i(1-(-1)^{2k_i(z+\lambda_i)})dz\\   &= \frac{b}{2 \pi it}\sum_\alpha\frac{1}{m_\alpha-1}\left(\frac{d}{dz}\right)^{m_\alpha-1}e^{z \log\left(\frac{a}{t}\right)}(1-(-1)^{2k_i(z+\lambda_i)})\bigg|_{z = -\lambda_\alpha} \\&=   \begin{cases}        \frac{b}{2 \pi it}\sum_\alpha\frac{1}{m_\alpha-1}e^{-\lambda_\alpha \log\left(\frac{a}{t}\right)}\sum_j\binom{m_\alpha-1}{j} (\log\left(\frac{a}{t}\right)^{m_\alpha-1-j}(2\pi i k_i)^j, & \text{if } a > t, \\       0, & \text{if } a \leq t.   \end{cases}\end{align*}\)We can proceed with the rest of the calculation with each summand \(j\) and just have a smaller \(m_\alpha\). This does not change anything about the leading terms, that are relevant for the Free Energy formula.I am still confused, about why the lecture went from 0 to 1, and would be grateful for an explanation in the comments.