Gibbs Variational Principle

Tilting a Distribution The Gibbs Variational Principle Temperature and Its Limits Relative Entropy and Log-Sum-Exp as a Conjugate Pair

Tilting a Distribution

Suppose a reference distribution \(\mathbf{q}\) on finitely many outcomes is given, together with a score \(x_k\) for each outcome \(k\). We look for the distribution \(\mathbf{p}\) that maximizes the expected score minus a price for moving away from \(\mathbf{q}\). The price is the KL divergence \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\). The answer is a single explicit distribution, obtained by reweighting \(\mathbf{q}\) by the exponentials of the scores, and the optimal value is the logarithm of the normalizing constant. This page proves that statement, the Gibbs variational principle, in the finite setting and restates it in terms of a pair of convex conjugates.

Convention. As on our page on entropy, \(\log\) is the natural logarithm and the limiting conventions stated there for \(0 \log 0\), \(0 \log \tfrac{0}{0}\), \(0 \log \tfrac{0}{q}\) and \(p \log \tfrac{p}{0}\) are in force.

We write \(\Delta_n = \{\, \mathbf{p} \in \mathbb{R}^n : p_k \geq 0, \ \sum_{k=1}^n p_k = 1 \,\}\) for the probability simplex, as in our gallery of conjugates. A vector \(\mathbf{p} \in \Delta_n\) is the same object as a distribution \(p\) on \(\{1, \ldots, n\}\) with \(p_k = p(k)\). We write such vectors in bold because we treat them as points of \(\mathbb{R}^n\). The support of \(\mathbf{q} \in \Delta_n\) is \(\operatorname{supp}(\mathbf{q}) = \{\, k : q_k \gt 0 \,\}\). It is nonempty, since the coordinates of \(\mathbf{q}\) sum to \(1\). For \(\mathbf{p} \in \Delta_n\) and \(\mathbf{x} \in \mathbb{R}^n\), the number \(\mathbf{p}^\top \mathbf{x} = \sum_k p_k x_k\) is the expected score under \(\mathbf{p}\).

Definition: Weighted Log-Sum-Exp and Gibbs Distribution

Let \(\mathbf{q} \in \Delta_n\) and \(\mathbf{x} \in \mathbb{R}^n\). The weighted log-sum-exp of \(\mathbf{x}\) with weights \(\mathbf{q}\) is \[ L_{\mathbf{q}}(\mathbf{x}) = \log \sum_{k=1}^n q_k e^{x_k}. \] The Gibbs distribution obtained by tilting \(\mathbf{q}\) by \(\mathbf{x}\) is the vector \(\mathbf{q}_{\mathbf{x}}\) with coordinates \[ (\mathbf{q}_{\mathbf{x}})_k = q_k \exp\big( x_k - L_{\mathbf{q}}(\mathbf{x}) \big), \quad k = 1, \ldots, n. \]

The sum inside the logarithm has a positive term for each \(k \in \operatorname{supp}(\mathbf{q})\) and no negative term, so \(L_{\mathbf{q}}(\mathbf{x})\) is a real number. Each coordinate of \(\mathbf{q}_{\mathbf{x}}\) is nonnegative, and \[ \begin{align*} \sum_{k=1}^n (\mathbf{q}_{\mathbf{x}})_k &= e^{-L_{\mathbf{q}}(\mathbf{x})} \sum_{k=1}^n q_k e^{x_k} \\\\ &= 1, \end{align*} \] so \(\mathbf{q}_{\mathbf{x}} \in \Delta_n\). Since \(q_k \exp(x_k - L_{\mathbf{q}}(\mathbf{x}))\) is positive exactly when \(q_k\) is, \(\operatorname{supp}(\mathbf{q}_{\mathbf{x}}) = \operatorname{supp}(\mathbf{q})\).

Tilting keeps the outcomes that \(\mathbf{q}\) allows and multiplies their probabilities by factors \(e^{x_k}\) before renormalizing. An outcome with \(q_k = 0\) stays impossible however large its score is.

For the uniform vector \(\mathbf{u} = (1/n, \ldots, 1/n)\), the Gibbs distribution is the softmax and the weighted log-sum-exp is a shifted log-sum-exp: \[ \begin{align*} \mathbf{u}_{\mathbf{x}} &= \operatorname{softmax}(\mathbf{x}), \\\\ L_{\mathbf{u}}(\mathbf{x}) &= \operatorname{lse}(\mathbf{x}) - \log n, \end{align*} \] with \(\operatorname{softmax}\) and \(\operatorname{lse}\) as defined before the theorem that negative entropy and log-sum-exp are conjugate. Both identities follow by putting \(q_k = 1/n\) into the definition. A general \(\mathbf{q}\) records how plausible each outcome was before the scores were seen, and the tilt moves probability toward the outcomes with higher scores.

The basic identity of the page compares an arbitrary \(\mathbf{p}\) with \(\mathbf{q}_{\mathbf{x}}\).

Lemma: The Gibbs Identity

Let \(\mathbf{q} \in \Delta_n\), \(\mathbf{x} \in \mathbb{R}^n\), and \(\mathbf{p} \in \Delta_n\) with \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \lt +\infty\). Then \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}_{\mathbf{x}}) \lt +\infty\) and \[ \mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = L_{\mathbf{q}}(\mathbf{x}) - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}_{\mathbf{x}}). \]

Proof.

Let \(P = \operatorname{supp}(\mathbf{p})\). By the definition of the KL divergence, finiteness of \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) means that \(q_k \gt 0\) for every \(k \in P\). The supports of \(\mathbf{q}\) and \(\mathbf{q}_{\mathbf{x}}\) coincide, so \((\mathbf{q}_{\mathbf{x}})_k \gt 0\) for every \(k \in P\) as well, and \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}_{\mathbf{x}})\) is finite.

A term with \(p_k = 0\) contributes \(0\) to both divergences, by the conventions for \(0 \log \tfrac{0}{q}\) and \(0 \log \tfrac{0}{0}\), and contributes \(0\) to \(\mathbf{p}^\top \mathbf{x}\). Both divergences are therefore finite sums over \(k \in P\). For \(k \in P\), the definition of \(\mathbf{q}_{\mathbf{x}}\) gives \[ \log \frac{p_k}{(\mathbf{q}_{\mathbf{x}})_k} = \log \frac{p_k}{q_k} - x_k + L_{\mathbf{q}}(\mathbf{x}). \] Multiplying by \(p_k\), summing over \(k \in P\) and using \(\sum_{k \in P} p_k = 1\), we obtain \[ D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}_{\mathbf{x}}) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) - \mathbf{p}^\top \mathbf{x} + L_{\mathbf{q}}(\mathbf{x}). \] Every quantity in this equation is a real number, so it may be rearranged into the stated identity.

The identity already gives the optimal value. By Gibbs' inequality, \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}_{\mathbf{x}}) \geq 0\), so \(\mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \leq L_{\mathbf{q}}(\mathbf{x})\) whenever \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) is finite. When it is \(+\infty\), the left-hand side is \(-\infty\) and the bound is trivial.

Since \(\operatorname{supp}(\mathbf{q}_{\mathbf{x}}) = \operatorname{supp}(\mathbf{q})\), the divergence \(D_{\mathbb{KL}}(\mathbf{q}_{\mathbf{x}} \| \mathbf{q})\) is finite, so the identity applies at \(\mathbf{p} = \mathbf{q}_{\mathbf{x}}\). Every term of the divergence of \(\mathbf{q}_{\mathbf{x}}\) from itself is \(0\), so \(D_{\mathbb{KL}}(\mathbf{q}_{\mathbf{x}} \| \mathbf{q}_{\mathbf{x}}) = 0\), and the bound is attained at \(\mathbf{q}_{\mathbf{x}}\). The uniqueness of the maximizer is proved in the section on the Gibbs variational principle. That proof rests on the conjugacy of negative entropy and log-sum-exp, which is proved without Jensen's inequality or the KL divergence.

The Gibbs Variational Principle

We now show that the bound of the section on tilting a distribution is attained only at the Gibbs distribution. The proof writes the KL divergence to a reference \(\mathbf{q}\) with full support as negative entropy minus a linear function, and then obtains the maximum and the maximizer from the conjugate pair formed by negative entropy and log-sum-exp. A reference with zeros reduces to that case by deleting the outcomes it excludes.

Theorem: Gibbs Variational Principle

Let \(\mathbf{q} \in \Delta_n\) and \(\mathbf{x} \in \mathbb{R}^n\). Then \[ L_{\mathbf{q}}(\mathbf{x}) = \max_{\mathbf{p} \in \Delta_n} \big( \mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \big), \] and the maximum is attained at the single point \(\hat{\mathbf{p}} = \mathbf{q}_{\mathbf{x}}\). That is, every \(\mathbf{p} \in \Delta_n\) with \(\mathbf{p} \neq \mathbf{q}_{\mathbf{x}}\) satisfies \[ \mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \lt L_{\mathbf{q}}(\mathbf{x}), \] where the left-hand side is \(-\infty\) when \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = +\infty\).

Proof.

Full support.
Suppose first that \(q_k \gt 0\) for every \(k\), and let \(\mathbf{b} = (\log q_1, \ldots, \log q_n) \in \mathbb{R}^n\). Let \(\phi\) be the closed entropy integrand from our discussion of extended-real convex functions: \(\phi(u) = u \log u\) for \(u \gt 0\), \(\phi(0) = 0\), and \(\phi(u) = +\infty\) for \(u \lt 0\). Let \(f(\mathbf{p}) = \sum_k \phi(p_k) + \iota_{\Delta_n}(\mathbf{p})\) be the negative entropy on \(\Delta_n\), where \(\iota_{\Delta_n}\) is the convex indicator of \(\Delta_n\). For \(\mathbf{p} \in \Delta_n\), the divergence \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) is finite because every \(q_k\) is positive, and by the convention \(0 \log 0 = 0\), \[ \begin{align*} D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) &= \sum_{k=1}^n \phi(p_k) - \sum_{k=1}^n p_k \log q_k \\\\ &= f(\mathbf{p}) - \mathbf{b}^\top \mathbf{p}. \end{align*} \] Hence, for every \(\mathbf{p} \in \Delta_n\), \[ \mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = (\mathbf{x} + \mathbf{b})^\top \mathbf{p} - f(\mathbf{p}). \] Since \(f = +\infty\) off \(\Delta_n\), the supremum of the right-hand side over \(\mathbf{p} \in \Delta_n\) is the conjugate \(f^*(\mathbf{x} + \mathbf{b})\). By the theorem on negative entropy and log-sum-exp, this supremum equals \(\operatorname{lse}(\mathbf{x} + \mathbf{b})\) and is attained only at \(\operatorname{softmax}(\mathbf{x} + \mathbf{b})\). The two sides of the identity above agree on \(\Delta_n\), so the left-hand side has the same supremum and the same maximizers. Finally \(e^{x_k + b_k} = q_k e^{x_k}\), so \[ \begin{align*} \operatorname{lse}(\mathbf{x} + \mathbf{b}) &= \log \sum_{k=1}^n q_k e^{x_k} \\\\ &= L_{\mathbf{q}}(\mathbf{x}), \\\\ \operatorname{softmax}(\mathbf{x} + \mathbf{b})_k &= \frac{q_k e^{x_k}}{\sum_{j=1}^n q_j e^{x_j}} \\\\ &= (\mathbf{q}_{\mathbf{x}})_k. \end{align*} \]

General reference.
Let \(S = \operatorname{supp}(\mathbf{q})\), a nonempty set with \(m\) elements. If \(\mathbf{p} \in \Delta_n\) has \(p_k \gt 0\) for some \(k \notin S\), then \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = +\infty\), and the objective equals \(-\infty\), which is less than \(L_{\mathbf{q}}(\mathbf{x})\). Such a \(\mathbf{p}\) differs from \(\mathbf{q}_{\mathbf{x}}\), whose support is \(S\). Every other \(\mathbf{p} \in \Delta_n\) vanishes off \(S\). For a vector \(\mathbf{v} \in \mathbb{R}^n\), write \(\mathbf{v}_S \in \mathbb{R}^m\) for its coordinates indexed by \(S\), in increasing order. The map \(\mathbf{p} \mapsto \mathbf{p}_S\) is a bijection from the vectors of \(\Delta_n\) that vanish off \(S\) onto \(\Delta_m\), and \(\mathbf{q}_S \in \Delta_m\) has full support. Terms with \(k \notin S\) contribute \(0\) to every sum below, so for \(\mathbf{p}\) vanishing off \(S\), \[ \begin{align*} \mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) &= \mathbf{p}_S^\top \mathbf{x}_S - D_{\mathbb{KL}}(\mathbf{p}_S \| \mathbf{q}_S), \\\\ L_{\mathbf{q}}(\mathbf{x}) &= L_{\mathbf{q}_S}(\mathbf{x}_S), \end{align*} \] and \((\mathbf{q}_{\mathbf{x}})_S = (\mathbf{q}_S)_{\mathbf{x}_S}\). By the full-support case in \(\mathbb{R}^m\), the objective is at most \(L_{\mathbf{q}}(\mathbf{x})\), with equality exactly when \(\mathbf{p}_S = (\mathbf{q}_{\mathbf{x}})_S\). Since \(\mathbf{p}\) and \(\mathbf{q}_{\mathbf{x}}\) both vanish off \(S\), this means \(\mathbf{p} = \mathbf{q}_{\mathbf{x}}\). Combining the two kinds of \(\mathbf{p}\), we conclude that \(\mathbf{q}_{\mathbf{x}}\), which vanishes off \(S\), attains the value \(L_{\mathbf{q}}(\mathbf{x})\) and that every other \(\mathbf{p} \in \Delta_n\) gives a strictly smaller value.

For the value alone, the full-support case is an instance of the rules for conjugates. The relevant rule is the one for adding an affine function, applied to \(g(\mathbf{p}) = f(\mathbf{p}) - \mathbf{b}^\top \mathbf{p}\) with vector \(-\mathbf{b}\) and constant \(d = 0\). This \(g\) equals \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) on \(\Delta_n\) and \(+\infty\) off it. The rule gives \(g^*(\mathbf{x}) = f^*(\mathbf{x} + \mathbf{b})\) and speaks only of values, so the proof repeats the computation pointwise to obtain the maximizer as well.

For the uniform reference \(\mathbf{u}\) the theorem is the conjugate computation itself. For \(\mathbf{p} \in \Delta_n\) we have \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{u}) = \sum_k \phi(p_k) + \log n\), and \(L_{\mathbf{u}}(\mathbf{x}) = \operatorname{lse}(\mathbf{x}) - \log n\). Both sides of the principle are thus shifted by \(-\log n\) from the two sides of the identity \(f^* = \operatorname{lse}\) used in the proof. At \(\mathbf{x} = \mathbf{0}\) the principle with \(\mathbf{q} = \mathbf{u}\) says that \(-D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{u}) \leq 0\) with equality only at \(\mathbf{p} = \mathbf{u}\), that is, \(-\sum_k \phi(p_k) \leq \log n\) with equality only at the uniform vector. This is the statement that the uniform distribution maximizes entropy, equality case included.

A reference with positive weights adds nothing beyond a shift of the scores, and that shift is the first step of the proof. The uniform reference cannot express a weight equal to zero, which excludes an outcome.

Rearranged, the theorem bounds the divergence from below by a family of explicit quantities: for every \(\mathbf{p} \in \Delta_n\), \[ D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \geq \mathbf{p}^\top \mathbf{x} - L_{\mathbf{q}}(\mathbf{x}) \quad \text{for all } \mathbf{x} \in \mathbb{R}^n, \] with equality exactly when \(\mathbf{p} = \mathbf{q}_{\mathbf{x}}\). The bound is trivial and strict when \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = +\infty\). Every score vector \(\mathbf{x}\) therefore gives a lower bound on the divergence, and evaluating that bound costs one log-sum-exp.

When \(\operatorname{supp}(\mathbf{p}) = \operatorname{supp}(\mathbf{q})\), the scores \(x_k = \log(p_k / q_k)\) on the support (and any values off it) give \(\mathbf{q}_{\mathbf{x}} = \mathbf{p}\), and equality holds. When the supports differ, no score vector gives equality, and the section on the conjugate pair shows that the bounds still approach the divergence.

Temperature and Its Limits

The divergence is often given a weight \(\tau \gt 0\), called the temperature. A small \(\tau\) makes it cheap to move away from \(\mathbf{q}\) within the support of \(\mathbf{q}\) and lets the scores dominate there. A large \(\tau\) makes it expensive and keeps the maximizer near \(\mathbf{q}\). Dividing the objective by \(\tau\) reduces the weighted problem to the principle we have proved.

Corollary: Gibbs Variational Principle with Temperature

Let \(\mathbf{q} \in \Delta_n\), \(\mathbf{x} \in \mathbb{R}^n\) and \(\tau \gt 0\). Then \[ \tau L_{\mathbf{q}}(\mathbf{x} / \tau) = \max_{\mathbf{p} \in \Delta_n} \big( \mathbf{p}^\top \mathbf{x} - \tau D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \big), \] with \(\hat{\mathbf{p}}_\tau = \mathbf{q}_{\mathbf{x} / \tau}\) as its only maximizer. The coordinates of \(\hat{\mathbf{p}}_\tau\) are \[ (\hat{\mathbf{p}}_\tau)_k = \frac{q_k e^{x_k / \tau}}{\sum_{j=1}^n q_j e^{x_j / \tau}}, \quad k = 1, \ldots, n. \]

Proof.

For every \(\mathbf{p} \in \Delta_n\), \[ \mathbf{p}^\top \mathbf{x} - \tau D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = \tau \big( \mathbf{p}^\top (\mathbf{x} / \tau) - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \big), \] both sides being \(-\infty\) when the divergence is \(+\infty\). Multiplication by \(\tau \gt 0\) preserves strict inequalities, so the left-hand side has the same maximizers as the bracket, and its maximum is \(\tau\) times the maximum of the bracket. By the Gibbs variational principle applied to the score vector \(\mathbf{x} / \tau\), the bracket has maximum \(L_{\mathbf{q}}(\mathbf{x} / \tau)\), attained only at \(\mathbf{q}_{\mathbf{x} / \tau}\). The formula for the coordinates is the definition of the Gibbs distribution with \(\mathbf{x} / \tau\) in place of \(\mathbf{x}\).

The two extremes of the temperature isolate the two terms of the objective. As \(\tau \to 0^+\), the expected score dominates, and the maximizer should concentrate on the best outcomes that \(\mathbf{q}\) allows. As \(\tau \to \infty\), the divergence dominates. By the principle at \(\mathbf{x} = \mathbf{0}\), this term vanishes at \(\mathbf{q}\) and nowhere else. Since \(L_{\mathbf{q}}(\mathbf{0}) = \log \sum_k q_k = 0\), the Gibbs vector \(\mathbf{q}_{\mathbf{0}}\) is \(\mathbf{q}\) itself, and the principle makes it the unique maximizer of \(-D_{\mathbb{KL}}(\cdot \| \mathbf{q})\). So the maximizer should return to \(\mathbf{q}\). The next proposition makes both statements precise.

Proposition: Zero- and Infinite-Temperature Limits

Let \(\mathbf{q} \in \Delta_n\) and \(\mathbf{x} \in \mathbb{R}^n\), let \(S = \operatorname{supp}(\mathbf{q})\), and let \[ \begin{align*} M &= \max_{k \in S} x_k, \\\\ A &= \{\, k \in S : x_k = M \,\}, \\\\ q(A) &= \sum_{k \in A} q_k. \end{align*} \] Write \(V(\tau) = \tau L_{\mathbf{q}}(\mathbf{x} / \tau)\) for the optimal value and \(\hat{\mathbf{p}}_\tau\) for the maximizer in the Gibbs variational principle with temperature.

(a) Zero temperature. For every \(\tau \gt 0\), \[ \begin{align*} M + \tau \log q(A) &\leq V(\tau) \\\\ &\leq M, \end{align*} \] so \(V(\tau) \to M\) as \(\tau \to 0^+\). Moreover \(\hat{\mathbf{p}}_\tau \to \mathbf{r}\) coordinatewise, where \(r_k = q_k / q(A)\) for \(k \in A\) and \(r_k = 0\) otherwise.

(b) Infinite temperature. As \(\tau \to \infty\), \(V(\tau) \to \mathbf{q}^\top \mathbf{x}\) and \(\hat{\mathbf{p}}_\tau \to \mathbf{q}\) coordinatewise.

Proof.

The set \(S\) is nonempty, so \(M\) and \(A\) are well defined, \(A\) is nonempty, and \(0 \lt q(A) \leq 1\). Let \(Z_\tau = \sum_{k=1}^n q_k e^{x_k / \tau}\), so that \(V(\tau) = \tau \log Z_\tau\). Only the terms with \(k \in S\) are nonzero.

(a)
Every \(k \in S\) has \(x_k \leq M\), so \(e^{x_k / \tau} \leq e^{M / \tau}\), and \(Z_\tau \leq e^{M / \tau} \sum_{k \in S} q_k = e^{M / \tau}\). Keeping only the terms with \(k \in A\) gives \(Z_\tau \geq q(A)\, e^{M / \tau}\). Taking logarithms and multiplying by \(\tau \gt 0\), we obtain \[ \begin{align*} M + \tau \log q(A) &\leq \tau \log Z_\tau \\\\ &\leq M. \end{align*} \] Since \(\log q(A)\) is a fixed real number, \(\tau \log q(A) \to 0\), which gives \(V(\tau) \to M\). For the maximizer, divide the numerator and the denominator of \((\hat{\mathbf{p}}_\tau)_k\) by \(e^{M / \tau}\): \[ (\hat{\mathbf{p}}_\tau)_k = \frac{q_k e^{(x_k - M) / \tau}}{q(A) + \sum_{j \in S \setminus A} q_j e^{(x_j - M) / \tau}}. \] For \(j \in S \setminus A\) we have \(x_j - M \lt 0\), so \(e^{(x_j - M) / \tau} \to 0\), and the denominator tends to \(q(A) \gt 0\). The numerator equals \(q_k\) for \(k \in A\), tends to \(0\) for \(k \in S \setminus A\), and equals \(0\) for \(k \notin S\). Hence \((\hat{\mathbf{p}}_\tau)_k \to r_k\) for every \(k\).

(b)
Let \(h(t) = \log \sum_{k=1}^n q_k e^{t x_k}\) for \(t \in \mathbb{R}\). The sum has finitely many exponential terms and is positive, so \(h\) is differentiable, with \(h(0) = \log 1 = 0\) and \[ \begin{align*} h'(0) &= \frac{\sum_{k=1}^n q_k x_k}{\sum_{k=1}^n q_k} \\\\ &= \mathbf{q}^\top \mathbf{x}. \end{align*} \] With \(t = 1 / \tau\), we have \[ \begin{align*} V(\tau) &= h(t) / t \\\\ &= (h(t) - h(0)) / t, \end{align*} \] and \(t \to 0^+\) as \(\tau \to \infty\), so \(V(\tau) \to h'(0) = \mathbf{q}^\top \mathbf{x}\). For the maximizer, \(e^{x_k / \tau} \to 1\) for every \(k\), so the numerator of \((\hat{\mathbf{p}}_\tau)_k\) tends to \(q_k\) and the denominator to \(\sum_j q_j = 1\).

Both limit values are expected scores, each taken under the limit of the maximizers. The distributions with finite divergence from \(\mathbf{q}\) are those that vanish off \(S\). The value \(M\) is the largest expected score among them, since every such \(\mathbf{p}\) has \(\mathbf{p}^\top \mathbf{x} \leq M\) and \(\mathbf{r}\) attains \(M\). Here \(\mathbf{r}\) lies in \(\Delta_n\) and vanishes off \(S\), because \(A \subseteq S\). The value \(\mathbf{q}^\top \mathbf{x}\) is the expected score of the reference itself, whose divergence from \(\mathbf{q}\) is \(0\). In the zero-temperature limit the reference decides which outcomes are allowed, the scores pick the best of them, and, beyond that, it enters only through the tie-breaking weights \(q_k / q(A)\) among those best outcomes.

Relative Entropy and Log-Sum-Exp as a Conjugate Pair

The principle can also be stated in terms of the convex conjugate. For \(\mathbf{q} \in \Delta_n\), define \(K_{\mathbf{q}} : \mathbb{R}^n \to (-\infty, +\infty]\) by \[ K_{\mathbf{q}}(\mathbf{p}) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) + \iota_{\Delta_n}(\mathbf{p}), \] with the convex indicator \(\iota_{\Delta_n}\).

The divergence is defined only for \(\mathbf{p} \in \Delta_n\), and the indicator assigns \(+\infty\) to every other \(\mathbf{p}\), so \(K_{\mathbf{q}}\) is defined on all of \(\mathbb{R}^n\). The function \(K_{\mathbf{q}}\) never takes the value \(-\infty\), because by the conventions each term of the divergence is a real number or \(+\infty\), and a finite sum of such terms is a real number or \(+\infty\). Moreover \(K_{\mathbf{q}}(\mathbf{q}) = 0\). Indeed, each term of \(D_{\mathbb{KL}}(\mathbf{q} \| \mathbf{q})\) with \(q_k \gt 0\) is \(q_k \log 1 = 0\), and each term with \(q_k = 0\) is \(0\) by the convention for \(0 \log \tfrac{0}{0}\). Hence \(K_{\mathbf{q}}\) is proper. For the uniform reference, \(K_{\mathbf{u}}\) is the negative entropy on \(\Delta_n\) plus the constant \(\log n\).

Theorem: The Conjugate of Relative Entropy on the Simplex

For every \(\mathbf{q} \in \Delta_n\) and \(\mathbf{x} \in \mathbb{R}^n\), \[ K_{\mathbf{q}}^*(\mathbf{x}) = L_{\mathbf{q}}(\mathbf{x}), \] and \(\mathbf{q}_{\mathbf{x}}\) is the only point at which the supremum defining \(K_{\mathbf{q}}^*(\mathbf{x})\) is attained.

Proof.

By definition, \(K_{\mathbf{q}}^*(\mathbf{x})\) is the supremum of \(\mathbf{x}^\top \mathbf{p} - K_{\mathbf{q}}(\mathbf{p})\) over \(\mathbf{p} \in \mathbb{R}^n\). A point off \(\Delta_n\) contributes \(-\infty\), and for \(\mathbf{p} \in \Delta_n\) the expression equals \(\mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\). The Gibbs variational principle shows that the supremum of this expression over \(\Delta_n\) is \(L_{\mathbf{q}}(\mathbf{x})\) and that its only maximizer is \(\mathbf{q}_{\mathbf{x}}\).

The reverse direction asks for the conjugate of \(L_{\mathbf{q}}\). One route would show that \(K_{\mathbf{q}}\) is closed and convex, conjugate both sides of the identity \(K_{\mathbf{q}}^* = L_{\mathbf{q}}\), and use the biconjugate theorem. That theorem recovers a proper closed convex function from its conjugate, and a later page develops it. We compute the conjugate directly instead, because the computation also shows when the supremum is attained.

Theorem: The Conjugate of the Weighted Log-Sum-Exp

For every \(\mathbf{q} \in \Delta_n\) and \(\mathbf{p} \in \mathbb{R}^n\), \[ L_{\mathbf{q}}^*(\mathbf{p}) = K_{\mathbf{q}}(\mathbf{p}). \] That is, \(\sup_{\mathbf{x} \in \mathbb{R}^n} \big( \mathbf{p}^\top \mathbf{x} - L_{\mathbf{q}}(\mathbf{x}) \big)\) equals \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) for \(\mathbf{p} \in \Delta_n\) and \(+\infty\) otherwise. When the value is finite, the supremum is attained if and only if \(\operatorname{supp}(\mathbf{p}) = \operatorname{supp}(\mathbf{q})\).

Proof.

Write \(\Psi(\mathbf{x}) = \mathbf{p}^\top \mathbf{x} - L_{\mathbf{q}}(\mathbf{x})\), let \(S = \operatorname{supp}(\mathbf{q})\), let \(\mathbf{1}\) be the vector of ones and \(\mathbf{e}_j\) the \(j\)-th standard basis vector. We use two facts about \(L_{\mathbf{q}}\). First, \(L_{\mathbf{q}}(\mathbf{x} + t\mathbf{1}) = L_{\mathbf{q}}(\mathbf{x}) + t\) for \(t \in \mathbb{R}\), because \(\sum_k q_k e^{x_k + t} = e^t \sum_k q_k e^{x_k}\). Second, \(L_{\mathbf{q}}(\mathbf{0}) = \log \sum_k q_k = 0\).

Coordinates not summing to one.
If \(\sum_k p_k \neq 1\), then \(\Psi(t\mathbf{1}) = t \big( \sum_k p_k - 1 \big)\), which tends to \(+\infty\) as \(t \to +\infty\) or as \(t \to -\infty\), according to the sign of \(\sum_k p_k - 1\). So \(L_{\mathbf{q}}^*(\mathbf{p}) = +\infty\).

A negative coordinate.
If \(\sum_k p_k = 1\) and \(p_j \lt 0\) for some \(j\), take \(\mathbf{x} = -t\mathbf{e}_j\) with \(t \gt 0\). Then \(\sum_k q_k e^{x_k} \leq \sum_k q_k = 1\), so \(L_{\mathbf{q}}(-t\mathbf{e}_j) \leq 0\) and \(\Psi(-t\mathbf{e}_j) \geq -t p_j\), which tends to \(+\infty\) as \(t \to +\infty\). Hence \(L_{\mathbf{q}}^*(\mathbf{p}) = +\infty\).

Mass outside the support of \(\mathbf{q}\).
Let \(\mathbf{p} \in \Delta_n\) with \(p_j \gt 0\) for some \(j \notin S\). Then \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = +\infty\). Since \(q_j = 0\), the coordinate \(x_j\) does not enter \(L_{\mathbf{q}}\), so \(L_{\mathbf{q}}(t\mathbf{e}_j) = L_{\mathbf{q}}(\mathbf{0}) = 0\) and \(\Psi(t\mathbf{e}_j) = t p_j \to +\infty\) as \(t \to +\infty\). So \(L_{\mathbf{q}}^*(\mathbf{p}) = +\infty = K_{\mathbf{q}}(\mathbf{p})\).

Finite divergence.
Let \(\mathbf{p} \in \Delta_n\) vanish off \(S\), so that \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) is finite, and let \(P = \operatorname{supp}(\mathbf{p}) \subseteq S\). For every \(\mathbf{x}\), the Gibbs variational principle gives \(\mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) \leq L_{\mathbf{q}}(\mathbf{x})\), that is, \(\Psi(\mathbf{x}) \leq D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\). For the reverse inequality, fix \(t \gt 0\) and let \(x_k = \log(p_k / q_k)\) for \(k \in P\) and \(x_k = -t\) otherwise. With \(c = \sum_{k \in S \setminus P} q_k \geq 0\), \[ \begin{align*} \sum_{k=1}^n q_k e^{x_k} &= \sum_{k \in P} p_k + c\, e^{-t} \\\\ &= 1 + c\, e^{-t}, \end{align*} \] and \(\mathbf{p}^\top \mathbf{x} = \sum_{k \in P} p_k \log(p_k / q_k) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\). Hence \(\Psi(\mathbf{x}) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) - \log(1 + c\, e^{-t})\), which tends to \(D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) as \(t \to \infty\). So \(L_{\mathbf{q}}^*(\mathbf{p}) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q}) = K_{\mathbf{q}}(\mathbf{p})\).

Attainment.
In the case of finite divergence, suppose that \(\Psi(\mathbf{x}) = D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) for some \(\mathbf{x} \in \mathbb{R}^n\). Then \(\mathbf{p}\) maximizes the objective of the principle for this score vector, and the only maximizer is \(\mathbf{q}_{\mathbf{x}}\), so \(\mathbf{p} = \mathbf{q}_{\mathbf{x}}\). Since \(\operatorname{supp}(\mathbf{q}_{\mathbf{x}}) = S\), the supremum can be attained only if \(P = S\). Conversely, if \(P = S\), then \(c = 0\), and the score vector constructed above attains the supremum for every \(t\).

The two theorems say that \(K_{\mathbf{q}}\) and \(L_{\mathbf{q}}\) are conjugate to each other. Since every conjugate is closed and convex, both functions have these properties.

Now let \(\mathbf{p} \in \Delta_n\) with \(\operatorname{supp}(\mathbf{p}) = \operatorname{supp}(\mathbf{q})\). Equality in the Fenchel-Young inequality, \(K_{\mathbf{q}}(\mathbf{p}) + L_{\mathbf{q}}(\mathbf{x}) = \mathbf{p}^\top \mathbf{x}\), holds exactly when \(\mathbf{p}\) attains the supremum defining \(K_{\mathbf{q}}^*(\mathbf{x})\). By the uniqueness in the conjugate of relative entropy, this happens exactly at the score vectors with \(\mathbf{q}_{\mathbf{x}} = \mathbf{p}\). On the support, the condition \((\mathbf{q}_{\mathbf{x}})_k = p_k\) means \(x_k = \log(p_k / q_k) + L_{\mathbf{q}}(\mathbf{x})\). Conversely, if \(x_k = \log(p_k / q_k) + \gamma\) on the support for a constant \(\gamma\), with arbitrary values off it, then \(\sum_k q_k e^{x_k} = e^{\gamma} \sum_k p_k = e^{\gamma}\), so \(L_{\mathbf{q}}(\mathbf{x}) = \gamma\) and \(\mathbf{q}_{\mathbf{x}} = \mathbf{p}\). Equality therefore holds exactly for the score vectors of this form.

Where the Gibbs Distribution Appears

Softmax and temperature. Under the uniform reference, tilting reduces to the softmax, the map that gives the class probabilities of multinomial logistic regression. The temperature form explains two uses of the softmax. The softmax exploration rule of reinforcement learning, which chooses action \(a\) with probability proportional to \(\exp(Q(s, a) / \tau)\), is the unique distribution on the actions that maximizes the expected action value plus \(\tau\) times the entropy. Each row of an attention matrix with temperature \(\tau\) is, in the same way, the maximizer of the expected score plus \(\tau\) times the entropy, with the scores of the row taken before the division by \(\tau\).

Variational inference.
Let a latent variable take values in \(\{1, \ldots, n\}\) with prior \(\mathbf{q}\). Suppose that every latent value gives the observation a positive likelihood, and let \(x_k\) be the logarithm of the likelihood for the latent value \(k\), so that \(\mathbf{x} \in \mathbb{R}^n\). Then \(e^{L_{\mathbf{q}}(\mathbf{x})}\) is the evidence, \(\mathbf{q}_{\mathbf{x}}\) is the posterior, and \(\mathbf{p}^\top \mathbf{x} - D_{\mathbb{KL}}(\mathbf{p} \| \mathbf{q})\) is the evidence lower bound of a distribution \(\mathbf{p}\) over the latent values. The Gibbs identity is then the finite case of the ELBO-KL decomposition, stated there for densities, with the roles of the letters \(p\) and \(q\) exchanged. The principle says that the evidence lower bound is maximized exactly at the posterior, with the log-evidence as its maximum. The coordinate ascent update of mean-field inference follows the same pattern for one factor at a time, with densities in place of vectors.

The exponential family.
Consider a family on \(\{1, \ldots, n\}\) whose sufficient statistic sends each outcome \(k\) to its indicator vector \(\mathbf{e}_k\) and whose base measure is a probability vector \(\mathbf{h}\). The family has the log-partition function \(L_{\mathbf{h}}\), and its member with natural parameter \(\boldsymbol{\eta} \in \mathbb{R}^n\) is the Gibbs distribution \(\mathbf{h}_{\boldsymbol{\eta}}\). Our page on the exponential family uses the first of the two theorems of this section to show that \(L_{\mathbf{h}}\) is the convex conjugate of \(K_{\mathbf{h}}\), the relative entropy with respect to \(\mathbf{h}\). That page does not treat this duality for other exponential families.

KL-regularized objectives.
Consider a model that, given a prompt, outputs a distribution \(\pi\) over responses. Fine-tuning it toward a reward \(r\) while keeping it close to a reference model \(\pi_{\mathrm{ref}}\) is often posed as maximizing \(\mathbb{E}_{\pi}[r] - \beta\, D_{\mathbb{KL}}(\pi \| \pi_{\mathrm{ref}})\) with \(\beta \gt 0\). The regularizer \(D_{\mathbb{KL}}(\pi \| \pi_{\mathrm{ref}})\) appears in our discussion of Radon-Nikodym derivatives. For a fixed prompt and a finite set of responses \(y\), the temperature form with \(\tau = \beta\), \(\mathbf{q} = \pi_{\mathrm{ref}}\) and \(\mathbf{x} = r\) gives the maximizer in closed form, \(\hat{\pi}(y) \propto \pi_{\mathrm{ref}}(y)\, e^{r(y) / \beta}\).