Practice / Probability for ML

Jensen's inequality and convexity

Ten problems on convex functions and Jensen's inequality: the second-derivative test, the tangent-line proof of Jensen, the finite version by induction, AM–GM, the Jensen gaps behind the variance and the Gaussian moment generating function, why the ELBO is a lower bound and why averaging importance weights tightens it, the log-sum-exp bounds and its PSD Hessian, convexity-preserving operations applied to the logistic and hinge losses, the entropy ceiling and Gibbs' inequality, and the ambiguity decomposition for ensembles, with worked solutions and the mistakes that compose convex functions, apply Jensen to a plain sum, swap E[1/X] for 1/E[X], call log-sum-exp strictly convex, or test convexity at one point.

Before you start

One inequality sits under more of machine learning than any other: for a convex function, the function of an average is at most the average of the function. It is why the variance is nonnegative, why the KL divergence is nonnegative, why the evidence lower bound is a lower bound, why log-sum-exp is a smooth maximum, and why an ensemble's average prediction loses no more than its members do on average. These ten problems build it from the second-derivative test and the tangent line, prove the finite version from the definition alone, and then spend it: on the AM–GM inequality, on the moment generating function of a Gaussian, on the ELBO and the importance-weighted bound that tightens it, on the softmax Hessian, on the convexity of the logistic and hinge losses, on the entropy ceiling, and on the ambiguity decomposition. The five mistakes at the end are the ones that produce a true-looking inequality that is false: composing convex functions, applying Jensen to a sum instead of an average, replacing the mean of a reciprocal by the reciprocal of the mean, calling a flat direction strictly convex, and reading convexity off a single point.

  • A function ff on an interval II is convex if f(λx+(1−λ)y)≤λf(x)+(1−λ)f(y)f(\lambda x + (1 - \lambda)y) \le \lambda f(x) + (1 - \lambda)f(y) for all x,y∈Ix, y \in I and λ∈[0,1]\lambda \in [0, 1]: the chord between two points of the graph lies on or above the graph. It is strictly convex if the inequality is strict whenever x≠yx \neq y and 0<λ<10 < \lambda < 1, and concave if −f-f is convex. The same definition applies to ff on Rn\mathbb{R}^n with vectors x,yx, y.
  • Jensen's inequality: for a convex ff and a random variable XX with finite mean, f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]; for concave ff the inequality reverses. For a finite distribution with weights pi≥0p_i \ge 0, ∑ipi=1\sum_i p_i = 1, it reads f(∑ipixi)≤∑ipif(xi)f\big(\sum_i p_i x_i\big) \le \sum_i p_i f(x_i). The difference E[f(X)]−f(E[X])\mathbb{E}[f(X)] - f(\mathbb{E}[X]) is the Jensen gap.
  • log⁡\log is the natural logarithm. σ(t)=1/(1+e−t)\sigma(t) = 1/(1 + e^{-t}) is the logistic sigmoid with σ′=σ(1−σ)\sigma' = \sigma(1 - \sigma), and the softplus is sp⁡(t)=log⁡(1+et)\operatorname{sp}(t) = \log(1 + e^t), with sp⁡′=σ\operatorname{sp}' = \sigma (the activation-functions page).
  • For z∈Rnz \in \mathbb{R}^n, LSE⁡(z)=log⁡∑iezi\operatorname{LSE}(z) = \log\sum_i e^{z_i} is the log-sum-exp and s=softmax⁡(z)s = \operatorname{softmax}(z) has si=ezi/∑jezjs_i = e^{z_i}/\sum_j e^{z_j}; 1\mathbf{1} is the all-ones vector and diag⁡(s)\operatorname{diag}(s) the diagonal matrix with ss on its diagonal. A symmetric matrix HH is positive semidefinite (PSD) if v⊤Hv≥0v^\top Hv \ge 0 for every vv, and a twice-differentiable ff on Rn\mathbb{R}^n is convex exactly when its Hessian ∇2f\nabla^2 f is PSD everywhere (the gradients-and-Hessians page).
  • pp and qq are distributions over KK outcomes with pi,qi>0p_i, q_i > 0; the entropy is H(p)=−∑ipilog⁡piH(p) = -\sum_i p_i\log p_i and KL⁡(p ∥ q)=∑ipilog⁡(pi/qi)\operatorname{KL}(p\,\|\,q) = \sum_i p_i\log(p_i/q_i) (the entropy page). For a latent-variable model, p(x,z)p(x, z) is the joint, p(x)=∑zp(x,z)p(x) = \sum_z p(x, z) the evidence, q(z)q(z) a distribution the model chooses, and w(z)=p(x,z)/q(z)w(z) = p(x, z)/q(z) the importance weight.

Builds on: Entropy, cross-entropy and KL divergence, Variance, covariance and correlation

Problems

  1. ·

    Using the second derivative, decide which of exe^x, −log⁡x-\log x, xlog⁡xx\log x and x\sqrt{x} are convex and which are concave on x>0x > 0.

  2. ··

    Let ff be twice differentiable with f′′≥0f'' \ge 0 on an interval. Show that the tangent line lies below the graph, f(y)≥f(x)+f′(x)(y−x)f(y) \ge f(x) + f'(x)(y - x), and deduce Jensen's inequality f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)] for any random variable XX taking values in the interval with finite mean.

  3. ··

    Without derivatives, show from the definition of convexity that f(∑i=1npixi)≤∑i=1npif(xi)f\big(\sum_{i=1}^n p_i x_i\big) \le \sum_{i=1}^n p_i f(x_i) for weights pi≥0p_i \ge 0 with ∑ipi=1\sum_i p_i = 1, by induction on nn. Why does this version apply to f(x)=∣x∣f(x) = \lvert x\rvert, which has no second derivative?

  4. ··

    From Jensen's inequality for log⁡\log, prove the weighted AM–GM inequality ∏iaipi≤∑ipiai\prod_i a_i^{p_i} \le \sum_i p_ia_i for ai>0a_i > 0 and weights pi≥0p_i \ge 0, ∑ipi=1\sum_i p_i = 1. Evaluate both sides for a=(1,4)a = (1, 4) with equal weights and for a=(1,2,4)a = (1, 2, 4) with equal weights.

  5. ··

    Show that each of the following is a Jensen gap and compute it: (a) E[X2]−(E[X])2\mathbb{E}[X^2] - (\mathbb{E}[X])^2 for any XX with finite variance; (b) E[eX]−eE[X]\mathbb{E}[e^X] - e^{\mathbb{E}[X]} for X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2), by first showing E[eX]=eμ+σ2/2\mathbb{E}[e^X] = e^{\mu + \sigma^2/2}; (c) E[1/X]−1/E[X]\mathbb{E}[1/X] - 1/\mathbb{E}[X] for XX equal to 11 or 44 with probability 12\tfrac12 each.

  6. ···

    For a latent-variable model with z∼qz \sim q and w(z)=p(x,z)/q(z)w(z) = p(x, z)/q(z), show that log⁡p(x)≥Eq[log⁡w(z)]\log p(x) \ge \mathbb{E}_q[\log w(z)], the evidence lower bound. Then, for KK independent draws z1,…,zK∼qz_1, \dots, z_K \sim q, show that log⁡p(x)≥E[log⁡1K∑k=1Kw(zk)]≥Eq[log⁡w(z)]\log p(x) \ge \mathbb{E}\Big[\log\dfrac1K\sum_{k=1}^K w(z_k)\Big] \ge \mathbb{E}_q[\log w(z)]: averaging the weights inside the log tightens the bound.

  7. ···

    For LSE⁡(z)=log⁡∑i=1nezi\operatorname{LSE}(z) = \log\sum_{i=1}^n e^{z_i}, show that max⁡izi≤LSE⁡(z)≤max⁡izi+log⁡n\max_i z_i \le \operatorname{LSE}(z) \le \max_i z_i + \log n, that ∇LSE⁡(z)=s=softmax⁡(z)\nabla\operatorname{LSE}(z) = s = \operatorname{softmax}(z), and that ∇2LSE⁡(z)=diag⁡(s)−ss⊤\nabla^2\operatorname{LSE}(z) = \operatorname{diag}(s) - ss^\top is PSD, so LSE⁡\operatorname{LSE} is convex.

  8. ··

    Show from the definition that (a) if ff is convex then g(x)=f(Ax+b)g(x) = f(Ax + b) is convex, and (b) if f1,…,fmf_1, \dots, f_m are convex then g(x)=max⁡jfj(x)g(x) = \max_j f_j(x) is convex. Use (a) to show that the logistic loss ℓ(w)=log⁡(1+e−y w⊤x)\ell(w) = \log\big(1 + e^{-y\,w^\top x}\big) is convex in ww for fixed x∈Rdx \in \mathbb{R}^d and y∈{−1,+1}y \in \{-1, +1\}, and compute its Hessian. Use (b) for the hinge loss h(w)=max⁡(0,1−y w⊤x)h(w) = \max(0, 1 - y\,w^\top x).

  9. ··

    Use Jensen's inequality to show that (a) H(p)≤log⁡KH(p) \le \log K for every distribution pp over KK outcomes, with equality for the uniform distribution, and (b) KL⁡(p ∥ q)≥0\operatorname{KL}(p\,\|\,q) \ge 0.

  10. ···

    An ensemble of MM models makes predictions y^1,…,y^M\hat y_1, \dots, \hat y_M for a target yy, and the ensemble predicts the average yˉ=1M∑my^m\bar y = \tfrac1M\sum_m\hat y_m. (a) Show that for any loss ℓ(y^,y)\ell(\hat y, y) that is convex in y^\hat y, ℓ(yˉ,y)≤1M∑mℓ(y^m,y)\ell(\bar y, y) \le \tfrac1M\sum_m\ell(\hat y_m, y). (b) For the squared loss, show the exact identity (yˉ−y)2=1M∑m(y^m−y)2−1M∑m(y^m−yˉ)2(\bar y - y)^2 = \tfrac1M\sum_m(\hat y_m - y)^2 - \tfrac1M\sum_m(\hat y_m - \bar y)^2.

Worked solutions

Problem 1

Using the second derivative, decide which of exe^x, −log⁡x-\log x, xlog⁡xx\log x and x\sqrt{x} are convex and which are concave on x>0x > 0.

  1. (ex)′′=ex>0(e^x)'' = e^x > 0.Differentiate twice; the exponential is its own derivative and is positive everywhere.
  2. (−log⁡x)′′=(−1/x)′=1/x2>0(-\log x)'' = (-1/x)' = 1/x^2 > 0.The derivative of −log⁡x-\log x is −1/x-1/x, and the derivative of −x−1-x^{-1} is x−2x^{-2}.
  3. (xlog⁡x)′′=(log⁡x+1)′=1/x>0(x\log x)'' = (\log x + 1)' = 1/x > 0.Product rule for the first derivative: 1⋅log⁡x+x⋅1x=log⁡x+11\cdot\log x + x\cdot\tfrac1x = \log x + 1.
  4. (x)′′=(12x−1/2)′=−14x−3/2<0(\sqrt{x})'' = \big(\tfrac12 x^{-1/2}\big)' = -\tfrac14 x^{-3/2} < 0.Power rule twice; the second derivative is negative for every x>0x > 0.
  5. exe^x, −log⁡x-\log x and xlog⁡xx\log x are convex on x>0x > 0 (second derivatives exe^x, 1/x21/x^2, 1/x1/x); x\sqrt{x} and log⁡x\log x are concave (second derivatives −14x−3/2-\tfrac14x^{-3/2} and −1/x2-1/x^2)A nonnegative second derivative on an interval means the slope never decreases, so the graph bends upwards and every chord lies above it; Problem 2 makes that precise through the tangent line. The same test in several variables asks whether the Hessian is PSD (Problem 7). Concavity of log⁡\log is the fact behind Problems 4, 6 and 9, and convexity of xlog⁡xx\log x is the fact behind the entropy being concave.

Problem 2

Let ff be twice differentiable with f′′≥0f'' \ge 0 on an interval. Show that the tangent line lies below the graph, f(y)≥f(x)+f′(x)(y−x)f(y) \ge f(x) + f'(x)(y - x), and deduce Jensen's inequality f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)] for any random variable XX taking values in the interval with finite mean.

  1. f(y)=f(x)+f′(x)(y−x)+12f′′(ξ)(y−x)2f(y) = f(x) + f'(x)(y - x) + \tfrac12 f''(\xi)(y - x)^2 for some ξ\xi between xx and yy.Taylor's theorem with the Lagrange remainder at order one (the Taylor-series page).
  2. 12f′′(ξ)(y−x)2≥0\tfrac12 f''(\xi)(y - x)^2 \ge 0, so f(y)≥f(x)+f′(x)(y−x)f(y) \ge f(x) + f'(x)(y - x).f′′≥0f'' \ge 0 on the interval and a square is nonnegative.
  3. Put x=μ=E[X]x = \mu = \mathbb{E}[X] and y=Xy = X: f(X)≥f(μ)+f′(μ)(X−μ)f(X) \ge f(\mu) + f'(\mu)(X - \mu) for every value of XX.Step 2 holds for every pair of points in the interval, and μ\mu lies in the interval because it is an average of values in it.
  4. E[f(X)]≥f(μ)+f′(μ) E[X−μ]=f(μ)+f′(μ)⋅0\mathbb{E}[f(X)] \ge f(\mu) + f'(\mu)\,\mathbb{E}[X - \mu] = f(\mu) + f'(\mu)\cdot 0.Expectation preserves inequalities and is linear; f(μ)f(\mu) and f′(μ)f'(\mu) are constants, and E[X−μ]=μ−μ=0\mathbb{E}[X - \mu] = \mu - \mu = 0.
  5. f(y)≥f(x)+f′(x)(y−x)f(y) \ge f(x) + f'(x)(y - x), and f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]The whole of Jensen is the supporting line at the mean: the graph sits above its tangent there, and the tangent's expectation is exactly f(μ)f(\mu) because the linear term averages to zero. The argument never used what the distribution of XX is, so it covers sums, integrals and anything in between. If f′′>0f'' > 0 strictly, step 1's remainder is zero only when y=xy = x, so the gap is zero only when X=μX = \mu with probability one: equality in Jensen for a strictly convex ff means XX is constant, which is what pins the ELBO's equality case to the posterior in Problem 6.

Problem 3

Without derivatives, show from the definition of convexity that f(∑i=1npixi)≤∑i=1npif(xi)f\big(\sum_{i=1}^n p_i x_i\big) \le \sum_{i=1}^n p_i f(x_i) for weights pi≥0p_i \ge 0 with ∑ipi=1\sum_i p_i = 1, by induction on nn. Why does this version apply to f(x)=∣x∣f(x) = \lvert x\rvert, which has no second derivative?

  1. n=1n = 1: p1=1p_1 = 1 and both sides are f(x1)f(x_1). n=2n = 2: f(p1x1+p2x2)≤p1f(x1)+p2f(x2)f(p_1x_1 + p_2x_2) \le p_1f(x_1) + p_2f(x_2) with p2=1−p1p_2 = 1 - p_1.The two-point case is the definition of convexity with λ=p1\lambda = p_1.
  2. Suppose the claim holds for n−1n - 1 points, and take nn points with pn<1p_n < 1. Write ∑i=1npixi=pnxn+(1−pn) xˉ\sum_{i=1}^n p_ix_i = p_nx_n + (1 - p_n)\,\bar x with xˉ=∑i=1n−1pi1−pnxi\bar x = \sum_{i=1}^{n-1}\dfrac{p_i}{1 - p_n}x_i.Factor 1−pn1 - p_n out of the first n−1n - 1 terms; the new weights pi/(1−pn)p_i/(1 - p_n) are nonnegative and sum to (1−pn)/(1−pn)=1(1 - p_n)/(1 - p_n) = 1, so xˉ\bar x is a convex combination of x1,…,xn−1x_1, \dots, x_{n-1}. If pn=1p_n = 1 there is nothing to prove.
  3. f(∑i=1npixi)=f(pnxn+(1−pn)xˉ)≤pnf(xn)+(1−pn)f(xˉ)f\Big(\sum_{i=1}^n p_ix_i\Big) = f\big(p_nx_n + (1 - p_n)\bar x\big) \le p_nf(x_n) + (1 - p_n)f(\bar x).The two-point case with λ=pn\lambda = p_n applied to the points xnx_n and xˉ\bar x.
  4. f(xˉ)≤∑i=1n−1pi1−pnf(xi)f(\bar x) \le \sum_{i=1}^{n-1}\dfrac{p_i}{1 - p_n}f(x_i), so (1−pn)f(xˉ)≤∑i=1n−1pif(xi)(1 - p_n)f(\bar x) \le \sum_{i=1}^{n-1}p_if(x_i).The induction hypothesis on the n−1n - 1 points with the new weights; multiply through by 1−pn>01 - p_n > 0.
  5. f(∑i=1npixi)≤∑i=1npif(xi)f\big(\sum_{i=1}^n p_ix_i\big) \le \sum_{i=1}^n p_if(x_i)Steps 3 and 4 together. Only the chord definition was used, so the result holds for every convex function, differentiable or not. ∣x∣\lvert x\rvert is convex because ∣λx+(1−λ)y∣≤λ∣x∣+(1−λ)∣y∣\lvert\lambda x + (1 - \lambda)y\rvert \le \lambda\lvert x\rvert + (1 - \lambda)\lvert y\rvert is the triangle inequality, so ∣E[X]∣≤E∣X∣\lvert\mathbb{E}[X]\rvert \le \mathbb{E}\lvert X\rvert for any finite distribution, and the same chord argument gives ∥E[X]∥≤E∥X∥\|\mathbb{E}[X]\| \le \mathbb{E}\|X\| for vectors. The induction fails if the weights do not sum to one, which is Mistake 2.

Problem 4

From Jensen's inequality for log⁡\log, prove the weighted AM–GM inequality ∏iaipi≤∑ipiai\prod_i a_i^{p_i} \le \sum_i p_ia_i for ai>0a_i > 0 and weights pi≥0p_i \ge 0, ∑ipi=1\sum_i p_i = 1. Evaluate both sides for a=(1,4)a = (1, 4) with equal weights and for a=(1,2,4)a = (1, 2, 4) with equal weights.

  1. log⁡\log is concave on x>0x > 0, so ∑ipilog⁡ai≤log⁡(∑ipiai)\sum_i p_i\log a_i \le \log\Big(\sum_i p_ia_i\Big).Problem 1 for the concavity; Problem 3's finite Jensen with the inequality reversed for a concave function.
  2. ∑ipilog⁡ai=log⁡∏iaipi\sum_i p_i\log a_i = \log\prod_i a_i^{p_i}.plog⁡a=log⁡app\log a = \log a^p and a sum of logs is the log of the product.
  3. log⁡∏iaipi≤log⁡∑ipiai\log\prod_i a_i^{p_i} \le \log\sum_i p_ia_i, so ∏iaipi≤∑ipiai\prod_i a_i^{p_i} \le \sum_i p_ia_i.exp⁡\exp is increasing, so it preserves the inequality.
  4. a=(1,4)a = (1, 4), p=(12,12)p = (\tfrac12, \tfrac12): 1⋅4=2≤12(1+4)=2.5\sqrt{1\cdot 4} = 2 \le \tfrac12(1 + 4) = 2.5.The geometric mean is 41/24^{1/2} and the arithmetic mean is 5/25/2.
  5. a=(1,2,4)a = (1, 2, 4), p=(13,13,13)p = (\tfrac13, \tfrac13, \tfrac13): (1⋅2⋅4)1/3=81/3=2≤13(1+2+4)=73(1\cdot 2\cdot 4)^{1/3} = 8^{1/3} = 2 \le \tfrac13(1 + 2 + 4) = \tfrac73.8=238 = 2^3.
  6. ∏iaipi≤∑ipiai\prod_i a_i^{p_i} \le \sum_i p_ia_i; for (1,4)(1, 4): 2≤2.52 \le 2.5; for (1,2,4)(1, 2, 4): 2≤7/32 \le 7/3Equality needs the aia_i all equal, because log⁡\log is strictly concave (Problem 2's equality case). With n=2n = 2 and equal weights the inequality is ab≤12(a+b)\sqrt{ab} \le \tfrac12(a + b), which is (a−b)2≥0(\sqrt a - \sqrt b)^2 \ge 0 rearranged. The same step from the mean of logs to the log of the mean is the one taken, in the other direction, in Problem 6.

Problem 5

Show that each of the following is a Jensen gap and compute it: (a) E[X2]−(E[X])2\mathbb{E}[X^2] - (\mathbb{E}[X])^2 for any XX with finite variance; (b) E[eX]−eE[X]\mathbb{E}[e^X] - e^{\mathbb{E}[X]} for X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2), by first showing E[eX]=eμ+σ2/2\mathbb{E}[e^X] = e^{\mu + \sigma^2/2}; (c) E[1/X]−1/E[X]\mathbb{E}[1/X] - 1/\mathbb{E}[X] for XX equal to 11 or 44 with probability 12\tfrac12 each.

  1. (a) x2x^2 is convex, so (E[X])2≤E[X2](\mathbb{E}[X])^2 \le \mathbb{E}[X^2], and the gap is E[X2]−(E[X])2=Var⁡(X)≥0\mathbb{E}[X^2] - (\mathbb{E}[X])^2 = \operatorname{Var}(X) \ge 0.(x2)′′=2>0(x^2)'' = 2 > 0; the variance page's Var⁡(X)=E[X2]−(E[X])2\operatorname{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}[X])^2.
  2. (b) Write X=μ+σεX = \mu + \sigma\varepsilon with ε∼N(0,1)\varepsilon \sim \mathcal{N}(0, 1): E[eX]=eμ E[eσε]\mathbb{E}[e^X] = e^\mu\,\mathbb{E}[e^{\sigma\varepsilon}].A Gaussian is a shifted and scaled standard normal; eμe^\mu is a constant.
  3. E[eσε]=12π∫eσε−ε2/2 dε=eσ2/212π∫e−(ε−σ)2/2 dε=eσ2/2\mathbb{E}[e^{\sigma\varepsilon}] = \dfrac{1}{\sqrt{2\pi}}\int e^{\sigma\varepsilon - \varepsilon^2/2}\,d\varepsilon = e^{\sigma^2/2}\dfrac{1}{\sqrt{2\pi}}\int e^{-(\varepsilon - \sigma)^2/2}\,d\varepsilon = e^{\sigma^2/2}.Complete the square: σε−12ε2=−12(ε−σ)2+12σ2\sigma\varepsilon - \tfrac12\varepsilon^2 = -\tfrac12(\varepsilon - \sigma)^2 + \tfrac12\sigma^2; the remaining integral is the density of N(σ,1)\mathcal{N}(\sigma, 1), which integrates to 11.
  4. E[eX]=eμ+σ2/2\mathbb{E}[e^X] = e^{\mu + \sigma^2/2}, and the gap is eμ+σ2/2−eμ=eμ(eσ2/2−1)>0e^{\mu + \sigma^2/2} - e^\mu = e^\mu\big(e^{\sigma^2/2} - 1\big) > 0.exe^x is convex (Problem 1) and E[X]=μ\mathbb{E}[X] = \mu; eσ2/2>1e^{\sigma^2/2} > 1 for σ>0\sigma > 0.
  5. (c) 1/x1/x is convex on x>0x > 0 since (1/x)′′=2/x3>0(1/x)'' = 2/x^3 > 0; E[1/X]=12(1+14)=58=0.625\mathbb{E}[1/X] = \tfrac12\big(1 + \tfrac14\big) = \tfrac58 = 0.625 and 1/E[X]=1/52=0.41/\mathbb{E}[X] = 1/\tfrac52 = 0.4.Each value has probability 12\tfrac12; E[X]=12(1+4)=52\mathbb{E}[X] = \tfrac12(1 + 4) = \tfrac52.
  6. (a) the gap is Var⁡(X)\operatorname{Var}(X); (b) E[eX]=eμ+σ2/2\mathbb{E}[e^X] = e^{\mu + \sigma^2/2} and the gap is eμ(eσ2/2−1)e^\mu(e^{\sigma^2/2} - 1); (c) E[1/X]=0.625>0.4=1/E[X]\mathbb{E}[1/X] = 0.625 > 0.4 = 1/\mathbb{E}[X], gap 0.2250.225Three faces of one inequality. (a) says the variance is a Jensen gap, and Problem 7 reuses it to prove a Hessian is PSD. (b) is the moment generating function of a Gaussian; it is why the mean of a log-normal variable is eμ+σ2/2e^{\mu + \sigma^2/2}, not eμe^\mu, and why exponentiating a predicted log-price under-estimates the expected price by the factor eσ2/2e^{\sigma^2/2}. (c) is the harmonic-mean gap: the expected reciprocal exceeds the reciprocal of the expectation, which is Mistake 3 when it is forgotten.

Problem 6

For a latent-variable model with z∼qz \sim q and w(z)=p(x,z)/q(z)w(z) = p(x, z)/q(z), show that log⁡p(x)≥Eq[log⁡w(z)]\log p(x) \ge \mathbb{E}_q[\log w(z)], the evidence lower bound. Then, for KK independent draws z1,…,zK∼qz_1, \dots, z_K \sim q, show that log⁡p(x)≥E[log⁡1K∑k=1Kw(zk)]≥Eq[log⁡w(z)]\log p(x) \ge \mathbb{E}\Big[\log\dfrac1K\sum_{k=1}^K w(z_k)\Big] \ge \mathbb{E}_q[\log w(z)]: averaging the weights inside the log tightens the bound.

  1. Eq[w(z)]=∑zq(z)p(x,z)q(z)=∑zp(x,z)=p(x)\mathbb{E}_q[w(z)] = \sum_z q(z)\dfrac{p(x, z)}{q(z)} = \sum_z p(x, z) = p(x).The q(z)q(z) cancels; summing the joint over zz gives the marginal.
  2. log⁡p(x)=log⁡Eq[w]≥Eq[log⁡w]\log p(x) = \log\mathbb{E}_q[w] \ge \mathbb{E}_q[\log w].Jensen for the concave log⁡\log (Problem 1), with the inequality reversed as for every concave function.
  3. Let wˉK=1K∑kw(zk)\bar w_K = \dfrac1K\sum_k w(z_k). Then E[wˉK]=p(x)\mathbb{E}[\bar w_K] = p(x), so log⁡p(x)=log⁡E[wˉK]≥E[log⁡wˉK]\log p(x) = \log\mathbb{E}[\bar w_K] \ge \mathbb{E}[\log\bar w_K].Each w(zk)w(z_k) has mean p(x)p(x) by step 1 and the mean of an average is the average of the means; then Jensen again on the random variable wˉK\bar w_K.
  4. log⁡wˉK=log⁡(1K∑kw(zk))≥1K∑klog⁡w(zk)\log\bar w_K = \log\Big(\dfrac1K\sum_k w(z_k)\Big) \ge \dfrac1K\sum_k\log w(z_k) for every draw.Problem 3's finite Jensen for the concave log⁡\log with equal weights 1/K1/K: the log of an average is at least the average of the logs.
  5. Taking expectations in step 4: E[log⁡wˉK]≥1K∑kE[log⁡w(zk)]=Eq[log⁡w(z)]\mathbb{E}[\log\bar w_K] \ge \dfrac1K\sum_k\mathbb{E}[\log w(z_k)] = \mathbb{E}_q[\log w(z)].Expectation preserves inequalities; the zkz_k are identically distributed, so each term has the same mean.
  6. log⁡p(x)≥E[log⁡1K∑kw(zk)]≥Eq[log⁡w(z)]\log p(x) \ge \mathbb{E}\big[\log\tfrac1K\sum_k w(z_k)\big] \ge \mathbb{E}_q[\log w(z)], the right-hand side being the ELBOThe ELBO is the K=1K = 1 case. Equality in step 2 needs ww constant under qq, which by Problem 2's equality case means q(z)=p(z∣x)q(z) = p(z \mid x); the ELBO page's Problem 2 computes the gap as KL⁡(q ∥ p(z∣x))\operatorname{KL}(q\,\|\,p(z \mid x)). The KK-sample bound is tighter because wˉK\bar w_K is less spread than a single ww (its variance is Var⁡q(w)/K\operatorname{Var}_q(w)/K), so its Jensen gap is smaller; as K→∞K \to \infty, wˉK→p(x)\bar w_K \to p(x) and the bound closes, whatever qq is. This is the importance-weighted bound, and the check verifies both inequalities on a model small enough to enumerate every pair of draws.

Problem 7

For LSE⁡(z)=log⁡∑i=1nezi\operatorname{LSE}(z) = \log\sum_{i=1}^n e^{z_i}, show that max⁡izi≤LSE⁡(z)≤max⁡izi+log⁡n\max_i z_i \le \operatorname{LSE}(z) \le \max_i z_i + \log n, that ∇LSE⁡(z)=s=softmax⁡(z)\nabla\operatorname{LSE}(z) = s = \operatorname{softmax}(z), and that ∇2LSE⁡(z)=diag⁡(s)−ss⊤\nabla^2\operatorname{LSE}(z) = \operatorname{diag}(s) - ss^\top is PSD, so LSE⁡\operatorname{LSE} is convex.

  1. Let m=max⁡izim = \max_i z_i. Then em≤∑iezi≤n eme^m \le \sum_i e^{z_i} \le n\,e^m.The sum contains the term eme^m and all terms are positive; each of the nn terms is at most eme^m.
  2. m≤LSE⁡(z)≤m+log⁡nm \le \operatorname{LSE}(z) \le m + \log n.Take logs of step 1, which preserves the order; log⁡(nem)=log⁡n+m\log(ne^m) = \log n + m.
  3. ∂LSE⁡∂zi=ezi∑jezj=si\dfrac{\partial\operatorname{LSE}}{\partial z_i} = \dfrac{e^{z_i}}{\sum_j e^{z_j}} = s_i.Chain rule: the derivative of log⁡u\log u is u′/uu'/u, and only the ii-th term of the sum depends on ziz_i.
  4. ∂si∂zj=si(δij−sj)\dfrac{\partial s_i}{\partial z_j} = s_i(\delta_{ij} - s_j), so ∇2LSE⁡=diag⁡(s)−ss⊤\nabla^2\operatorname{LSE} = \operatorname{diag}(s) - ss^\top.The softmax Jacobian from the softmax page; the Hessian is the Jacobian of the gradient.
  5. v⊤(diag⁡(s)−ss⊤)v=∑isivi2−(∑isivi)2=Es[V2]−(Es[V])2=Var⁡s(V)≥0v^\top(\operatorname{diag}(s) - ss^\top)v = \sum_i s_iv_i^2 - \Big(\sum_i s_iv_i\Big)^2 = \mathbb{E}_s[V^2] - (\mathbb{E}_s[V])^2 = \operatorname{Var}_s(V) \ge 0, where VV takes the value viv_i with probability sis_i.Expand the quadratic form; ss is a probability vector, so the two sums are the second moment and the squared mean of VV under ss, and their difference is a variance, which is Problem 5(a)'s Jensen gap.
  6. max⁡izi≤LSE⁡(z)≤max⁡izi+log⁡n\max_i z_i \le \operatorname{LSE}(z) \le \max_i z_i + \log n; ∇LSE⁡=softmax⁡(z)\nabla\operatorname{LSE} = \operatorname{softmax}(z); ∇2LSE⁡=diag⁡(s)−ss⊤\nabla^2\operatorname{LSE} = \operatorname{diag}(s) - ss^\top is PSD, so LSE⁡\operatorname{LSE} is convexLog-sum-exp is a smooth maximum, never below the true maximum and never more than log⁡n\log n above it, which is why cross-entropy with softmax, LSE⁡(z)−zy\operatorname{LSE}(z) - z_y, is a convex function of the logits: a convex function minus a linear one. The PSD proof is Jensen's gap in disguise, and the bound of step 2 is tight at both ends: z=(c,−∞,… )z = (c, -\infty, \dots) gives mm and z=c1z = c\mathbf{1} gives m+log⁡nm + \log n. The Hessian is only semidefinite: v=1v = \mathbf{1} gives Var⁡s(V)=0\operatorname{Var}_s(V) = 0, which Mistake 4 overlooks.

Problem 8

Show from the definition that (a) if ff is convex then g(x)=f(Ax+b)g(x) = f(Ax + b) is convex, and (b) if f1,…,fmf_1, \dots, f_m are convex then g(x)=max⁡jfj(x)g(x) = \max_j f_j(x) is convex. Use (a) to show that the logistic loss ℓ(w)=log⁡(1+e−y w⊤x)\ell(w) = \log\big(1 + e^{-y\,w^\top x}\big) is convex in ww for fixed x∈Rdx \in \mathbb{R}^d and y∈{−1,+1}y \in \{-1, +1\}, and compute its Hessian. Use (b) for the hinge loss h(w)=max⁡(0,1−y w⊤x)h(w) = \max(0, 1 - y\,w^\top x).

  1. (a) g(λu+(1−λ)v)=f(A(λu+(1−λ)v)+b)=f(λ(Au+b)+(1−λ)(Av+b))g(\lambda u + (1 - \lambda)v) = f\big(A(\lambda u + (1 - \lambda)v) + b\big) = f\big(\lambda(Au + b) + (1 - \lambda)(Av + b)\big).An affine map sends a convex combination of points to the same convex combination of their images: λb+(1−λ)b=b\lambda b + (1 - \lambda)b = b.
  2. ≤λf(Au+b)+(1−λ)f(Av+b)=λg(u)+(1−λ)g(v)\le \lambda f(Au + b) + (1 - \lambda)f(Av + b) = \lambda g(u) + (1 - \lambda)g(v).Convexity of ff at the points Au+bAu + b and Av+bAv + b.
  3. (b) fj(λu+(1−λ)v)≤λfj(u)+(1−λ)fj(v)≤λg(u)+(1−λ)g(v)f_j(\lambda u + (1 - \lambda)v) \le \lambda f_j(u) + (1 - \lambda)f_j(v) \le \lambda g(u) + (1 - \lambda)g(v) for every jj, so the maximum over jj of the left side, g(λu+(1−λ)v)g(\lambda u + (1 - \lambda)v), obeys the same bound.Convexity of each fjf_j, then fj≤gf_j \le g pointwise; a bound that holds for every jj holds for the largest.
  4. ℓ(w)=sp⁡(t)\ell(w) = \operatorname{sp}(t) with t=−y w⊤xt = -y\,w^\top x, and sp⁡′′(t)=σ′(t)=σ(t)(1−σ(t))>0\operatorname{sp}''(t) = \sigma'(t) = \sigma(t)(1 - \sigma(t)) > 0, so sp⁡\operatorname{sp} is convex and ℓ\ell is sp⁡\operatorname{sp} composed with the affine map w↦−y x⊤ww \mapsto -y\,x^\top w: convex by (a).sp⁡′=σ\operatorname{sp}' = \sigma (the activation-functions page); σ∈(0,1)\sigma \in (0, 1) makes the product positive; (a) with A=−y x⊤A = -y\,x^\top (1×d1 \times d) and b=0b = 0.
  5. ∇wℓ=σ(t) (−y x)\nabla_w\ell = \sigma(t)\,(-y\,x) and ∇w2ℓ=σ(t)(1−σ(t)) xx⊤\nabla_w^2\ell = \sigma(t)(1 - \sigma(t))\,x x^\top.Chain rule through tt: ∂t/∂w=−y x\partial t/\partial w = -y\,x, and y2=1y^2 = 1 in the second derivative. xx⊤xx^\top is PSD since v⊤xx⊤v=(x⊤v)2≥0v^\top xx^\top v = (x^\top v)^2 \ge 0, in agreement with (a).
  6. h(w)=max⁡(f1,f2)h(w) = \max(f_1, f_2) with f1(w)=0f_1(w) = 0 and f2(w)=1−y w⊤xf_2(w) = 1 - y\,w^\top x, both affine, hence convex; so hh is convex by (b).An affine function satisfies the chord inequality with equality.
  7. f(Ax+b)f(Ax + b) and max⁡jfj(x)\max_j f_j(x) are convex when ff, fjf_j are; ℓ(w)=sp⁡(−y w⊤x)\ell(w) = \operatorname{sp}(-y\,w^\top x) is convex with ∇2ℓ=σ(1−σ) xx⊤\nabla^2\ell = \sigma(1 - \sigma)\,xx^\top, σ=σ(−y w⊤x)\sigma = \sigma(-y\,w^\top x); the hinge loss is a maximum of two affine functions, hence convexThese two rules, with nonnegative sums (a sum of convex functions is convex because the chord inequalities add), build almost every convex loss in machine learning from a few one-dimensional pieces: the logistic loss is softplus after an affine map, the hinge loss and ReLU are maxima of affine maps, the squared loss is u2u^2 after an affine map, and a mean over a dataset is a nonnegative sum. What the rules do not include is composition of two convex functions (Mistake 1) or products.

Problem 9

Use Jensen's inequality to show that (a) H(p)≤log⁡KH(p) \le \log K for every distribution pp over KK outcomes, with equality for the uniform distribution, and (b) KL⁡(p ∥ q)≥0\operatorname{KL}(p\,\|\,q) \ge 0.

  1. (a) H(p)=∑ipilog⁡1pi=Ep[log⁡1pI]H(p) = \sum_i p_i\log\dfrac{1}{p_i} = \mathbb{E}_p\Big[\log\dfrac1{p_I}\Big], where II is an outcome drawn from pp.−log⁡pi=log⁡(1/pi)-\log p_i = \log(1/p_i); a pp-weighted sum is an expectation under pp.
  2. Ep[log⁡1pI]≤log⁡Ep[1pI]=log⁡∑ipi⋅1pi=log⁡K\mathbb{E}_p\Big[\log\dfrac1{p_I}\Big] \le \log\mathbb{E}_p\Big[\dfrac1{p_I}\Big] = \log\sum_i p_i\cdot\dfrac1{p_i} = \log K.Jensen for the concave log⁡\log; the expectation of 1/pI1/p_I is a sum of KK ones.
  3. For pi=1/Kp_i = 1/K: H(p)=∑i1Klog⁡K=log⁡KH(p) = \sum_i\tfrac1K\log K = \log K.Direct evaluation; 1/pI1/p_I is the constant KK, so there is no Jensen gap.
  4. (b) KL⁡(p ∥ q)=∑ipilog⁡piqi=−Ep[log⁡qIpI]\operatorname{KL}(p\,\|\,q) = \sum_i p_i\log\dfrac{p_i}{q_i} = -\mathbb{E}_p\Big[\log\dfrac{q_I}{p_I}\Big].Flip the fraction and pull out the sign: log⁡(p/q)=−log⁡(q/p)\log(p/q) = -\log(q/p).
  5. −Ep[log⁡qIpI]≥−log⁡Ep[qIpI]=−log⁡∑ipiqipi=−log⁡∑iqi=−log⁡1=0-\mathbb{E}_p\Big[\log\dfrac{q_I}{p_I}\Big] \ge -\log\mathbb{E}_p\Big[\dfrac{q_I}{p_I}\Big] = -\log\sum_i p_i\dfrac{q_i}{p_i} = -\log\sum_i q_i = -\log 1 = 0.Jensen for the concave log⁡\log, multiplied by −1-1, which flips ≤\le to ≥\ge; the pip_i cancel and qq sums to one.
  6. H(p)≤log⁡KH(p) \le \log K with equality for the uniform distribution; KL⁡(p ∥ q)≥0\operatorname{KL}(p\,\|\,q) \ge 0Both are Jensen on log⁡\log with a cleverly chosen random variable, 1/pI1/p_I and qI/pIq_I/p_I, whose expectations under pp are known constants, KK and 11. Equality in (b) needs qI/pIq_I/p_I constant, and a constant ratio between two distributions is 11, so q=pq = p: Gibbs' inequality, which the entropy page proves instead from log⁡t≤t−1\log t \le t - 1, the tangent line of log⁡\log at t=1t = 1, which is Problem 2's supporting line at the point where E[qI/pI]\mathbb{E}[q_I/p_I] sits.

Problem 10

An ensemble of MM models makes predictions y^1,…,y^M\hat y_1, \dots, \hat y_M for a target yy, and the ensemble predicts the average yˉ=1M∑my^m\bar y = \tfrac1M\sum_m\hat y_m. (a) Show that for any loss ℓ(y^,y)\ell(\hat y, y) that is convex in y^\hat y, ℓ(yˉ,y)≤1M∑mℓ(y^m,y)\ell(\bar y, y) \le \tfrac1M\sum_m\ell(\hat y_m, y). (b) For the squared loss, show the exact identity (yˉ−y)2=1M∑m(y^m−y)2−1M∑m(y^m−yˉ)2(\bar y - y)^2 = \tfrac1M\sum_m(\hat y_m - y)^2 - \tfrac1M\sum_m(\hat y_m - \bar y)^2.

  1. (a) ℓ(yˉ,y)=ℓ(∑m1My^m, y)≤∑m1M ℓ(y^m,y)\ell(\bar y, y) = \ell\Big(\sum_m\tfrac1M\hat y_m,\,y\Big) \le \sum_m\tfrac1M\,\ell(\hat y_m, y).Problem 3's finite Jensen with equal weights 1/M1/M, applied to ℓ(⋅,y)\ell(\cdot, y) with yy held fixed.
  2. (b) y^m−y=(y^m−yˉ)+(yˉ−y)\hat y_m - y = (\hat y_m - \bar y) + (\bar y - y), so (y^m−y)2=(y^m−yˉ)2+2(y^m−yˉ)(yˉ−y)+(yˉ−y)2(\hat y_m - y)^2 = (\hat y_m - \bar y)^2 + 2(\hat y_m - \bar y)(\bar y - y) + (\bar y - y)^2.Add and subtract yˉ\bar y, then expand the square.
  3. 1M∑m(y^m−y)2=1M∑m(y^m−yˉ)2+2(yˉ−y)⋅1M∑m(y^m−yˉ)+(yˉ−y)2\tfrac1M\sum_m(\hat y_m - y)^2 = \tfrac1M\sum_m(\hat y_m - \bar y)^2 + 2(\bar y - y)\cdot\tfrac1M\sum_m(\hat y_m - \bar y) + (\bar y - y)^2.Average step 2 over mm; (yˉ−y)(\bar y - y) does not depend on mm.
  4. 1M∑m(y^m−yˉ)=yˉ−yˉ=0\tfrac1M\sum_m(\hat y_m - \bar y) = \bar y - \bar y = 0, so the cross term vanishes.The deviations from a mean sum to zero.
  5. ℓ(yˉ,y)≤1M∑mℓ(y^m,y)\ell(\bar y, y) \le \tfrac1M\sum_m\ell(\hat y_m, y) for convex ℓ\ell; for the squared loss, (yˉ−y)2=1M∑m(y^m−y)2−1M∑m(y^m−yˉ)2(\bar y - y)^2 = \tfrac1M\sum_m(\hat y_m - y)^2 - \tfrac1M\sum_m(\hat y_m - \bar y)^2The ensemble's error is the members' average error minus the members' spread, the ambiguity decomposition: averaging can only help, and it helps most when the members disagree. (b) is Problem 5(a) applied across models, with the spread term the variance of the predictions, so the Jensen gap for the squared loss is exactly that variance. For the log loss −log⁡p^y-\log\hat p_y with probabilities, (a) says the averaged probability scores at least as well on average as its members; the inequality is strict unless all members agree. This is the inequality behind bagging and model averaging, and it says nothing about any single member, which may be better than the ensemble; the bias–variance page quantifies how much averaging reduces variance.

Where this goes wrong

1. Composing two convex functions

Convexity survives affine maps inside and nonnegative sums and maxima outside, and the natural next guess is that it survives any composition.

  1. g(x)=x2−1g(x) = x^2 - 1 and f(u)=u2f(u) = u^2 are both convexRight so far: both have positive second derivatives.
  2. “A convex function of a convex function is convex.”The rule that causes the mistake: Problem 8(a) allows an affine inner function, not a convex one.
  3. f(g(x))=(x2−1)2f(g(x)) = (x^2 - 1)^2 is convexIts second derivative is 12x2−412x^2 - 4, negative on ∣x∣<1/3\lvert x\rvert < 1/\sqrt3, and it has two minima at x=±1x = \pm 1 with a local maximum at 00: the chord from x=−1x = -1 to x=1x = 1 runs along 00 while the graph rises to 11 between them. Composition preserves convexity only when the outer function is also nondecreasing, which u2u^2 is not on u<0u < 0; that is why sp⁡(affine)\operatorname{sp}(\text{affine}) in Problem 8 is safe (the inner map is affine) and why σ(w⊤x)\sigma(w^\top x) is not convex (sigmoid is neither convex nor monotone-convex), so the squared error of a logistic unit is not a convex function of ww.

2. Jensen applied to a sum instead of an average

The finite inequality says ff of a combination is at most the combination of ff, and the weights are easy to forget.

  1. f(∑ipixi)≤∑ipif(xi)f\big(\sum_i p_ix_i\big) \le \sum_i p_if(x_i) for pi≥0p_i \ge 0, ∑ipi=1\sum_i p_i = 1Right so far: Problem 3.
  2. “The pip_i are just positive weights, so any positive weights will do.”The habit that causes the mistake: Problem 3's induction needs ∑ipi=1\sum_i p_i = 1 at every stage; with pnp_n and the rescaled pi/(1−pn)p_i/(1 - p_n), the normalisation is what makes xˉ\bar x a point the chord inequality can be applied to.
  3. f(x+y)≤f(x)+f(y)f(x + y) \le f(x) + f(y) for convex ffWith f(x)=x2f(x) = x^2 and x=y=1x = y = 1: f(2)=4>2=f(1)+f(1)f(2) = 4 > 2 = f(1) + f(1). For f(x)=x2f(x) = x^2 the true statement is f(x+y)=f(2⋅x+y2)=4f(x+y2)≤2f(x)+2f(y)f(x + y) = f\big(2\cdot\tfrac{x + y}{2}\big) = 4f\big(\tfrac{x + y}{2}\big) \le 2f(x) + 2f(y): the inequality holds only after the sum is rewritten as a multiple of an average. The fix is the same in every case: pull out the total weight, apply Jensen to the normalised combination, and keep the factor. LSE⁡\operatorname{LSE} in Problem 7 is the one place a sum appears without weights, and there the inequality that survives is the bound LSE⁡(z)≤max⁡izi+log⁡n\operatorname{LSE}(z) \le \max_i z_i + \log n, not a Jensen inequality.

3. The expected reciprocal taken to be the reciprocal of the expectation

The mean of a ratio comes up constantly: a mean rate, a mean waiting time, a mean of importance weights, and the shortcut takes expectations inside.

  1. E[X]=52\mathbb{E}[X] = \tfrac52 for X∈{1,4}X \in \{1, 4\} with equal probabilityRight so far: Problem 5(c).
  2. “Expectation is linear, so it passes through 1/X1/X.”The habit that causes the mistake: linearity passes expectation through aX+baX + b, and 1/x1/x is not linear.
  3. E[1/X]=1/E[X]=0.4\mathbb{E}[1/X] = 1/\mathbb{E}[X] = 0.4E[1/X]=0.625\mathbb{E}[1/X] = 0.625 (Problem 5), and the direction is forced by Jensen: 1/x1/x is convex on x>0x > 0, so E[1/X]≥1/E[X]\mathbb{E}[1/X] \ge 1/\mathbb{E}[X] always, with equality only for a constant XX. The same error in the other direction treats E[log⁡X]\mathbb{E}[\log X] as log⁡E[X]\log\mathbb{E}[X], which would make the ELBO equal to log⁡p(x)\log p(x) for every qq (Problem 6), and treats E[eX]\mathbb{E}[e^X] as eE[X]e^{\mathbb{E}[X]}, which drops the eσ2/2e^{\sigma^2/2} of Problem 5(b). The estimators page on importance sampling meets the first form again in the self-normalised estimator, whose denominator is a mean of weights.

4. Calling log-sum-exp strictly convex

The Hessian diag⁡(s)−ss⊤\operatorname{diag}(s) - ss^\top has positive diagonal entries, and the quadratic form is a variance, which feels positive.

  1. v⊤∇2LSE⁡(z) v=Var⁡s(V)≥0v^\top\nabla^2\operatorname{LSE}(z)\,v = \operatorname{Var}_s(V) \ge 0Right so far: Problem 7, step 5.
  2. “A variance is positive, so the Hessian is positive definite and LSE⁡\operatorname{LSE} is strictly convex.”The shortcut that causes the mistake: a variance is zero when the variable is constant.
  3. ∇2LSE⁡(z)≻0\nabla^2\operatorname{LSE}(z) \succ 0, so LSE⁡\operatorname{LSE} is strictly convex and cross-entropy with softmax has a unique minimising logit vectorv=1v = \mathbf{1} gives VV constant and 1⊤(diag⁡(s)−ss⊤)1=1−1=0\mathbf{1}^\top(\operatorname{diag}(s) - ss^\top)\mathbf{1} = 1 - 1 = 0, so 1\mathbf{1} is in the Hessian's null space at every zz: along 1\mathbf{1} the function is linear, LSE⁡(z+c1)=LSE⁡(z)+c\operatorname{LSE}(z + c\mathbf{1}) = \operatorname{LSE}(z) + c, and the softmax does not change at all (the softmax page's shift invariance). Cross-entropy LSE⁡(z)−zy\operatorname{LSE}(z) - z_y is constant along 1\mathbf{1}, so every minimiser comes with a whole line of them, and in a linear model z=Wxz = Wx the Hessian in WW is singular for the same reason. The positive-definite-matrices page has the general test: PSD with a null vector is not PD, however positive the diagonal looks.

5. Checking the second derivative at one point

The second-derivative test for a minimum is local, and the same test is reached for when convexity is wanted.

  1. f(x)=x4−x2f(x) = x^4 - x^2 has f′′(x)=12x2−2f''(x) = 12x^2 - 2, and f′′(1)=10>0f''(1) = 10 > 0Right so far: a correct second derivative.
  2. “f′′>0f'' > 0, so ff is convex.”The habit that causes the mistake: Problem 1's test asks for f′′≥0f'' \ge 0 on the whole interval, and Problem 2's tangent-line argument needs f′′(ξ)≥0f''(\xi) \ge 0 at an unknown point ξ\xi between xx and yy.
  3. ff is convex, so f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)] for every XXf′′(0)=−2<0f''(0) = -2 < 0: the graph is a double well with minima at x=±1/2x = \pm 1/\sqrt2 and a local maximum at 00. Take X=±1/2X = \pm 1/\sqrt2 with probability 12\tfrac12 each: E[X]=0\mathbb{E}[X] = 0, f(0)=0f(0) = 0, but E[f(X)]=−14\mathbb{E}[f(X)] = -\tfrac14, so the claimed inequality reads 0≤−140 \le -\tfrac14. One positive second derivative certifies a local minimum at a critical point, not convexity; convexity is a statement about every chord, and it fails as soon as f′′f'' is negative anywhere between two points. The same error in several variables accepts a PSD Hessian at the current iterate as proof that the loss is convex, which for any neural network with a hidden layer it is not.

Print this set: jensens-inequality-and-convexity.pdf (problems, answers, and worked solutions on separate pages).