Smoothness, Strong Convexity and Conditioning
Convexity tells you that a method will find the minimum. Two more numbers tell you how fast: the smoothness constant bounds how sharply the function curves up, and the strong convexity constant guarantees it curves up at least a little. Their ratio, the condition number, predicts the speed of almost every first-order method.
Definitions
A differentiable is -smooth if its gradient is -Lipschitz, . For twice-differentiable this means all Hessian eigenvalues are at most . It gives a quadratic upper bound:
is -strongly convex () if is convex, i.e. all Hessian eigenvalues are at least . It gives a quadratic lower bound:
For a quadratic , and , and the condition number is .
What the upper bound buys: the step
Minimizing the upper bound over gives , the gradient step with step size , and guarantees a decrease:
With strong convexity as well, the distance to the minimum shrinks by at least the factor per step. Since , each extra digit of accuracy costs a number of steps proportional to .
import numpy as np
def gd_steps(kappa, tol=1e-8):
Q = np.diag([1.0, kappa]) # mu = 1, L = kappa
x = np.array([1.0, 1.0]); f0 = 0.5 * x @ Q @ x
for k in range(1, 10**6):
x = x - (1 / kappa) * (Q @ x)
if 0.5 * x @ Q @ x < tol * f0:
return k
for kappa in (2, 10, 100, 1000):
print(f"kappa = {kappa:5d}: {gd_steps(kappa):6d} steps to reduce f by 1e8")kappa = 2: 13 steps to reduce f by 1e8
kappa = 10: 77 steps to reduce f by 1e8
kappa = 100: 687 steps to reduce f by 1e8
kappa = 1000: 5754 steps to reduce f by 1e8
The step count grows in proportion to .
Seeing conditioning
Level sets of a well-conditioned function are round; of an ill-conditioned one, long thin ellipses. Gradient descent steps across the narrow direction and barely moves along the long one, zig-zagging. Rescaling the variables (preconditioning) makes the level sets rounder:
import numpy as np
Q = np.array([[50.0, 0.0], [0.0, 1.0]])
print("kappa before:", np.linalg.cond(Q))
D = np.diag(1 / np.sqrt(np.diag(Q))) # diagonal (Jacobi) scaling, x = D z
print("kappa after scaling:", np.linalg.cond(D @ Q @ D))
Q2 = np.array([[50.0, 7.0], [7.0, 1.0]]) # a rotated, correlated version
D2 = np.diag(1 / np.sqrt(np.diag(Q2)))
print("correlated: before", round(np.linalg.cond(Q2), 1), " after diagonal scaling", round(np.linalg.cond(D2 @ Q2 @ D2), 1))kappa before: 50.0
kappa after scaling: 1.0
correlated: before 2599.0 after diagonal scaling 198.0
Diagonal scaling fixes axis-aligned stretching completely but cannot remove strong correlation between variables; that needs a full preconditioner such as the Hessian itself, which is Newton's Method.
Estimating in practice
For least squares the Hessian is , so , computable with a few power iterations. For general functions, backtracking line search (Line Search and Backtracking) finds a usable step without knowing .
In software
- Feature standardization (
StandardScaler) before training is preconditioning: it lowers so gradient methods converge faster. - Batch normalization and Adam's per-coordinate scaling are learned or adaptive diagonal preconditioners (Adam and AdamW).
np.linalg.condreports of a matrix; a huge value warns that both solving and optimizing will be hard.
Exercises
Exercise 1: Read off and
For , find , , and the safe step .
Answer
, , , step .
Solution
The Hessian is , so and .
Exercise 2: Not strongly convex
Is strongly convex? Is it -smooth on ?
Answer
Neither.
Solution
is 0 at , so no works, and it grows without bound, so no works. Gradient descent on slows down near 0 because the curvature vanishes there.
Exercise 3: Lipschitz constant of least squares (code)
Compute for with in two ways.
Answer
.
Solution
import numpy as np
A = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
print(round(float(np.linalg.eigvalsh(A.T @ A).max()), 4), round(float(np.linalg.norm(A, 2)**2), 4))90.7355 90.7355
The largest eigenvalue of equals the squared largest singular value of .
Test yourself
For with , the condition number is…
With an -smooth function, the step size that minimizes the quadratic upper bound is…
Doubling the condition number of a strongly convex quadratic roughly… the number of gradient descent steps.
- halves
- does not change
- doubles
- squares