Tutorials › Statistical Learning (Graduate) › Temperature, Loss Scale, and Weight Concentration

Exponential Weights and Convex Aggregation · Tutorial 324 of 989

Temperature, Loss Scale, and Weight Concentration

Learn how temperature and loss units control exponential-weight concentration, and how to quantify that concentration using relative entropy.

Advanced 11 min read

What You'll Learn

  • Define normalized exponential weights using empirical losses, a prior, and inverse temperature.
  • Translate a loss rescaling into the corresponding temperature adjustment.
  • Derive how pairwise weight ratios respond to empirical-risk gaps.
  • Prove that relative entropy from the prior increases with inverse temperature.
  • Identify the limiting weights as temperature approaches zero.
  • Avoid confusing a change of loss units with a change in the underlying candidate ranking.

Why Temperature and Loss Scale Matter

Exponential weights turn empirical losses into a probability distribution over candidate predictors. A candidate with lower empirical risk receives more weight, but the size of the difference matters: a small risk gap can have little effect or a large effect depending on the temperature. The numerical scale used to record losses matters for the same reason. Risks measured in different units cannot be compared through the exponential formula without accounting for that scale.

The main point is that temperature controls sensitivity to loss differences, not the ordering of candidates. We will make that distinction precise, calculate its consequences, and show how relative entropy measures the weights’ concentration relative to a prior distribution.

Definition and Basic Identities

Consider a finite set of \(M\) candidates, indexed by \(j=1,\ldots,M\). Let \(\hat R_j\) be candidate \(j\)'s empirical risk, and let \(\pi_j>0\) be its prior weight, with \(\sum_{j=1}^M \pi_j=1\). For inverse temperature \(\eta\geq 0\), define the normalized exponential weights by

$$ \hat w_j(\eta) = \frac{\pi_j\exp(-\eta\hat R_j)} {\sum_{k=1}^M \pi_k\exp(-\eta\hat R_k)}. $$

The denominator normalizes the weights so that they sum to one. When \(\eta>0\), the temperature is \(\tau=1/\eta\). Thus a low temperature means a large inverse temperature and greater sensitivity to risk gaps. At \(\eta=0\), the weights equal the prior: \(\hat w_j(0)=\pi_j\).

Definition: The exponential weights at inverse temperature \(\eta\) are the probabilities \(\hat w_j(\eta)\) above. Their normalizing constant is \(Z(\eta)=\sum_{k=1}^M\pi_k\exp(-\eta\hat R_k)\). The empirical risk averaged under these weights is \(\bar R(\eta)=\sum_{j=1}^M\hat w_j(\eta)\hat R_j\).

For any two candidates \(j\) and \(k\), division cancels the common normalizing constant:

$$ \frac{\hat w_j(\eta)}{\hat w_k(\eta)} = \frac{\pi_j}{\pi_k} \exp\bigl(-\eta(\hat R_j-\hat R_k)\bigr). $$

This identity separates two influences. The prior ratio sets the starting odds, while the empirical-risk difference changes those odds exponentially. If \(j\) has smaller empirical risk than \(k\), increasing \(\eta\) increases the odds in favor of \(j\).

Worked Example: Changing Temperature for Three Candidates

Suppose the empirical risks are \((0,1,2)\) and the prior is uniform, so \(\pi_j=1/3\) for each candidate. Since the common factor \(1/3\) cancels, at \(\eta=\log 2\) the unnormalized weights are \(1,1/2,1/4\). Their sum is \(7/4\), giving

$$ (\hat w_1,\hat w_2,\hat w_3) = \left(\frac{4}{7},\frac{2}{7},\frac{1}{7}\right). $$

At \(\eta=\log 4\), the unnormalized weights are \(1,1/4,1/16\), with sum \(21/16\). Thus

$$ (\hat w_1,\hat w_2,\hat w_3) = \left(\frac{16}{21},\frac{4}{21},\frac{1}{21}\right). $$

The best candidate's weight rises from about \(0.571\) to \(0.762\). The risk ordering did not change; the larger inverse temperature made the existing risk gaps count more strongly.

Loss Rescaling and Temperature

Suppose every empirical risk is multiplied by the same constant \(c>0\), as when changing from one loss unit to another. With inverse temperature \(\eta'\), the weights based on the rescaled risks are proportional to \(\pi_j\exp(-\eta'c\hat R_j)\). They are exactly the original weights at inverse temperature \(\eta\) when \(\eta'c=\eta\).

Key identity: Multiplying every empirical risk by \(c>0\) and replacing \(\eta\) by \(\eta/c\) leaves all normalized weights unchanged. Equivalently, if temperature is \(\tau=1/\eta\), preserving the weights after multiplying losses by \(c\) requires replacing \(\tau\) by \(c\tau\).

Adding a common constant to every empirical risk also leaves the weights unchanged, because it multiplies every unnormalized weight by the same factor. These two facts give a useful general expression. For any \(a>0\) and any real \(b\), the weights formed from risks \(a\hat R_j+b\) at inverse temperature \(\eta'\) equal the original weights at \(\eta\) whenever \(\eta'a=\eta\). The additive shift \(b\) has no effect on the normalized weights.

Worked Example: Changing Loss Units

Use the three risks \((0,1,2)\), the uniform prior, and inverse temperature \(\eta=\log 2\). If risks are doubled, the new risks are \((0,2,4)\). Keeping the original inverse temperature would give unnormalized weights \(1,1/4,1/16\), so concentration would increase. To preserve the original weights, use \(\eta'=(\log 2)/2\). Then the exponents are

$$ -\eta'(0,2,4)=(0,-\log 2,-2\log 2), $$

and the unnormalized weights are again \(1,1/2,1/4\). Normalizing gives \((4/7,2/7,1/7)\), exactly as before. Doubling the loss scale without adjusting temperature is not a neutral change: it doubles the effective inverse temperature.

How Concentration Changes

A direct measure of separation from the prior is the relative entropy

$$ D(\hat w(\eta)\Vert\pi) = \sum_{j=1}^M \hat w_j(\eta)\log\left(\frac{\hat w_j(\eta)}{\pi_j}\right). $$

It is zero when the weights equal the prior and increases as the weights move away from it. The next result shows exactly how this measure changes with inverse temperature. All risks here are finite real numbers, and all prior weights are positive.

Theorem: For finite \(M\), the function \(\bar R(\eta)\) is differentiable and \(\bar R'(\eta)=-\operatorname{Var}_{\hat w(\eta)}(\hat R)\). Moreover, \[ \frac{d}{d\eta}D(\hat w(\eta)\Vert\pi) = \eta\operatorname{Var}_{\hat w(\eta)}(\hat R)\geq 0. \] Thus relative entropy from the prior is nondecreasing in inverse temperature.

Proof. Write \(Z(\eta)=\sum_j\pi_j\exp(-\eta\hat R_j)\). Since this is a finite sum of differentiable functions and \(Z(\eta)>0\), its logarithm \(A(\eta)=\log Z(\eta)\) is differentiable. Differentiating gives

$$ A'(\eta) = \frac{-\sum_j\pi_j\hat R_j\exp(-\eta\hat R_j)}{Z(\eta)} = -\bar R(\eta). $$

Differentiating the weights directly yields

$$ \hat w_j'(\eta) = \hat w_j(\eta)\bigl(\bar R(\eta)-\hat R_j\bigr). $$

Therefore

$$ \bar R'(\eta) = \sum_j\hat w_j'(\eta)\hat R_j = \bar R(\eta)^2-\sum_j\hat w_j(\eta)\hat R_j^2 = -\operatorname{Var}_{\hat w(\eta)}(\hat R). $$

From the definition of the weights, \(\log(\hat w_j/\pi_j)=-\eta\hat R_j-\log Z(\eta)\). Summing this identity against \(\hat w_j\) gives \(D=-\eta\bar R-A\). Differentiate and use \(A'=-\bar R\):

$$ D' = -\bar R-\eta\bar R'-A' = -\eta\bar R' = \eta\operatorname{Var}_{\hat w(\eta)}(\hat R)\geq 0. $$

The variance is nonnegative, which proves the claimed monotonicity. If the risks are not all equal and \(\eta>0\), the variance is positive because every weight is positive; in that case the relative entropy is strictly increasing. \(\square\)

This theorem quantifies concentration relative to the chosen prior, including when the prior is nonuniform. For a uniform prior, \(D(\hat w\Vert\pi)=\log M-H(\hat w)\), where \(H(\hat w)=-\sum_j\hat w_j\log\hat w_j\) is Shannon entropy. Consequently, with a uniform prior, Shannon entropy is nonincreasing as \(\eta\) increases. With a nonuniform prior, it is relative entropy from the prior—not necessarily Shannon entropy—that has the general monotonicity guarantee.

Worked Example: A Nonuniform Prior and a Risk Gap

Take empirical risks \((1,1.5,3)\), prior weights \((0.6,0.3,0.1)\), and \(\eta=2\). Subtracting 1 from every risk does not change the normalized weights, so use the shifted risks \((0,0.5,2)\). The unnormalized weights are

$$ (0.6,\;0.3e^{-1},\;0.1e^{-4}) \approx (0.60000,\;0.11036,\;0.00183). $$

Their sum is approximately \(0.71220\), so the normalized weights are approximately \((0.8425,0.1550,0.0026)\). The first candidate had prior mass \(0.6\), but its lower empirical risk increases its weight substantially. The third candidate's higher risk reduces its weight despite its positive prior mass. The positive prior keeps every candidate's weight positive at finite \(\eta\); concentration is not the same as assigning exact zero weight.

The Low-Temperature Limit

The pairwise-ratio identity also describes the limiting behavior as \(\eta\) grows. Let \(\hat R_{\min}=\min_j\hat R_j\), and let \(S=\{j:\hat R_j=\hat R_{\min}\}\) be the set of empirical minimizers. Factoring \(\exp(-\eta\hat R_{\min})\) out of the normalizing constant gives

$$ \hat w_j(\eta) = \frac{\pi_j\exp\{-\eta(\hat R_j-\hat R_{\min})\}} {\sum_k\pi_k\exp\{-\eta(\hat R_k-\hat R_{\min})\}}. $$

For \(j\in S\), the exponential factor in this expression equals one. For \(j\notin S\), the gap \(\hat R_j-\hat R_{\min}\) is positive, so that factor tends to zero as \(\eta\) tends to infinity. Since there are only finitely many candidates, the denominator tends to \(\sum_{k\in S}\pi_k>0\). It follows that

$$ \lim_{\eta\to\infty}\hat w_j(\eta) = \begin{cases} \displaystyle\frac{\pi_j}{\sum_{k\in S}\pi_k}, & j\in S,\\[6pt] 0, & j\notin S. \end{cases} $$

Thus low temperature concentrates on the empirical minimizers. If there is a unique minimizer, its weight tends to one. If several candidates tie, the limiting weights among them are proportional to their prior masses, rather than necessarily equal.

Worked Example: A Finite Temperature Is Not Hard Selection

Suppose three candidates have risks \((0,0.2,0.4)\), a uniform prior, and \(\eta=5\). After canceling the common prior, the unnormalized weights are \((1,e^{-1},e^{-2})\), which sum to approximately \(1.50321\). The normalized weights are approximately

$$ (0.6652,\;0.2447,\;0.0900). $$

At \(\eta=10\), the unnormalized weights are \((1,e^{-2},e^{-4})\), which sum to approximately \(1.15365\). The normalized weights are approximately \((0.8668,0.1173,0.0159)\). Increasing inverse temperature makes the weight on the lowest-risk candidate larger, but at either finite value all three candidates retain positive weight. Only in the limit \(\eta\to\infty\) does the unique minimizer receive weight one.

Common Mistake and Practical Use

A common mistake is to say, “Multiplying all losses by a constant does not change which candidate is best, so it does not change the weights.” The first clause is correct; the conclusion is not. The normalized weights depend on the products \(\eta\hat R_j\), not only on the ranking. Scaling losses by \(c\) while keeping \(\eta\) fixed changes the effective inverse temperature from \(\eta\) to \(c\eta\). The weights are preserved only if the inverse temperature is also divided by \(c\).

This distinction matters when choosing a temperature or comparing implementations that use different conventions for loss scale. A temperature that produces moderate concentration for a loss recorded between zero and one may produce near-hard selection if the same loss is recorded on a scale one hundred times larger. Before interpreting weights, check the loss units, the inverse temperature, and the prior. Pairwise odds provide a quick diagnostic: for a risk gap \(\Delta>0\), the odds in favor of the lower-risk candidate are multiplied by \(\exp(\eta\Delta)\), relative to the prior odds.

Key takeaway: Exponential weights respond to scaled risk gaps. Increasing inverse temperature or multiplying losses by a positive constant increases sensitivity to those gaps; adjusting temperature inversely with the loss scale preserves the weights. Relative entropy from the prior gives a precise, nondecreasing measure of this concentration.

Check Your Understanding

Use the definitions and identities in this tutorial to answer the following.

  1. If every empirical risk is multiplied by 3, what change to inverse temperature preserves the exponential weights?
  2. For two candidates with equal prior weights and a risk gap of \(\Delta>0\), what is the ratio of the lower-risk candidate's weight to the higher-risk candidate's weight?
  3. Why does adding the same constant to every empirical risk leave normalized weights unchanged?
  4. What is the limiting distribution of the weights when several candidates tie for the minimum empirical risk?
  5. Why does the theorem guarantee that relative entropy from the prior is nondecreasing, even when the prior is nonuniform?
Clinical Biostats