TL;DR
Take a log of an average of exponentials, . The Gibbs variational principle says this number is the largest value of a simple objective: the average of the score under some distribution , minus the KL divergence from to the prior . The best is the prior reweighted by and normalized, which is called the tilted or Gibbs distribution.
The result turns a hard calculation, a log of a weighted sum of exponentials, into an optimization over distributions. Any choice of gives a lower bound, and the bound is exact at the best .
Where you'll see it: in statistical mechanics, where the free energy of a system is a log partition function, in variational inference, where the evidence lower bound is this principle applied to a model, and in the Donsker–Varadhan formula for large deviations.
Intuition
A log of a sum that is hard to compute
Suppose you have a prior over many possible configurations, and each configuration has a score . You want the log of the average of under . This number is the log partition function, and it is central in physics and machine learning. It is hard to compute when there are many configurations, because you must sum over all of them.
The Gibbs principle changes the question. Instead of computing the number directly, ask: which distribution over configurations gives the largest value of "average score under , minus the price of moving away from the prior"? The price is the KL divergence , which is zero when equals and grows as moves away from it.
The trade-off is the whole idea. Putting all weight on the highest-scoring configuration maximizes the score, but it pays a large KL cost because it is far from the prior. Keeping equal to the prior pays no cost, but it ignores the scores. The best balances the two, and it does so by tilting the prior toward high scores by exactly the amount .
flowchart LR P[prior pi] --> T[tilt by e^f] F[scores f] --> T T --> N[normalize by Z] N --> Q[best Q = Gibbs distribution] Q --> V[value: log Z]
Why this matters: the objective "score minus KL" is easy to evaluate for any you can sample from. You get a lower bound on the hard quantity for free, and you know exactly when the bound is tight.
The math
Definition
Let be a probability distribution on a set , and let be a score. Define the partition function
the average of under the prior. The Gibbs distribution, also called the tilted distribution, is
Here is the prior probability of configuration , is its exponentiated score, and is the normalizing constant that makes sum to one.
The principle
For every probability distribution on ,
and equality holds exactly when . Written as a supremum,
Proof
Take any with its probabilities. Expand the KL term and combine it with the expected score:
Now compare with . Its probabilities satisfy , so . Substitute this into the sum. Each term becomes . Summing gives
The KL divergence between two distributions is never negative and is zero only when they match, so the right-hand side is at most . Equality holds exactly when . This is the whole proof, and it uses only the fact that KL is non-negative. The non-negativity itself comes from Jensen's inequality, as shown in the KL divergence lesson.
Free-energy form
In statistical mechanics the configurations are the states of a physical system, the score is for an energy at temperature , and the prior is uniform, . Then is the Boltzmann distribution. Let be the usual partition function, so that . For a uniform prior, , where is the Shannon entropy of in nats. The terms cancel and the principle reads
The left-hand side is the free energy, and the right-hand side is the minimum of energy minus temperature times entropy over all distributions. Nature settles into the distribution that minimizes this trade-off between low energy and high entropy.
Connection to the convex conjugate
The map is convex in . The supremum above says that it is the Legendre–Fenchel transform (convex conjugate) of the convex function , evaluated at . That is why the principle is also called a duality. The dual variable is the distribution , and the penalty is the KL divergence.
Worked examples
Let with a uniform prior . Let the scores be and , so .
- The partition function is , so .
- The tilted distribution is and .
- Evaluate the objective at . Its expected score is . Its KL divergence from the prior is . The objective is , which matches .
- Try two other distributions to see that they do worse. gives expected score and KL , for . gives expected score and KL , for . Both are below .
Interpretation: the best distribution puts three times as much weight on as on (0.75 against 0.25), whereas the prior put equal weight on both. That factor is exactly . Any other choice of either loses score or pays more KL than it gains.
The plot shows the objective as a function of , with . It peaks at , where the value is .
- E_Q[f] - KL(Q || pi)
Let with a uniform prior, and scores . This is the same calculation as a softmax over three logits.
- Compute the exponentials: , , .
- The partition function is .
- The log is .
- The tilted distribution is the softmax of the scores: . These sum to .
- Evaluate the objective at . The expected score is . The KL from the uniform prior is . The objective is , which matches .
Interpretation: the highest-scoring configuration gets the most weight, but not all of it, because putting all weight there would cost too much KL. Here sits just below the largest score, . The gap, about , is the price of the prior's spread. In general , so with three states the gap is at most .
Note that is computed with the log-sum-exp trick in practice, subtracting the maximum score before exponentiating, so large scores do not overflow.
Tradeoffs and failure modes
The principle is exact, but using it in practice requires choices.
| Situation | What goes wrong | Better choice |
|---|---|---|
| The configuration space is huge, so cannot be summed | The exact log partition function is out of reach | Restrict to a simpler family and maximize the bound, which is the variational approach |
| The family of does not contain the tilted distribution | The bound is strictly below , and the gap is not visible from the bound alone | A richer family, or a sampling method such as Monte Carlo that targets directly |
| The prior is badly chosen | The bound is loose or the tilt is distorted, since KL is measured against the wrong reference | Pick a prior that already covers the plausible configurations |
| Scores are large | Direct exponentiation overflows | Log-sum-exp with the maximum subtracted first |
| Scores are noisy or estimated | The optimal fits the noise, and the bound overstates the value | Regularize or average over several score estimates |
A common mistake is to read the bound as an estimate of from either side. Any gives a lower bound, never an upper bound. An upper bound needs a different argument, such as the simple bound , which holds because the prior's weights sum to one.
History
The formula comes from Josiah Willard Gibbs's work on statistical mechanics in the late 19th century. In his 1902 book on the subject he described how a system at equilibrium is a distribution over states that balances low energy against entropy. The equilibrium distribution is the exponential tilt of the prior, and the free energy is the log of the normalizing constant. Gibbs's framework is the origin of the name.
The variational form as a supremum over distributions, with KL as the penalty, was developed in probability theory in the 1970s. Monroe Donsker and S. R. S. Varadhan used it to study large deviations of Markov processes, and it is now called the Donsker–Varadhan formula. In machine learning, the same identity underlies the evidence lower bound used in variational inference, which became popular in the 1990s and 2000s as a way to fit probabilistic models that have intractable normalizing constants. These dates are approximate, and the names are the main contributors rather than a full history.
Check yourself
QuestionWhy is the KL penalty needed? What would go wrong if the objective were only the expected score under ?Show answer
Without the penalty, the supremum of is achieved by putting all weight on the highest-scoring configuration, which gives . That is an upper bound on that is usually loose, and it ignores the prior entirely. The KL term measures how far has moved from the prior, and it is what makes the optimum the exponentially tilted distribution, with value exactly .
QuestionWith a uniform prior over two states and scores , , what is ?Show answer
, so . Therefore . The tilted distribution is , which is .
QuestionWhy does the Gibbs variational principle give a lower bound for any , and when is that bound tight?Show answer
For any , the objective equals . KL is non-negative, so the objective is at most , which means it is a lower bound. The bound is tight exactly when equals the tilted distribution , because then the KL term is zero.
QuestionIn a variational model, a family of distributions can only be a Gaussian with a fixed variance, and the true tilted distribution is skewed. What happens to the bound, and why?Show answer
The bound is still valid, since it holds for every , but it cannot reach because the tilted distribution is not in the family. The best Gaussian in the family gives a value strictly below , and the gap is the KL divergence from that Gaussian to the true tilted distribution. Enlarging the family, for example by allowing skew or by learning the variance, shrinks the gap.