Convex Optimization I: Convexity and Examples

On this page
Convex optimization illustration

For a convex function on a convex domain, every local minimum is also a global minimum. Before using this property, we must check convexity in the variables and domain of the problem. This series begins with that check, then examines how constraints affect the conditions for an optimum.

We begin with the defining inequality. We then give two ways to verify it: use derivatives to check curvature, or combine functions through operations that preserve convexity. These operations are often called closure properties.

The series covers:

  • How to determine if a function is convex.
  • Properties and operations that preserve convexity.
  • Standard forms of convex optimization problems.
  • The Karush-Kuhn-Tucker (KKT) conditions: what they are and when they apply.
  • Mathematical derivations, with an SVM-like example and various convex loss functions.
  • A broad survey of commonly used convex functions in optimization.

Series Division:

  • Part 1: Fundamentals, Convexity Criteria, and Examples.
  • Part 2: Duality, KKT Conditions, and Advanced Applications.
  • Part 3: Convex Loss Functions.

1. Identifying Convex Functions

A function f:Rn→Rf: \mathbb{R}^n \to \mathbb{R} is convex if and only if, for all x,y∈Rnx, y \in \mathbb{R}^n and all θ∈[0,1]\theta \in [0,1],

f(θx+(1−θ)y)  ≤  θf(x)+(1−θ) f(y).f(\theta x + (1-\theta) y) \;\le\; \theta f(x) + (1-\theta)\,f(y).

For a function defined on a smaller domain, the domain must itself be convex, and the inequality is required for points in that domain. The derivative tests below apply on an open convex domain. These definitions and tests follow Boyd and Vandenberghe's convex-functions notes.

1.1 First-Order and Second-Order Criteria

  1. First-Order Test (if ff is differentiable):

    f(y)  ≥  f(x)  +  ∇f(x)⊤( y−x ),∀ x,y.f(y) \;\ge\; f(x) \;+\; \nabla f(x)^\top (\,y - x\,), \quad \forall\,x, y.

    This criterion says that the function lies above each of its first-order approximations. At a fixed point xx, define the affine approximation ℓx(y)=f(x)+∇f(x)⊤(y−x)\ell_x(y)=f(x)+\nabla f(x)^\top(y-x). Convexity requires f(y)≥ℓx(y)f(y)\ge\ell_x(y) throughout the domain; equality holds at y=xy=x.

  2. Second-Order Test (if ff is twice differentiable):

    ∇2f(x)  ⪰  0,∀ x.\nabla^2 f(x) \;\succeq\; 0, \quad \forall\, x.

    That is, the Hessian is positive semidefinite at every point xx.

A real symmetric matrix AA is positive semidefinite (PSD) if the quadratic form zTAzz^T A z is nonnegative for every vector zz.

How to check:

  • Eigenvalue Method: Compute the eigenvalues of AA. If all eigenvalues are nonnegative, AA is PSD.
  • Principal Minors: For a symmetric matrix, PSD is equivalent to every principal minor being nonnegative. A principal submatrix uses the same index set for its rows and columns. Checking only the leading, top-left submatrices is not sufficient for PSD.

The quadratic form tests the matrix along a chosen direction. Positive semidefiniteness requires a nonnegative value in every direction.

Below are some important examples demonstrating these criteria in action—some are convex, one is not.

1.2 Preserving Convexity

Derivative tests are useful when the derivatives are simple to compute. For functions assembled from simpler pieces, the following closure properties provide another route:

  • Nonnegative Weighted Sum: If fif_i are convex and αi≥0\alpha_i \ge 0, then ∑iαifi\sum_{i}\alpha_i f_i is convex.

  • Affine Transformation: If ff is convex, then g(x)=f(Ax+b)g(x) = f(Ax + b) is convex for any matrix AA and vector bb.

  • Pointwise Maximum: If fif_i are convex, then max⁡ifi(x)\max_i f_i(x) is convex.

  • Composition with a Nondecreasing Convex Function: If f:Rm→Rf:\mathbb{R}^m\to\mathbb{R} is convex and nondecreasing in each argument, and every component of gg is convex on a common convex domain, then x↦f(g(x))x\mapsto f(g(x)) is convex. For restricted domains, the composition must also satisfy the relevant domain conditions.


2. Examples

2.1 Quadratic Function

Consider the univariate quadratic

f(x)=ax2+bx+c,a≥0,f(x) = ax^2 + bx + c,\quad a\ge 0,

or the multivariate version

f(x)=x⊤A x  +  b⊤x  +  c,f(x) = x^\top A\,x \;+\; b^\top x \;+\; c,

where AA is symmetric and A⪰0A \succeq 0 (positive semidefinite).

Step-by-step check:

  • Gradient (multivariate):
    ∇f(x)=2A x+b.\nabla f(x) = 2A\,x + b.
  • Hessian (multivariate):
    ∇2f(x)=2A.\nabla^2 f(x) = 2A.
  • Because A⪰0,A \succeq 0, we have 2A⪰0.2A \succeq 0. Hence, ∇2f(x)\nabla^2 f(x) is positive semidefinite for all x,x, implying convexity.

Interpretation: A PSD coefficient matrix gives nonnegative curvature in every direction. Zero curvature in some directions is allowed, so convexity here does not imply a unique minimizer.


2.2 Log-Sum-Exp

Define

f(x)=log⁡ ⁣(∑i=1nexi),x=(x1,…,xn)∈Rn.f(x) = \log\!\Bigl(\sum_{i=1}^n e^{x_i}\Bigr), \quad x = (x_1,\dots,x_n)\in \mathbb{R}^n.

Step-by-step check (Hessian test):

  1. Gradient of f(x)f(x):
    If we let z=∑i=1nexiz = \sum_{i=1}^n e^{x_i}, then

    ∂f∂xj=1z exj.\frac{\partial f}{\partial x_j} = \frac{1}{z} \, e^{x_j}.

    So the gradient is

    ∇f(x)=1z (ex1,ex2,…,exn)⊤.\nabla f(x) = \frac{1}{z}\,\bigl(e^{x_1}, e^{x_2}, \dots, e^{x_n}\bigr)^\top.
  2. Hessian of f(x)f(x):
    For j,k=1,…,nj,k=1,\dots,n,

    ∂2f∂xj∂xk=∂∂xk(exj∑ℓ=1nexℓ)=δjkexjz−exjexkz2,\frac{\partial^2 f}{\partial x_j \partial x_k} = \frac{\partial}{\partial x_k} \Bigl(\tfrac{ e^{x_j} }{ \sum_{\ell=1}^n e^{x_\ell} }\Bigr) = \delta_{jk}\frac{e^{x_j}}{z} -\frac{e^{x_j}e^{x_k}}{z^2},

    where z=∑ℓ=1nexℓz = \sum_{\ell=1}^n e^{x_\ell} and δjk\delta_{jk} is 11 if j=kj=k and 00 otherwise.

    The matrix form of the Hessian is

    ∇2f(x)=1z diag(ex1,…,exn)  −  1z2 (ex)(ex)⊤,\nabla^2 f(x) = \frac{1}{z}\,\mathrm{diag}(e^{x_1},\dots,e^{x_n}) \;-\; \frac{1}{z^2}\, \bigl(e^{x}\bigr)\bigl(e^{x}\bigr)^\top,

    where exe^x is the column vector of exponentials. To see why this matrix is positive semidefinite, write pi=exi/zp_i=e^{x_i}/z. For any vector vv, its quadratic form is

    v⊤∇2f(x)v=∑ipivi2−(∑ipivi)2≥0,v^\top\nabla^2f(x)v =\sum_i p_i v_i^2-\left(\sum_i p_i v_i\right)^2\ge0,

    the variance Var⁡I∼Categorical⁡(p1,…,pn)(vI)\operatorname{Var}_{I\sim\operatorname{Categorical}(p_1,\ldots,p_n)}(v_I). Here xx and vv are fixed; only the auxiliary index II is random. Its probabilities are the displayed softmax weights, so nonnegativity follows from the definition of variance.

Thus, ∇2f(x)⪰0\nabla^2 f(x)\succeq 0, so ff is convex.

Interpretation: Log-sum-exp gives a smooth alternative to max⁡ixi\max_i x_i. Its convexity follows from the nonnegative variance just derived, not merely from approximating a convex function.

It is convex but not strictly convex on all of Rn\mathbb{R}^n: adding the same constant to every coordinate gives f(x+c1)=f(x)+cf(x+c\mathbf{1})=f(x)+c, an affine direction.


2.3 Euclidean Norm (p=2p=2)

Consider

f(x)=∥x∥2=x12+x22+⋯+xn2,x∈Rn.f(x) = \|x\|_2 = \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2},\quad x\in \mathbb{R}^n.

Step-by-step check (first-order or second-order approach):

  1. Second-Order tests do not apply at x=0x=0 because the norm is not differentiable there. We therefore use the more general fact that norms are convex.

    • Geometric argument: The unit ball of ∥⋅∥2\|\cdot\|_2 is a disk or ball, which is convex. The norm ∥x∥2\|x\|_2 measures how much we must scale this unit ball to include a point. This scaling function, called its Minkowski functional, is convex because the unit ball is convex and symmetric.
  2. Subgradient at x≠0x\neq 0:

    ∇f(x)=x∥x∥2,\nabla f(x) = \frac{x}{\|x\|_2},

    whereas a subgradient approach is needed at x=0x=0.

Thus, the Euclidean norm is convex.

General fact: ∥x∥p\|x\|_p is convex for all p≥1p \ge 1.


2.4 Non-Convex Example: sin⁡(x)\sin(x)

Consider f(x)=sin⁡(x)f(x) = \sin(x) (univariate, for simplicity).

Step-by-step check:

  • First derivative: f′(x)=cos⁡(x).f'(x) = \cos(x).
  • Second derivative: f′′(x)=−sin⁡(x).f''(x) = -\sin(x).

Global convexity would require f′′(x)≥0f''(x) \ge 0 for all xx. However, −sin⁡(x)-\sin(x) changes sign. In particular, for x∈(0,π)x \in (0, \pi), f′′(x)=−sin⁡(x)<0,f''(x) = -\sin(x) < 0, so ff is concave on that interval. At x=0x=0, we have f′′(0)=0f''(0)=0, but the value at a single point does not establish convexity. Therefore, sin⁡(x)\sin(x) is not convex over R\mathbb{R}.

Interpretation: sin⁡(x)\sin(x) oscillates, so it curves up and down infinitely often, violating any global convexity requirement.


Notes

  1. Quadratic + PSD → Convex.
  2. Log-sum-exp: Convex, but not strictly convex on its full domain.
  3. ℓ₂-norm: Convex (more generally, ℓₚ-norms for p≥1p \ge 1 are convex).
  4. sin⁡(x)\sin(x): Not convex, since its second derivative changes sign.

General thinking process when Verifying Convexity:

  • Definition Check: Confirm that for any two points xx and yy in the domain and any θ∈[0,1]\theta \in [0,1],

    f(θx+(1−θ)y)≤θf(x)+(1−θ)f(y).f(\theta x + (1-\theta)y) \le \theta f(x) + (1-\theta)f(y).

    This is the fundamental property of convex functions.

  • First-Order Condition: For differentiable functions, verify that the function always lies above its tangent lines. In other words, check that

    f(y)≥f(x)+∇f(x)T(y−x)f(y) \ge f(x) + \nabla f(x)^T (y-x)

    holds for all xx and yy.

  • Second-Order Condition: For twice differentiable functions, check that the Hessian matrix is positive semidefinite everywhere in the domain. This guarantees that the curvature is non-negative throughout (and watch for points of non-differentiability).

  • Composition Rules: Many functions are built from simpler components. Convexity is preserved under operations such as:

    • Sum: If f(x)f(x) and g(x)g(x) are convex, then

      h(x)=f(x)+g(x)h(x) = f(x) + g(x)

      is convex.

    • Scaling: If f(x)f(x) is convex and a≥0a \ge 0 is a scalar, then

      g(x)=a f(x)g(x) = a \, f(x)

      is convex.

    • Affine Transformation: If ff is convex and g(x)=Ax+bg(x) = A x + b is an affine mapping, then

      h(x)=f(Ax+b)h(x) = f(A x + b)

      is convex.

    • Nondecreasing/Nonincreasing Composition:
      If f:R→Rf:\mathbb{R}\to\mathbb{R} is convex and nondecreasing and g:Rn→Rg:\mathbb{R}^n\to\mathbb{R} is convex, then

      h(x)=f(g(x))h(x) = f(g(x))

      is convex.
      Similarly, if ff is convex and nonincreasing and gg is concave, then h(x)=f(g(x))h(x)=f(g(x)) is convex.

    • Pointwise Maximum: The pointwise maximum of convex functions is also convex. If fi(x)f_i(x) are convex for i=1,2,…,ni = 1, 2, \dots, n, then

      h(x)=max⁡{f1(x),f2(x),…,fn(x)}h(x) = \max\{f_1(x), f_2(x), \dots, f_n(x)\}

      is convex.

    • Perspective Function: Given a convex function f:Rn→Rf:\mathbb{R}^n\to\mathbb{R}, its perspective

      g(x,t)=t f(xt)g(x,t) = t \, f\Bigl(\frac{x}{t}\Bigr)

      is convex on {(x,t)∈Rn+1:t>0}\{(x,t) \in \mathbb{R}^{n+1}: t > 0\}. This is particularly useful for scaling or normalization.

    • Elementwise Composition: A convex outer function alone does not guarantee a convex composition. For example, h(x)=∥g(x)∥2h(x)=\|g(x)\|_2 is convex if each component of gg is convex and nonnegative: the Euclidean norm is convex and coordinatewise nondecreasing on the nonnegative orthant.

  • Reformulation: If the convexity of the original function is not immediately clear, try to reformulate it as a combination of simpler convex components. This can often reveal the hidden structure.

  • Convex Relaxation: Replacing a nonconvex problem by a convex relaxation changes the problem. It can provide a bound or a tractable approximation, but it does not establish convexity of the original problem or automatically preserve its optimizer.

  • Additional Tools: Numerical checks can expose counterexamples or suggest an argument, but checking finitely many points does not prove global convexity. Symbolic calculations can support a proof when their domain and assumptions are explicit.

Use the expression and domain to choose the proof. Derivative tests require differentiability throughout the domain; closure properties can also cover corners such as the origin of a norm. A numerical check can suggest a counterexample, but cannot replace either argument.

These examples establish the tools used in the rest of the series. Part 2: Duality, KKT Conditions, and Advanced Applications uses them to study constrained problems, while Part 3: Convex Loss Functions collects common functions and their derivatives.

References & Further Reading

  1. Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press.
  2. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning.
  3. Schölkopf, B., & Smola, A. (2001). Learning with Kernels. MIT Press.