Jensen's Inequality

The average of a curve is not the curve of the average. The gap has a direction, a size, and a great many consequences.

Jensen's Inequality

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

For a convex f: E[f(X)] ≥ f(E[X]). For concave, the inequality reverses.
Geometrically it is the chord lying above the curve — the same picture as convexity itself.
The gap grows with the spread of X and with the curvature of f. It is zero only if one of them is zero.
It is the reason a log-likelihood can be bounded from below, which is the reason EM and variational inference work at all.

Overview

The inequality

If f is convex and X has a finite expectation, Jensen’s inequality states:

f(E[X]) ≤ E[f(X)]

For f(x) = x², this says (E[X])² ≤ E[X²]. The difference is Var(X) ≥ 0. Equality holds when X is constant with probability one, or more generally when f is affine over the values X can take.

In this guide
  1. Why averages can mislead
  2. Check the function, domain, and equality case
  3. Try this above
  4. Sources and next steps

Jensen’s Inequality

For a convex function, the function of an average is no greater than the average of the function values.

Why averages can mislead

A convex penalty makes large deviations count disproportionately: applying the penalty after averaging is smaller than averaging the penalties. For concave functions the inequality reverses. This is useful in probability, statistics, and machine learning, but first check that the function is convex on the relevant domain and that the expectations exist.

For example, because log(x) is concave on x > 0, E[log X] ≤ log(E[X]). It is not valid to switch these expressions freely. See expectation and variance and convexity.

Check the function, domain, and equality case

A function is convex if its graph bends upward, or equivalently if every chord lies on or above the graph. For a differentiable function, its tangent line lies below the graph. Jensen applies this shape property to a weighted average: if X takes x₁,…,xₙ with probabilities pᵢ, then f(Σpᵢxᵢ)≤Σpᵢf(xᵢ). The probabilities must be nonnegative and sum to one, and the relevant expectations must exist.

For values 1 and 3 with equal probability and f(x)=x², f(E[X])=f(2)=4, while E[f(X)]=(1+9)/2=5. The gap is the variance, 1. If f is concave, such as log(x) on positive inputs, the inequality reverses. Equality occurs when the function is affine over the values with positive probability; it need not require X to be constant. Jensen is useful for bounding expectations, but it does not allow you to move a nonlinear function through an average without checking convexity and domain.

Try this above

Compare f at the mean with the mean of f-values as the spread changes. For a convex curve, the latter should stay at least as large.

For a random variable with finitely many outcomes, the inequality is a weighted average with weights P(X=xᵢ); it is not limited to equally likely cases. For example, if X=0 with probability 0.75 and X=4 with probability 0.25, then E[X]=1. With f(x)=x², f(E[X])=1 while E[f(X)]=4. The larger outcome has a disproportionate effect after squaring. This is the same mechanism behind variance penalties and why averaging losses before applying a nonlinear transformation can change the result.

Jensen also gives a useful relationship between arithmetic and geometric means. Since log is concave, E[log X]≤log(E[X]) for positive X. Exponentiating yields the geometric mean no greater than the arithmetic mean under the corresponding equal-weight setup. This does not say one is a better summary in every setting: the geometric mean is natural for multiplicative growth rates, while the arithmetic mean is natural for additive totals. Choosing the scale and function reflects the process being described.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. For a convex f, which is larger?

  2. When is the gap exactly zero?

  3. How does Jensen make variational inference possible?

Cheat sheet

Jensen's Inequality

Apply a convex function before and after averaging and see why the results differ. Trace how this gap appears in KL divergence and the ELBO.

MATHS · vizlearn.in/maths/jensens_inequality.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.