Module I·Article II·~5 min read

Convex Functions: Definitions and Criteria

Convex Sets and Functions

Reading tools · save, download, print, audio

Turn this article into a podcast

Pick voices, format, length — AI generates the audio

Why Study Convex Functions?

The main practical fact: if a function is convex, then any of its local minima is also a global minimum. This is an enormous advantage. In a non-convex problem, you may have thousands of local minima, and the algorithm can get "stuck" in a bad one. In a convex problem, there is only one minimum, and any descent method will reach it. Therefore, the entire foundation of modern machine learning is built to exploit convex structures as much as possible.

Definition of a Convex Function

A function f:Rn→Rf: \mathbb{R}^n \to \mathbb{R} (or f:dom⁡(f)→Rf: \operatorname{dom}(f) \to \mathbb{R}, where dom⁡(f)\operatorname{dom}(f) is a convex set) is called convex if for any x,y∈dom⁡(f)x, y \in \operatorname{dom}(f) and any λ∈[0,1]\lambda \in [0,1]:

f(λx+(1−λ)y)≤λf(x)+(1−λ)f(y)f(\lambda x + (1-\lambda)y) \leq \lambda f(x) + (1-\lambda)f(y)

Geometric meaning: consider two points on the graph of the function: A=(x,f(x))A = (x, f(x)), B=(y,f(y))B = (y, f(y)). The right-hand side, λf(x)+(1−λ)f(y)\lambda f(x) + (1-\lambda)f(y), is a point on the chord AB corresponding to parameter λ\lambda. The left-hand side, f(λx+(1−λ)y)f(\lambda x + (1-\lambda)y), is the value of the function at the same point horizontally. Convexity means: the graph of the function lies below every chord. The chord "hangs over" the graph.

If a strict inequality holds (<< instead of ≤\leq) for x≠yx \neq y and λ∈(0,1)\lambda \in (0,1), the function is strictly convex. A strictly convex function has a unique minimum.

Concave function: ff is concave if −f-f is convex. The inequality "reverses".

Examples of Convex Functions

In one variable:

  • f(x)=x2f(x) = x^2 — convex (parabola "opens upwards")
  • f(x)=exf(x) = e^x — convex (exponential)
  • f(x)=∣x∣f(x) = |x| — convex, but not differentiable at 00
  • f(x)=xlog⁡xf(x) = x \log x on x>0x > 0 — convex (used in information theory)
  • f(x)=log⁡xf(x) = \log x on x>0x > 0 — concave

In several variables:

  • f(x)=∥x∥2=x12+…+xn2f(x) = \|x\|^2 = x_1^2 + \ldots + x_n^2 — convex
  • f(x)=max⁡(x1,…,xn)f(x) = \max(x_1, \ldots, x_n) — convex (maximum of linear functions)
  • f(x)=log⁡(∑iexi)f(x) = \log\left(\sum_i e^{x^i}\right) — "soft-max", log-sum-exp, convex and smooth
  • f(X)=λmax⁡(X)f(X) = \lambda_{\max}(X) — largest eigenvalue of a symmetric matrix — convex

Criteria of Convexity

Directly checking the definition is often inconvenient. In practice, analytic criteria are used.

First order criterion (for differentiable functions):

f is convex  ⟺  ∀x,y∈dom⁡(f):f(y)≥f(x)+∇f(x)T(y−x)f \text{ is convex} \iff \forall x, y \in \operatorname{dom}(f): \quad f(y) \geq f(x) + \nabla f(x)^T(y - x)

Meaning: the tangent hyperplane to the graph at any point xx lies below (or touches) the graph. The gradient ∇f(x)\nabla f(x) gives the "best linear approximation" to ff near xx, and for a convex function, this approximation is a global lower bound.

Important consequence: if ∇f(x∗)=0\nabla f(x^*) = 0, then x∗x^* is a global minimum! Indeed, f(y)≥f(x∗)+0=f(x∗)f(y) \geq f(x^*) + 0 = f(x^*) for all yy.

Second order criterion (for twice differentiable functions):

f is convex  ⟺  ∇2f(x)⪰0∀x∈dom⁡(f)f \text{ is convex} \iff \nabla^2 f(x) \succeq 0 \quad \forall x \in \operatorname{dom}(f)

Here, ∇2f(x)\nabla^2 f(x) is the Hessian matrix (matrix of second partial derivatives), ⪰0\succeq 0 means "positive semi-definite" (all eigenvalues ≥0\geq 0).

Meaning: the function "bends upwards" in all directions. For f(x)=x2f(x) = x^2, we have f′′(x)=2>0f''(x) = 2 > 0 — convex. For f(x)=−x2f(x) = -x^2, f′′(x)=−2<0f''(x) = -2 < 0 — concave.

Sublevel Sets and the Epigraph

Sublevel set Cα={x:f(x)≤α}C_\alpha = \{ x: f(x) \leq \alpha \} — all points where the function does not exceed α\alpha.

Theorem: if ff is convex, then all sublevel sets CαC_\alpha are convex.

Epigraph epi⁡(f)={(x,t):f(x)≤t}\operatorname{epi} (f) = \{ (x, t) : f(x) \leq t \} — "everything above the graph," including the graph itself.

Key theorem: ff is convex   ⟺  \iff epi⁡(f)\operatorname{epi}(f) is a convex set in Rn+1\mathbb{R}^{n+1}.

This connects the theory of functions and the theory of sets: the problem of minimizing a convex function is equivalent to finding the "lowest point" of a convex body.

Operations Preserving Convexity

Knowing a few simple convex functions, complex ones can be built:

  • Sum: f1+f2f_1 + f_2 is convex if f1f_1 and f2f_2 are convex
  • Nonnegative scaling: λf\lambda f for λ≥0\lambda \geq 0 is convex
  • Maximum: max⁡(f1,f2,…,fm)\max(f_1, f_2, \ldots, f_m) is convex (the maximum of convex functions is convex)
  • Affine substitution: f(Ax+b)f(Ax + b) is convex (if ff is convex)
  • Supremum: sup⁡y∈Sf(x,y)\sup_{y \in S} f(x, y) is convex in xx (if f(⋅,y)f(\cdot, y) is convex for every yy)

Complete Example Breakdown

Problem: check the convexity of f(x1,x2)=x12+2x1x2+3x22f(x_1, x_2) = x_1^2 + 2x_1x_2 + 3x_2^2 using the second order criterion.

Step 1: Compute the second partial derivatives. ∂f∂x1=2x1+2x2,\frac{\partial f}{\partial x_1} = 2x_1 + 2x_2, ∂2f∂x12=2\frac{\partial^2 f}{\partial x_1^2} = 2
∂f∂x2=2x1+6x2,\frac{\partial f}{\partial x_2} = 2x_1 + 6x_2, ∂2f∂x22=6\frac{\partial^2 f}{\partial x_2^2} = 6
∂2f∂x1∂x2=2\frac{\partial^2 f}{\partial x_1 \partial x_2} = 2

Step 2: The Hessian matrix (independent of xx in this example):

∇2f=[2226]\nabla^2 f = \begin{bmatrix} 2 & 2 \\ 2 & 6 \end{bmatrix}

Step 3: Check positive semi-definiteness. Sylvester’s criterion:

  • Leading principal minor 1×11 \times 1: 2>02 > 0 ✓
  • Determinant 2×22 \times 2: 2⋅6−2⋅2=12−4=8>02 \cdot 6 - 2 \cdot 2 = 12 - 4 = 8 > 0 ✓

Both leading principal minors are positive →\rightarrow the matrix is positive definite →\rightarrow ff is strictly convex.

Step 4: Find the minimum. ∇f(x)=0\nabla f(x) = 0: 2x1+2x2=02x_1 + 2x_2 = 0, 2x1+6x2=02x_1 + 6x_2 = 0. From the first equation: x1=−x2x_1 = -x_2. Substitute into the second: −2x2+6x2=0⇒x2=0-2x_2 + 6x_2 = 0 \Rightarrow x_2 = 0, x1=0x_1 = 0. The minimum at point (0,0)(0, 0), f(0,0)=0f(0, 0) = 0.

Applications

Regression: mean squared error f(w)=∥Xw−y∥2f(w) = \|Xw - y\|^2 is convex (criterion: ∇2f=2XTX⪰0\nabla^2 f = 2X^TX \succeq 0). Thus, gradient descent always finds the global minimum.

Logistic regression: loss function −∑[yilog⁡σ(wTxi)+(1−yi)log⁡(1−σ(wTxi))]-\sum \left[y_i \log \sigma(w^T x_i) + (1-y_i) \log (1 - \sigma(w^T x_i))\right] is convex in ww. Guaranteed convergence of any first-order method.

Finance: function of mean-variance risk of a portfolio wTΣww^T \Sigma w (Σ\Sigma is the covariance matrix, ⪰0\succeq 0) is convex. Minimizing risk is a convex problem with a unique solution.

§ Act · what next