TL;DR
Take a random quantity, average it, then apply a convex function. Compare that with applying the function first and averaging afterwards. For a convex function the second answer is never smaller. Jensen's inequality says exactly this: the function of the average is at most the average of the function, and the gap between them measures how much the randomness matters.
Where you'll see it: in proving that the evidence lower bound is a valid bound, in showing that a KL divergence is never negative, in the AM-GM inequality, and in explaining why plugging an average into a nonlinear function gives a biased estimate.
Intuition
A function is convex if its graph is shaped like a bowl: the straight segment joining any two points on the graph lies on or above the graph in between. Take and pick two points, and . The chord between them runs from height 1 to height 81. The curve between those two points sits below that chord.
Now let be a random number that equals 1 or 9, each with probability one half. Two things can be computed:
- Average first, then apply . The average of is 5, and .
- Apply first, then average. The values are and , whose average is 41.
The second number is bigger. That is no accident. Every point of the random variable sits on the curve, and the average of those points lies on the chord, which lies above the curve. Averaging the outputs moves you up to the chord; averaging the inputs and then reading the curve puts you down on the curve.
- f(x) = x^2
- chord from (1, 1) to (9, 81)
The same picture explains why the idea matters. Whenever a quantity is uncertain and you need some nonlinear function of it, the shortcut of applying the function to the average gives an answer that is too low for a convex function and too high for a concave one.
The math
Convex functions
A function defined on an interval is convex if, for every pair of points and and every weight between 0 and 1,
A function is concave when the inequality is reversed. Here is a mixing weight: picks the midpoint of and .
The left side is the function at a blend of two inputs. The right side is the same blend of the two outputs, which is the height of the chord. The definition says the curve stays on or below the chord; the allows the function to be linear on a stretch. The convex function lesson develops this in full.
Jensen's inequality
Statement. Let be a random variable with a finite mean, and let be convex. Then
If is concave, the inequality flips: .
Proof for a differentiable convex . Let . Draw the tangent line to at :
Convexity means the curve lies on or above every tangent line, so for all . Take expectations on both sides. The expectation is monotone, so
The right side is linear in , so it can be split up:
Putting the two lines together gives , which is the claim. The tangent line is the key tool: it touches the curve at the mean, and a straight line commutes with averaging. Convex functions that are not differentiable at have a supporting line with a slope chosen from the subgradient, and the same argument goes through.
Equality. For a strictly convex , equality holds only when is constant with probability 1. For a function that is linear on the range of , equality also holds. That is why the chord picture is tight only when the two points coincide.
Finite form. With weights that sum to 1 and points ,
This is the same statement with taking the value with probability .
Two standard consequences
Variance is never negative. Take , which is convex. Jensen gives . Subtracting the left side from the right gives
So variance can never be negative, and it is zero only when is constant.
Arithmetic mean versus geometric mean. Take , which is concave, so the inequality flips. For positive numbers with equal weights ,
Exponentiating both sides gives the AM-GM inequality: the arithmetic mean is at least the geometric mean.
Use in the evidence lower bound
Variational inference needs a lower bound on that can be optimised. Introduce any distribution over a hidden variable and write . Since is concave, Jensen gives
The right side is the evidence lower bound. Concavity of is used only in this one step, and it is why the bound holds for every choice of (with wherever ).
Worked examples
Let equal 2 or 6, each with probability one half, and let .
- Average first: , so .
- Apply first: and , so .
- Check the inequality: . The gap is 4.
- The gap equals the variance. The values are 2 and 6, each 2 away from the mean 4, so .
- Interpretation: the more the variable spreads out around its mean, the larger the gap between averaging before and after the convex function.
Let equal 0 or 2 with probability one half each, and let , which is convex.
- , so .
- and , so .
- Check: . Holds.
- Practical reading: a model that predicts for a quantity that is really with uncertain will systematically underestimate the average value.
Take the three numbers 1, 4 and 16, each with weight , and the concave function .
- Arithmetic mean: .
- Mean of the logs: , which is .
- Jensen with a concave function says . Indeed .
- Exponentiate: the geometric mean is and the arithmetic mean is 7. So , as AM-GM promises.
Tradeoffs and failure modes
Jensen is the right tool when you need to compare a function of an average with an average of a function, and you know the function's curvature. It gives a bound with no distributional assumptions beyond a finite mean.
The common mistakes are all about the direction of the inequality:
| Situation | What goes wrong | Better choice |
|---|---|---|
| Plugging the sample mean into a convex function to estimate | The estimate is biased low, since | Average over the samples |
| Reversing the inequality for a concave function | The bound points the wrong way and the proof fails | Check the sign of first |
| Using Jensen on a function that is neither convex nor concave | No inequality holds in general | Bound the function on its range, or use a Taylor expansion |
| Expecting equality in practice | Equality needs a constant variable or a linear function | Use the gap as a measure of uncertainty |
Some practical warnings:
- Jensen gives a bound, not the size of the gap. It says which way the error goes, but a tight estimate of usually needs a second-order term such as .
- Check that the expectation exists. If has heavy tails and is infinite, the statement is meaningless.
- Convexity is a property of , not of the data. Jensen says nothing about the distribution of beyond its mean, so the gap can be large or tiny for the same .
Alternatives include exact computation when the distribution is known, Monte Carlo averaging of over samples, and second-order expansions when the variance is small.
History
Johan Jensen, a Danish mathematician who worked mainly as an engineer at the Copenhagen telephone company, published the general statement in 1906 in Acta Mathematica, in a paper on convex functions and inequalities between mean values. Special cases were known long before: the arithmetic-geometric mean inequality was known in special cases long before, and inequalities of the same flavour appeared in the work of Hölder and others in the nineteenth century.
What Jensen did was isolate the principle. A single statement about convex functions and averages covers many earlier results at once, and the proof uses nothing but the definition of convexity and the linearity of averaging. That generality is why it caught on. It became a standard tool in analysis, then in probability, and later in statistics and information theory, where Gibbs' inequality and the non-negativity of KL divergence both follow from it.
Its modern prominence in machine learning comes from variational methods. The step that turns a log of an expectation into an expectation of a log is an application of Jensen, and it is the reason the evidence lower bound can be optimised by gradient methods.
Check yourself
QuestionA function is convex. What can you say about compared with , and what happens if is concave?Show answer
For convex , : the function of the average is at most the average of the function. For concave the inequality reverses. The intuition is that a convex curve lies below its chords, so averaging after applying lands above the curve.
QuestionLet equal 3 or 7 with probability one half each, and let . Compute and , and check the gap against the variance.Show answer
, so . The outcomes give and , so . The gap is . The variance is , so the gap is exactly the variance, as it is for in general.
QuestionA colleague estimates the expected value of by computing from the sample mean . Is that estimate too high or too low, and why?Show answer
Too low. The function is convex on positive numbers, so Jensen gives . Plugging the sample mean into therefore underestimates on average. A better estimate averages over the samples directly.
QuestionYou are fitting a model whose loss is a log of a sum over latent variables, and you want a tractable lower bound on the log likelihood. Explain where Jensen's inequality enters and why the bound is valid for any choice of the auxiliary distribution.Show answer
Writing the log of a sum as the log of an expectation under makes the function act on an average. Because is concave, Jensen says the log of the average is at least the average of the log. That gives a lower bound that depends on only through the expectation. Since the inequality holds for every , any choice gives a valid bound, and you then choose to make the bound as tight as possible.
Sources
- Jensen's inequality (Wikipedia): https://en.wikipedia.org/wiki/Jensen%27s_inequality
- Convex function (Wikipedia): https://en.wikipedia.org/wiki/Convex_function
- Cover and Thomas, Elements of Information Theory, Chapter 2: https://www.wiley.com/en-us/Elements+of+Information+Theory%2C+2nd+Edition-p-9780471241959