Convex function

On this page 7

A convex function is a real-valued function for which the line segment between any two points on its graph never falls below the graph. Formally, f is convex when f(θx + (1 − θ)y) ≤ θf(x) + (1 − θ)f(y) for all points x and y in a convex domain and every θ between 0 and 1. In optimization for artificial intelligence, convexity is the property that separates problems with a guaranteed global solution from problems where an algorithm may stall in a poor local optimum.

Convexity matters because it turns a local statement into a global one: for a convex function, every local minimum is a global minimum, and the set of minimizers is itself convex. Classical machine learning models such as logistic regression, support vector machines and ridge regression are trained by minimizing convex objectives, which is why their training is predictable and reproducible.

Equivalent ways to recognize a convex function

A convex function can be identified through three equivalent characterizations, depending on how smooth it is. The chord definition applies to every function, the first-order condition applies to differentiable functions, and the second-order condition applies to twice-differentiable functions. Each version is useful in a different stage of model design and proof.

The first-order condition states that the function lies above every tangent plane: f(y) ≥ f(x) + ∇f(x)ᵀ(y − x). This inequality is the reason a zero gradient certifies optimality for a convex function. The second-order condition requires the Hessian matrix to be positive semidefinite everywhere on the domain, which for a single variable simply means a nonnegative second derivative.

The table below summarizes the three tests and when each one is practical.

TestConditionRequiresTypical use
Chord definitionGraph lies below every chordNothing beyond a convex domainProofs for nonsmooth functions
First-order conditionGraph lies above every tangentDifferentiabilityOptimality certificates
Second-order conditionHessian is positive semidefiniteTwice differentiabilityChecking quadratic and smooth losses
Epigraph testRegion above the graph is a convex setNothing beyond a convex domainGeometric arguments and duality
Tests for convexity and their requirements

Convexity comes in several strengths, and the strength determines uniqueness of the minimizer and convergence speed. A strictly convex function has a strict inequality on its chords, so it has at most one minimizer. A strongly convex function with parameter m > 0 curves upward at least as fast as a quadratic, which guarantees a unique minimizer and linear convergence of gradient descent.

Weaker notions also appear in practice. Quasiconvex functions have convex sublevel sets but may contain flat regions, while concave functions are negatives of convex ones and are maximized rather than minimized. The following table compares these variants.

VariantDefining propertyMinimizerExample
ConvexChord inequality holdsSet of minimizers is convexAbsolute value |x|
Strictly convexChord inequality is strictAt most oneExponential function eˣ
Strongly convexCurvature at least m > 0Exactly one, if domain is closedSquared norm ‖x‖²
QuasiconvexSublevel sets are convexLocal minima may not be global on plateausCeiling function
ConcaveNegative of a convex functionMaximized insteadLogarithm log x
Variants of convexity and their consequences

Smoothness is a separate property from convexity. A function is L-smooth when its gradient is Lipschitz continuous with constant L. The ratio κ = L/m, called the condition number, governs how many iterations first-order methods need, and a large κ explains slow training on poorly scaled features.

Operations that preserve convexity

Practitioners rarely prove convexity from the definition; instead they build objectives from known convex pieces combined by convexity-preserving operations. This compositional approach, often called disciplined convex programming, lets modeling tools verify convexity automatically before solving.

  • Nonnegative weighted sums of convex functions are convex, so a loss plus an L1 or L2 penalty remains convex.
  • Composition with an affine map preserves convexity, which is why f(Ax + b) is convex whenever f is.
  • Pointwise maximum of convex functions is convex, which covers the hinge loss max(0, 1 − y·wᵀx).
  • Partial minimization over some variables of a jointly convex function keeps the result convex.
  • Perspective and conjugate transformations preserve convexity and underpin Lagrangian duality.

The product of two convex functions and the composition of two convex functions are not convex in general. A composition h(g(x)) is convex only under conditions such as h convex and nondecreasing with g convex, a rule that is easy to forget when designing custom losses.

Convex functions in machine learning objectives

Many standard training objectives are convex in the model parameters when the model is linear in those parameters. The table shows common losses and regularizers and the convexity properties that determine which solver suits them.

FunctionUsed inConvexitySmooth
Squared errorLinear regressionConvex, strongly convex with full-rank dataYes
Logistic lossLogistic regressionConvex, not strongly convexYes
Hinge lossSupport vector machinesConvexNo, kink at margin
L1 penaltyLasso, sparse modelsConvexNo, kink at zero
L2 penaltyRidge regression, weight decayStrongly convexYes
Cross-entropy with softmaxMultinomial regressionConvex in the logitsYes
Common convex losses and regularizers in machine learning

Deep neural networks are not convex in their weights, even when the loss is convex in the network outputs, because stacking nonlinear layers destroys convexity. Convex analysis nevertheless remains central: it supplies the convergence theory for gradient methods, the design of proximal gradient methods and ADMM for nonsmooth penalties, and convex surrogates such as the hinge and logistic losses that replace the nonconvex 0-1 loss.

Limitations and common mistakes

Convexity is a strong guarantee, but it is often assumed rather than verified. The most frequent errors concern the domain, the variables and the meaning of the guarantee itself.

  • Ignoring the domain: a function is convex only on a convex domain, so a feasible region with holes breaks the guarantee.
  • Confusing convexity in data and in parameters: what matters for training is convexity with respect to the variables being optimized.
  • Equating convex with easy: large convex problems can still be slow when they are ill-conditioned or nonsmooth.
  • Expecting a unique answer: a convex function that is not strictly convex can have infinitely many minimizers, which affects interpretability of coefficients.

Put simply

Picture a smooth bowl. Drop a marble anywhere inside, and it rolls to the single lowest point. A convex function has this bowl shape. It has no hidden dips where the marble could get stuck.

This shape is very useful for computers that learn from data. Training a model means searching for the lowest error. When the error has a bowl shape, a simple step-by-step downhill search always finds the best answer. When the shape is bumpy, the search may stop in a small dip and miss the true bottom.

In practice

A credit risk team at a mid-sized bank trains a logistic regression model on 400,000 past loan applications with 120 features. The team adds an L2 penalty to the logistic loss, which makes the objective strongly convex. Because of this, the L-BFGS solver reaches the same optimum from any starting point, and the fitted coefficients are identical across reruns on the same data.

This reproducibility has a regulatory benefit. Model validators can retrain the model independently and confirm the exact coefficients, while a gradient norm below 10⁻⁶ serves as a certificate of optimality. The team later tests a small neural network that gains about one percentage point of accuracy, but its nonconvex training produces different weights on each run, so the bank keeps the convex model for the decisions it must explain to auditors.