Proximal Operators
Many objectives split into a smooth part and a simple nonsmooth part: a loss plus an L1 penalty, a loss plus a constraint, a loss plus a nuclear norm. The proximal operator of the nonsmooth part is a small optimization problem, often with a closed-form solution, that plays the role a projection plays for constraints. Proximal gradient methods combine it with gradient steps and converge as fast as gradient descent on smooth problems.
Definition
The proximal operator of a convex function with parameter is
It finds a point that makes small without moving far from . Special cases:
| (no change) | |
| indicator of a convex set ( on , outside) | projection |
| soft threshold: | |
| (group lasso) | |
| (nuclear norm) | soft-threshold the singular values of |
import numpy as np
from scipy.optimize import minimize_scalar
soft = lambda v, k: np.sign(v) * np.maximum(np.abs(v) - k, 0)
t, lam = 0.5, 2.0
for v in (-3.0, -0.4, 0.8, 2.5):
brute = minimize_scalar(lambda x: lam * abs(x) + (x - v)**2 / (2 * t), bounds=(-10, 10), method="bounded", options={"xatol": 1e-10}).x
print(f"v = {v:5.1f}: soft threshold {round(float(soft(v, t * lam)), 3) + 0.0:6.3f}, numerical prox {round(brute, 3) + 0.0:6.3f}")v = -3.0: soft threshold -2.000, numerical prox -2.000
v = -0.4: soft threshold 0.000, numerical prox 0.000
v = 0.8: soft threshold 0.000, numerical prox 0.000
v = 2.5: soft threshold 1.500, numerical prox 1.500
Proximal gradient descent
To minimize with smooth (-smooth) and simple:
A gradient step on the smooth part, then a prox step on the rest. If is an indicator, this is projected gradient descent; if , it is gradient descent. The convergence rate is for convex problems, linear under strong convexity, exactly as for gradient descent, even though is not differentiable.
Example: non-negative, sparse deconvolution
import numpy as np
rng = np.random.default_rng(0)
n = 60
x_true = np.zeros(n); x_true[[10, 25, 40]] = [3.0, 2.0, 4.0] # a few spikes
kernel = np.exp(-0.5 * (np.arange(-6, 7) / 2.0)**2)
A = np.array([np.convolve(np.eye(n)[i], kernel, mode="same") for i in range(n)]).T
b = A @ x_true + 0.05 * rng.normal(size=n)
lam = 0.1; L = np.linalg.norm(A, 2)**2
x = np.zeros(n)
for k in range(3000):
v = x - A.T @ (A @ x - b) / L
x = np.maximum(v - lam / L, 0) # prox of lam*|x|_1 + indicator(x >= 0): one-sided soft threshold
print("largest recovered spikes at:", np.sort(np.argsort(x)[-3:]), " heights:", np.round(np.sort(x)[-3:], 2))
print("non-zeros:", int(np.sum(x > 1e-6)), "of", n)largest recovered spikes at: [10 25 40] heights: [1.89 2.84 3.77]
non-zeros: 9 of 60
The three spikes are found at the right positions. The L1 penalty shrinks their heights a little (the usual lasso bias) and leaves a few small non-zeros next to them.
The Moreau envelope
The optimal value of the prox problem, , is a smooth approximation of with gradient . For it is exactly the Huber function. Smoothing a nonsmooth function this way is another route to fast methods.
In software
- scikit-learn's
Lassouses coordinate descent, butSGDClassifier(penalty="l1")and many sparse-coding and compressed-sensing codes use proximal steps; theproxsuiteandpyproximallibraries collect proximal operators. - In deep learning, weight decay applied separately from the gradient update (AdamW) is a proximal step for (Adam and AdamW).
Exercises
Exercise 1: Prox of a quadratic
Derive for .
Answer
.
Solution
Set the gradient of to zero: .
Exercise 2: Prox of an indicator
Why is the prox of the indicator of a set the projection onto ?
Answer
The indicator is 0 on and outside, so the problem is .
Solution
Points outside have infinite cost, and on only the distance term remains; its minimizer is the closest point of , independent of .
Exercise 3: Group soft threshold (code)
Compute the prox of with at and at .
Answer
and .
Solution
import numpy as np
prox = lambda v, k: v * max(0.0, 1 - k / np.linalg.norm(v))
print(prox(np.array([3.0, 4.0]), 1.0), prox(np.array([0.3, 0.4]), 1.0))[2.4 3.2] [0. 0.]
The vector is shortened by 1 in length; if it is shorter than 1, the whole group is set to zero, which is how the group lasso removes entire groups of features.
Test yourself
The proximal operator of is…
- a projection onto the simplex
- soft thresholding
- hard thresholding
- the identity
Proximal gradient descent with = indicator of a convex set is…
- Newton's method
- projected gradient descent
- coordinate descent
- the simplex method
For convex with -smooth , proximal gradient converges at rate…
- , like gradient descent
- , like subgradients
- it does not converge
- quadratically