Convex Optimization III: A Reference to Convex Functions

On this page
Convex optimization illustration

Image credit: Huang et al. (2022)

This reference completes a three-part series on convex optimization. Across the series, we examine:

  • 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.

The convexity tests in Part 1 and the constrained problems in Part 2 use several common functions. This reference collects them in one place. Each entry gives the variable, domain, derivative or subgradient, and reason for convexity. Some functions measure prediction loss; others penalize a solution or define a constraint.

4. Common Convex Loss Functions

Convexity depends on which variable we optimize. A loss can be convex in a predicted probability or score but not in the parameters of the neural network producing that prediction. Each entry below concerns the function's stated variables. Substituting a model's output into the function requires a separate convexity check. The main rules are summarized in Boyd and Vandenberghe's convex-functions notes.

Recap: The convexity tests used below

The entries reuse the following results from Part 1. Choose a test that applies on the function's entire convex domain:

  • 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).
  • First-Order Condition (if differentiable): Verify f(y)≥f(x)+∇f(x)T(y−x)f(y) \ge f(x) + \nabla f(x)^T (y-x) holds for all x,yx, y.
  • Second-Order Condition (if twice differentiable): Check the Hessian is positive semidefinite everywhere.
  • Composition Rules: Recognize that sums, nonnegative scalings, affine transformations, pointwise maxima of convex functions, and suitable compositions preserve convexity.
  • Reformulation & Relaxation: Rewriting the same function can reveal its convexity. Replacing it by a convex surrogate changes the function and does not prove that the original was convex.

Derivative tests below apply where the derivatives exist. At nondifferentiable points, we use the subdifferential ∂f\partial f, the set of slopes defining supporting affine functions.

4.1 Linear and Affine Functions

  • Linear Function
    f(x)=a⊤x,a∈Rn  .f(\mathbf{x}) = \mathbf{a}^\top \mathbf{x}, \quad \mathbf{a} \in \mathbb{R}^n\;.
    This is convex in x\mathbf{x} because its Hessian is zero. Gradient: ∇f(x)=a\nabla f(\mathbf{x}) = \mathbf{a}.

Why It’s Convex: A linear function has zero curvature (its Hessian is the zero matrix). By the Second-Order Condition, a zero Hessian is positive semidefinite, hence convex. Also, by Definition Check, linear functions satisfy the convexity inequality exactly.


  • Affine Function
    f(x)=a⊤x+b,a∈Rn,  b∈R.f(\mathbf{x}) = \mathbf{a}^\top \mathbf{x} + b, \quad \mathbf{a} \in \mathbb{R}^n,\; b \in \mathbb{R}.
    Affine functions are both convex and concave (their Hessian is zero).
    Gradient: ∇f(x)=a\nabla f(\mathbf{x}) = \mathbf{a}.

Why It’s Convex: An affine function is just a linear function plus a constant shift. The same reasoning (zero Hessian, or direct verification by definition) shows it is convex. In fact, it’s both convex and concave.


4.2 Quadratic Functions

  • Univariate Quadratic
    f(x)=ax2+bx+c,a≥0.f(x) = ax^2 + bx + c, \quad a \ge 0.
    Convex if a≥0a \ge 0.
    Gradient: ∇f(x)=2ax+b\nabla f(x) = 2ax + b.

Why It’s Convex: The second derivative is 2a2a, which is nonnegative when a≥0a\ge0.


  • Multivariate Quadratic
    f(x)=x⊤Ax+b⊤x+c,A⪰0.f(\mathbf{x}) = \mathbf{x}^\top A \mathbf{x} + \mathbf{b}^\top \mathbf{x} + c,\quad A \succeq 0.
    Here AA is real symmetric and positive semidefinite. Gradient: ∇f(x)=2Ax+b\nabla f(\mathbf{x}) = 2 A \mathbf{x} + \mathbf{b}.

Why It’s Convex: By the Second-Order Condition, we check the Hessian 2A2A, which is positive semidefinite if A⪰0A \succeq 0. Hence, ff is convex.


4.3 Norm Functions

  • ℓ1\ell_1-Norm
    f(x)=∥x∥1=∑i=1n∣xi∣.f(\mathbf{x}) = \|\mathbf{x}\|_1 = \sum_{i=1}^n |x_i|.
    Subdifferential: A vector gg belongs to ∂f(x)\partial f(\mathbf{x}) when gi=sign⁡(xi)g_i=\operatorname{sign}(x_i) for xi≠0x_i\ne0 and gi∈[−1,1]g_i\in[-1,1] for xi=0x_i=0.

Why It’s Convex: Each absolute value ∣xi∣|x_i| is convex by the triangle inequality. A sum of these convex functions is convex.


  • ℓ2\ell_2-Norm
    f(x)=∥x∥2=∑i=1nxi2.f(\mathbf{x}) = \|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2}.
    Gradient, for x≠0\mathbf{x}\ne0: ∇f(x)=x/∥x∥2\nabla f(\mathbf{x})=\mathbf{x}/\|\mathbf{x}\|_2. At zero, ∂f(0)={g:∥g∥2≤1}\partial f(0)=\{g:\|g\|_2\le1\}.

Why It’s Convex: For a convex combination of two vectors, the triangle inequality and positive homogeneity give the defining convexity inequality. This argument also covers the origin, where the gradient does not exist.


  • Max Norm (ℓ∞\ell_\infty-Norm)
    f(x)=∥x∥∞=max⁡i∣xi∣.f(\mathbf{x}) = \|\mathbf{x}\|_\infty = \max_i |x_i|.
    Subdifferential: For x≠0\mathbf{x}\ne0, it is the convex hull of sign⁡(xi)ei\operatorname{sign}(x_i)e_i over coordinates attaining the largest absolute value, where eie_i is the iith coordinate vector. At zero, it is {g:∥g∥1≤1}\{g:\|g\|_1\le1\}.

Why It’s Convex: A maximum of convex functions { ∣x1∣,…,∣xn∣}\{\,|x_1|,\dots,|x_n|\} is still convex by the Pointwise Maximum rule. Since ∣xi∣|x_i| is convex, max⁡i∣xi∣\max_i |x_i| must be convex.


4.4 Exponential and Logarithmic Functions

  • Exponential Function
    f(x)=ex.f(x) = e^x.
    Convex in xx.
    Gradient: ∇f(x)=ex\nabla f(x) = e^x.

Why It’s Convex: The Second-Order Condition shows its second derivative exe^x is positive for all xx. Thus, the Hessian (in one dimension) is always > 0, satisfying convexity.


  • Logarithmic Function
    f(x)=log⁡(x),x>0.f(x) = \log(x), \quad x > 0.
    log⁡(x)\log(x) is concave, but −log⁡(x)-\log(x) is convex.
    Gradient: ∇f(x)=1/x\nabla f(x) = 1/x.

Curvature: The logarithm is concave, whereas its negative is convex. The second-derivative test gives d2dx2(−log⁡(x))=1x2≥0\frac{d^2}{dx^2}(-\log(x)) = \frac{1}{x^2} \ge 0 on the stated domain, establishing convexity of −log⁡(x)-\log(x).


4.5 Power Functions

  • Power Function
    f(x)=xp,x≥0,  p≥1.f(x) = x^p, \quad x \ge 0, \; p \ge 1.
    Convex in xx.
    Gradient: ∇f(x)=pxp−1\nabla f(x) = p x^{p-1}.

Why It’s Convex: On x>0x>0, the second derivative p(p−1)xp−2p(p-1)x^{p-2} is nonnegative for p≥1p\ge1. Continuity extends convexity to x=0x=0. At that boundary, the right derivative is zero for p>1p>1 and one for p=1p=1.


  • Reciprocal Function
    f(x)=1x,x>0.f(x) = \frac{1}{x}, \quad x > 0.
    Convex in xx.
    Gradient: ∇f(x)=−1x2\nabla f(x) = -\frac{1}{x^2}.

Why It’s Convex: Its second derivative 2x3\frac{2}{x^3} is positive for x>0x>0. This establishes convexity on the stated domain; monotonicity alone would not establish it.


  • Negative Entropy
    f(p)=∑i=1npilog⁡(pi),pi≥0,  ∑ipi=1.f(\mathbf{p}) = \sum_{i=1}^n p_i \log(p_i),\quad p_i \ge 0,\; \sum_i p_i = 1.
    Convex in p\mathbf{p}.
    Use 0log⁡0=00\log0=0. Gradient in the positive orthant: ∇f(p)=1+log⁡(p)\nabla f(\mathbf{p})=\mathbf{1}+\log(\mathbf{p}) (elementwise). This formula is not defined at a zero coordinate.

Why It’s Convex: Each term has second derivative 1/pi>01/p_i>0 in the interior, and the sum extends continuously to the boundary. Thus negative entropy is convex; entropy, with the opposite sign, is concave.


  • Log-Sum-Exp Function
    f(x)=log⁡(∑i=1nexi).f(\mathbf{x}) = \log \bigl(\sum_{i=1}^n e^{x_i}\bigr).
    Convex, but not strictly convex on all of Rn\mathbb{R}^n. Gradient: ∇f(x)=ex∑i=1nexi\nabla f(\mathbf{x}) = \frac{e^{\mathbf{x}}}{\sum_{i=1}^n e^{x_i}} (elementwise).

Why It’s Convex: If pi=exi/∑jexjp_i=e^{x_i}/\sum_j e^{x_j}, the Hessian is diag⁡(p)−pp⊤\operatorname{diag}(p)-pp^\top. For fixed x,vx,v, its quadratic form is Var⁡I∼Categorical⁡(p1,…,pn)(vI)≥0\operatorname{Var}_{I\sim\operatorname{Categorical}(p_1,\ldots,p_n)}(v_I)\ge0, as derived in Part 1. Only the auxiliary index II is random. The identity f(x+c1)=f(x)+cf(\mathbf{x}+c\mathbf{1})=f(\mathbf{x})+c shows why strict convexity fails on the full space. Being a smooth approximation to a convex function would not, by itself, prove convexity.


4.7 Hinge Loss Function

  • Hinge Loss

    f(x)=max⁡(0, 1−y⋅x),y∈{−1,+1}.f(x) = \max(0,\, 1 - y \cdot x),\quad y \in \{-1, +1\}.


    Convex in xx.
    Subdifferential:

    ∂f(x)={{−y},if 1−yx>0,{0},if 1−yx<0,{−ty:0≤t≤1},if 1−yx=0.\partial f(x) = \begin{cases} \{-y\}, & \text{if } 1-yx>0,\\[1mm] \{0\}, & \text{if } 1-yx<0,\\[1mm] \{-ty:0\le t\le1\}, & \text{if } 1-yx=0. \end{cases}

Why It’s Convex: The hinge loss is the pointwise maximum of the two affine functions 00 and 1−yx1-yx, with the label held fixed.


4.8 Absolute Value and Piecewise Linear Functions

  • Absolute Value
    f(x)=∣x∣.f(x) = |x|.
    Convex in xx.
    Subdifferential: ∂f(x)={sign⁡(x)}\partial f(x)=\{\operatorname{sign}(x)\} for x≠0x\ne0, while ∂f(0)=[−1,1]\partial f(0)=[-1,1].

Why It’s Convex: Using the Definition Check and the triangle inequality,

f(αx+βy)=∣αx+βy∣      ≤⏟triangle inequality    ∣αx∣+∣βy∣=α∣x∣+β∣y∣=αf(x)+βf(y),\begin{aligned} f(\alpha x + \beta y) &= |\alpha x + \beta y| \;\;\;\underbrace{\le}_{\text{triangle inequality}}\;\; |\alpha x| + |\beta y| \\ &= \alpha |x| + \beta |y| = \alpha f(x) + \beta f(y), \end{aligned}

where α,β∈R≥0\alpha, \beta \in \mathbb{R}_{\ge 0} with α+β=1\alpha + \beta = 1.
This directly satisfies the definition of convexity. Alternatively, one can note ∣x∣=max⁡(x,−x)|x| = \max(x, -x), which is a pointwise maximum of two affine (linear) functions, ensuring convexity. And away from x=0x=0, the Second-Order Condition also holds (the function is piecewise linear with zero curvature).

  • ReLU
    f(x)=max⁡(0,x).f(x) = \max(0, x).
    Convex in xx.
    Subdifferential: ∂f(x)={{1},x>0,[0,1],x=0,{0},x<0.\partial f(x) = \begin{cases} \{1\}, & x>0,\\ [0,1], & x=0,\\ \{0\}, & x<0. \end{cases}

Why It’s Convex: ReLU is a Pointwise Maximum of the linear function xx and constant 00. Hence, by that rule, it is convex.


4.9 Log-Barrier and Soft Constraints

A log barrier is defined only in the interior of the feasible region and diverges as the boundary is approached. It is therefore different from a finite penalty that allows constraint violations.

For example, consider minimizing a quadratic while requiring a positive variable:

f(x)=(x−1)2subject tox>0.f(x) = (x-1)^2 \quad \text{subject to} \quad x > 0.

A log barrier function adds a penalty term to the objective that grows large as xx approaches the boundary x=0x=0. In this case, the barrier term is:

−μln⁡(x),-\mu \ln(x),

where μ>0\mu > 0 is a parameter that controls the strength of the barrier. The modified objective function becomes:

min⁡x>0(x−1)2−μln⁡(x).\min_{x>0} \quad (x-1)^2 - \mu \ln(x).

As xx approaches zero from above, the term −μln⁡(x)-\mu\ln(x) tends to infinity. The objective is undefined for nonpositive inputs, so an algorithm must retain x>0x>0. A positive barrier parameter also changes the minimizer; it does not leave the original objective unchanged.

  • Log-Barrier Function
    f(x)=−log⁡(x),x>0.f(x) = -\log(x), \quad x > 0.
    Convex in xx.
    Gradient: ∇f(x)=−1x\nabla f(x) = -\frac{1}{x}.

Why It’s Convex: As above, log⁡(x)\log(x) is concave, so −log⁡(x)-\log(x) is convex. The Second-Order Condition reveals its Hessian 1x2\frac{1}{x^2} is > 0 for x>0x>0.


  • Softplus Function
    f(x)=log⁡(1+ex).f(x) = \log(1 + e^x).
    Convex in xx.
    Gradient: ∇f(x)=11+e−x\nabla f(x) = \frac{1}{1 + e^{-x}}.

Why It’s Convex: Its second derivative is ex/(1+ex)2>0e^x/(1+e^x)^2>0. Equivalently, it is log-sum-exp evaluated at the affine input (0,x)(0,x). The argument is not that logarithms preserve convexity in general; they do not.


4.10 Distance Functions

  • Squared Euclidean Distance
    f(x,y)=∥x−y∥22=(x−y)⊤(x−y).f(\mathbf{x}, \mathbf{y}) = \|\mathbf{x} - \mathbf{y}\|_2^2 = (\mathbf{x} - \mathbf{y})^\top (\mathbf{x} - \mathbf{y}).
    Jointly convex in (x,y)(\mathbf{x},\mathbf{y}). Gradient w.r.t. x\mathbf{x}: ∇f(x)=2(x−y)\nabla f(\mathbf{x}) = 2(\mathbf{x} - \mathbf{y}).

Why It’s Convex: The difference is an affine function of the pair of vectors, and the squared Euclidean norm is convex. Their composition is therefore jointly convex.


4.11 Matrix Norms and Functions

  • Frobenius Norm
    f(X)=∥X∥F=∑i,jXij2,X∈Rm×n.f(X) = \|X\|_F = \sqrt{\sum_{i,j} X_{ij}^2},\quad X \in \mathbb{R}^{m \times n}.
    Convex in XX.
    Gradient, for X≠0X\ne0: ∇f(X)=X/∥X∥F\nabla f(X)=X/\|X\|_F. At zero, ∂f(0)={G:∥G∥F≤1}\partial f(0)=\{G:\|G\|_F\le1\}.

Why It’s Convex: The Frobenius norm is the Euclidean norm of the vector containing all matrix entries. The same norm argument therefore applies.


  • Log-Determinant Function
    f(X)=−log⁡(det⁡(X)),X≻0,  X∈Rn×n.f(X) = -\log(\det(X)), \quad X \succ 0,\; X \in \mathbb{R}^{n \times n}.
    Convex on the cone of real symmetric positive-definite matrices. Gradient: ∇f(X)=−X−1\nabla f(X) = -X^{-1}.

Why It’s Convex: Along a symmetric perturbation HH, the second directional derivative is Tr⁡(X−1HX−1H)=∥X−1/2HX−1/2∥F2≥0\operatorname{Tr}(X^{-1}HX^{-1}H)=\|X^{-1/2}HX^{-1/2}\|_F^2\ge0. This establishes convexity in the matrix argument on the positive-definite cone, not merely in the determinant viewed as a scalar.


4.12 Cross-Entropy Loss Function

  • Cross-Entropy Loss
    f(p;y)=−∑i=1nyilog⁡(pi),f(\mathbf{p};\mathbf{y})=-\sum_{i=1}^n y_i\log(p_i), where the target vector is fixed, yi≥0y_i\ge0, and ∑iyi=1\sum_i y_i=1. A one-hot target represents an observed class. We take pi>0p_i>0 and ∑ipi=1\sum_i p_i=1. Gradient in the positive orthant: ∇f(p)=−y/p\nabla f(\mathbf{p})=-\mathbf{y}/\mathbf{p}, with elementwise division.

Why It’s Convex: The Hessian is diagonal with entries yi/pi2≥0y_i/p_i^2\ge0. Restricting this convex function to the probability simplex preserves convexity. This is a claim about the probability vector, not arbitrary model parameters.


Final Thoughts

The useful question is not just whether a familiar function is convex, but whether it remains convex in the variables and domain of the current problem. Check the domain, identify any nondifferentiable points, and then apply the relevant derivative or composition rule. Part 1 develops those tests, while Part 2 explains how constraints enter the optimality conditions.

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.