
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 and in the domain and any ,
- First-Order Condition (if differentiable): Verify holds for all .
- 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 , the set of slopes defining supporting affine functions.
4.1 Linear and Affine Functions
- Linear Function
This is convex in because its Hessian is zero. Gradient: .
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
Affine functions are both convex and concave (their Hessian is zero).
Gradient: .
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
Convex if .
Gradient: .
Why It’s Convex: The second derivative is , which is nonnegative when .
- Multivariate Quadratic
Here is real symmetric and positive semidefinite. Gradient: .
Why It’s Convex: By the Second-Order Condition, we check the Hessian , which is positive semidefinite if . Hence, is convex.
4.3 Norm Functions
- -Norm
Subdifferential: A vector belongs to when for and for .
Why It’s Convex: Each absolute value is convex by the triangle inequality. A sum of these convex functions is convex.
- -Norm
Gradient, for : . At zero, .
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 (-Norm)
Subdifferential: For , it is the convex hull of over coordinates attaining the largest absolute value, where is the th coordinate vector. At zero, it is .
Why It’s Convex: A maximum of convex functions is still convex by the Pointwise Maximum rule. Since is convex, must be convex.
4.4 Exponential and Logarithmic Functions
- Exponential Function
Convex in .
Gradient: .
Why It’s Convex: The Second-Order Condition shows its second derivative is positive for all . Thus, the Hessian (in one dimension) is always > 0, satisfying convexity.
- Logarithmic Function
is concave, but is convex.
Gradient: .
Curvature: The logarithm is concave, whereas its negative is convex. The second-derivative test gives on the stated domain, establishing convexity of .
4.5 Power Functions
- Power Function
Convex in .
Gradient: .
Why It’s Convex: On , the second derivative is nonnegative for . Continuity extends convexity to . At that boundary, the right derivative is zero for and one for .
- Reciprocal Function
Convex in .
Gradient: .
Why It’s Convex: Its second derivative is positive for . This establishes convexity on the stated domain; monotonicity alone would not establish it.
4.6 Entropy and Related Functions
- Negative Entropy
Convex in .
Use . Gradient in the positive orthant: (elementwise). This formula is not defined at a zero coordinate.
Why It’s Convex: Each term has second derivative 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
Convex, but not strictly convex on all of . Gradient: (elementwise).
Why It’s Convex: If , the Hessian is . For fixed , its quadratic form is , as derived in Part 1. Only the auxiliary index is random. The identity 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
Convex in .
Subdifferential:
Why It’s Convex: The hinge loss is the pointwise maximum of the two affine functions and , with the label held fixed.
4.8 Absolute Value and Piecewise Linear Functions
- Absolute Value
Convex in .
Subdifferential: for , while .
Why It’s Convex: Using the Definition Check and the triangle inequality,
where with .
This directly satisfies the definition of convexity.
Alternatively, one can note , which is a pointwise maximum of two affine (linear) functions, ensuring convexity. And away from , the Second-Order Condition also holds (the function is piecewise linear with zero curvature).
- ReLU
Convex in .
Subdifferential:
Why It’s Convex: ReLU is a Pointwise Maximum of the linear function and constant . 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:
A log barrier function adds a penalty term to the objective that grows large as approaches the boundary . In this case, the barrier term is:
where is a parameter that controls the strength of the barrier. The modified objective function becomes:
As approaches zero from above, the term tends to infinity. The objective is undefined for nonpositive inputs, so an algorithm must retain . A positive barrier parameter also changes the minimizer; it does not leave the original objective unchanged.
- Log-Barrier Function
Convex in .
Gradient: .
Why It’s Convex: As above, is concave, so is convex. The Second-Order Condition reveals its Hessian is > 0 for .
- Softplus Function
Convex in .
Gradient: .
Why It’s Convex: Its second derivative is . Equivalently, it is log-sum-exp evaluated at the affine input . The argument is not that logarithms preserve convexity in general; they do not.
4.10 Distance Functions
- Squared Euclidean Distance
Jointly convex in . Gradient w.r.t. : .
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
Convex in .
Gradient, for : . At zero, .
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
Convex on the cone of real symmetric positive-definite matrices. Gradient: .
Why It’s Convex: Along a symmetric perturbation , the second directional derivative is . 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
where the target vector is fixed, , and . A one-hot target represents an observed class. We take and . Gradient in the positive orthant: , with elementwise division.
Why It’s Convex: The Hessian is diagonal with entries . 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
- Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press.
- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning.
- Schölkopf, B., & Smola, A. (2001). Learning with Kernels. MIT Press.
