Trust-Region Methods
Line-search methods pick a direction first and then a step length. Trust-region methods do it the other way round: decide how far the quadratic model can be trusted, a radius , and then find the best step within that radius. This handles indefinite Hessians naturally and is the basis of robust solvers for nonlinear least squares and large-scale problems.
The subproblem
At build the model (with the Hessian or an approximation) and solve
Because the region is bounded, the subproblem has a solution even if is indefinite. Its solution satisfies for some with : a shifted Newton step, where the shift grows as the radius shrinks.
Adjusting the radius
Compare the actual reduction with the reduction the model predicted:
| Meaning | Action | |
|---|---|---|
| model was poor | shrink (e.g. ) | |
| and step at the boundary | model was good and limiting | grow (e.g. ) |
| otherwise | fine | keep |
The step is accepted only if exceeds a small threshold such as .
The dogleg method
An exact subproblem solve needs eigenvalues. The dogleg step is a cheap approximation for positive definite : follow the steepest-descent direction to the model's minimizer along it (the Cauchy point), then turn toward the full Newton step, and stop where the path leaves the trust region.
import numpy as np
f = lambda p: (1 - p[0])**2 + 100 * (p[1] - p[0]**2)**2
grad = lambda p: np.array([-2 * (1 - p[0]) - 400 * p[0] * (p[1] - p[0]**2), 200 * (p[1] - p[0]**2)])
hess = lambda p: np.array([[2 - 400 * p[1] + 1200 * p[0]**2, -400 * p[0]], [-400 * p[0], 200.0]])
def dogleg(g, B, delta):
pB = -np.linalg.solve(B, g)
if np.linalg.norm(pB) <= delta:
return pB
pU = -(g @ g) / (g @ B @ g) * g
if np.linalg.norm(pU) >= delta:
return -delta * g / np.linalg.norm(g)
d = pB - pU # solve |pU + tau d| = delta for tau in [0, 1]
a, b, c = d @ d, 2 * pU @ d, pU @ pU - delta**2
tau = (-b + np.sqrt(b * b - 4 * a * c)) / (2 * a)
return pU + tau * d
x, delta = np.array([-1.2, 1.0]), 1.0
for k in range(1, 200):
g, B = grad(x), hess(x)
if np.linalg.norm(g) < 1e-10:
break
if np.any(np.linalg.eigvalsh(B) <= 0):
B = B + (1e-3 - np.linalg.eigvalsh(B).min()) * np.eye(2) # dogleg needs B > 0
p = dogleg(g, B, delta)
rho = (f(x) - f(x + p)) / -(g @ p + 0.5 * p @ B @ p)
if rho < 0.25:
delta /= 4
elif rho > 0.75 and np.isclose(np.linalg.norm(p), delta):
delta *= 2
if rho > 0.1:
x = x + p
print("iterations:", k - 1, " x =", np.round(x, 8))iterations: 25 x = [1. 1.]
Trust region versus line search
| Line search | Trust region | |
|---|---|---|
| order of decisions | direction, then length | length, then direction |
| indefinite Hessian | needs modification | handled by the subproblem |
| cost per iteration | one direction + a few evaluations | subproblem solve (dogleg, Steihaug-CG) |
| typical use | BFGS, L-BFGS | Newton with exact Hessians, least squares |
For large problems, the Steihaug-CG method solves the subproblem approximately with conjugate gradient, stopping at the boundary or at negative curvature.
import numpy as np
from scipy.optimize import minimize
f = lambda p: (1 - p[0])**2 + 100 * (p[1] - p[0]**2)**2
grad = lambda p: np.array([-2 * (1 - p[0]) - 400 * p[0] * (p[1] - p[0]**2), 200 * (p[1] - p[0]**2)])
hess = lambda p: np.array([[2 - 400 * p[1] + 1200 * p[0]**2, -400 * p[0]], [-400 * p[0], 200.0]])
for m in ("dogleg", "trust-ncg", "trust-exact"):
r = minimize(f, [-1.2, 1.0], jac=grad, hess=hess, method=m, options={"gtol": 1e-10})
print(f"{m:12s} iterations {r.nit:3d} x = {np.round(r.x, 6)}")dogleg iterations 25 x = [1. 1.]
trust-ncg iterations 30 x = [1. 1.]
trust-exact iterations 26 x = [1. 1.]
In software
- SciPy offers
trust-constr,trust-exact,trust-ncg,trust-krylovanddogleg;least_squaresuses a trust-region reflective method by default. - Levenberg-Marquardt (Gauss-Newton and Levenberg-Marquardt) is a trust-region method in disguise. In reinforcement learning, TRPO limits each policy update to a KL-divergence "trust region".
Exercises
Exercise 1: The ratio
The model predicted a decrease of 2 and actually dropped by 0.3. What happens to the step and the radius?
Answer
: the step is accepted (above ) and the radius shrinks.
Solution
, so , but so moves.
Exercise 2: The Cauchy point
For with , , find the minimizer along .
Answer
.
Solution
, and .
Exercise 3: A saddle point start (code)
Start SciPy's trust-exact on at the saddle region point . Where does it go?
Answer
To one of the two minima , here with .
Solution
import numpy as np
from scipy.optimize import minimize
f = lambda p: p[0]**2 - p[1]**2 + p[1]**4
g = lambda p: np.array([2 * p[0], -2 * p[1] + 4 * p[1]**3])
H = lambda p: np.array([[2.0, 0.0], [0.0, -2 + 12 * p[1]**2]])
r = minimize(f, [1.0, 0.01], jac=g, hess=H, method="trust-exact")
print(np.round(r.x, 4) + 0, round(r.fun, 4))[ 0. -0.7071] -0.25
The Hessian is indefinite near ; the trust-region subproblem uses that negative curvature to escape the saddle instead of being attracted to it.
Test yourself
In a trust-region method, if the actual reduction is much smaller than predicted, you…
- grow the radius
- shrink the radius
- switch to integer variables
- stop
Why can a trust-region method use an indefinite Hessian directly?
- The subproblem is bounded, so it always has a solution
- It ignores the Hessian
- It makes the function convex
- It only works with positive definite Hessians
The dogleg path goes from the origin to…
- the Cauchy point, then toward the Newton step
- the Newton step, then back
- a random point
- the boundary along