Module 4. Jensen's inequality: when averaging meets nonlinearity
Try each exercise first. Expand worked answers or project guidance when needed; their open state is shared between RU/EN.
Download course files (.zip) 33.9 KBThe archive preserves the folder structure of nine Python solution files shared by RU/EN.
Exercise 1. See the Jensen gap
Let take values and , each with probability .
-
For , compute and .
-
Show that their difference equals .
-
Repeat the calculation for .
-
Explain why both inequalities are strict.
Show answer and solution
Let
Then
1. The square
For ,
while
Hence
2. Relation to variance
By definition,
Thus the Jensen gap for is exactly the variance.
3. The exponential
For ,
whereas
The gap is approximately
4. Why both inequalities are strict
Both on and are strictly convex. Since is not almost surely constant, equality in Jensen is impossible.
Exercise 2. Two ways to build an ensemble
Two models predict
and the observed class is the first one.
-
Compute the average NLL of the members.
-
Compute the NLL of the arithmetic probability mixture.
-
Construct the normalized geometric mean and compute its NLL.
-
Verify both Jensen inequalities.
-
Explain why the result does not imply higher top-1 accuracy on a dataset.
Show answer and solution
We have
equal weights, and target class .
1. Average member NLL
Therefore
2. Arithmetic probability mixture
For the target class,
so
3. Normalized geometric mean
The unnormalized weights are
Thus
After normalization,
Its NLL is
again below the average member NLL:
4. What has been verified
For probability averaging, Jensen is applied to :
For logit averaging, we use convexity of softmax cross-entropy in the logits.
5. Why dataset accuracy does not follow
The inequalities concern NLL of the observed class. Accuracy depends only on whether the argmax equals the label, while NLL uses the entire assigned probability. An ensemble may improve NLL without changing accuracy, and it may move some argmax decisions in either direction.
Exercise 3. The ELBO in a Gaussian model
Let
and suppose is observed.
-
Find the marginal distribution .
-
Find the exact posterior .
-
For , compute
-
Use the exact gap to obtain the ELBO.
-
State which choice of makes the bound tight.
Show answer and solution
The model is
1. Marginal distribution
Write
with independent and . Hence
At ,
2. Exact posterior
The posterior precision is
so its variance is . Its mean is
Therefore
3. KL for
For univariate Gaussians,
Substituting
gives
4. ELBO
Using the exact gap,
Therefore
5. Tightness
Choose
Then the KL gap is zero.
Exercise 4. Log-sum and coarse-graining
For
merge the outcomes into groups and .
-
Compute .
-
Compute the KL divergence between the grouped distributions.
-
Show how the inequality follows from two applications of log-sum.
-
State the equality condition in terms of the conditional distributions within each group.
Show answer and solution
1. KL before grouping
2. KL after grouping
The grouped distributions are
Thus
Hence
3. Two log-sum applications
For the first group,
For the second,
Adding the inequalities proves the result.
4. Equality condition
Within each group, the conditional distributions under and must match:
for every relevant .
Thus, once the group is known, the finer state must provide no additional ability to distinguish from .
Bonus. The Jensen gap as a Bregman divergence
Prove that, for differentiable convex ,
Check the identity for .
Show answer and solution
Let
By definition,
Taking expectations,
Since ,
For ,
Therefore
which matches the Jensen gap for .