TExcelTAD
Home › Optimization › Trust-Region Methods

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 Δk\Delta_k, 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 xk\mathbf{x}_k build the model mk(p)=fk+gkTp+12pTBkpm_k(\mathbf{p}) = f_k + \mathbf{g}_k^T\mathbf{p} + \frac{1}{2}\mathbf{p}^TB_k\mathbf{p} (with BkB_k the Hessian or an approximation) and solve

min⁡p mk(p)subject to∥p∥≤Δk\min_{\mathbf{p}} \ m_k(\mathbf{p}) \quad \text{subject to} \quad \lVert \mathbf{p} \rVert \le \Delta_k

Because the region is bounded, the subproblem has a solution even if BkB_k is indefinite. Its solution satisfies (Bk+λI)p=−gk(B_k + \lambda I)\mathbf{p} = -\mathbf{g}_k for some λ≥0\lambda \ge 0 with Bk+λI⪰0B_k + \lambda I \succeq 0: 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:

ρk=f(xk)−f(xk+pk)mk(0)−mk(pk)\rho_k = \frac{f(\mathbf{x}_k) - f(\mathbf{x}_k + \mathbf{p}_k)}{m_k(\mathbf{0}) - m_k(\mathbf{p}_k)}
ρk\rho_k Meaning Action
<0.25< 0.25 model was poor shrink Δ\Delta (e.g. Δ←Δ/4\Delta \leftarrow \Delta/4)
>0.75> 0.75 and step at the boundary model was good and limiting grow Δ\Delta (e.g. ×2\times 2)
otherwise fine keep Δ\Delta

The step is accepted only if ρk\rho_k exceeds a small threshold such as η=0.1\eta = 0.1.

The dogleg method

An exact subproblem solve needs eigenvalues. The dogleg step is a cheap approximation for positive definite BB: 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.

python · try it yourself
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 ff 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.

python · try it yourself
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-krylov and dogleg; least_squares uses 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 ff actually dropped by 0.3. What happens to the step and the radius?

Answer

ρ=0.15\rho = 0.15: the step is accepted (above η=0.1\eta = 0.1) and the radius shrinks.

Solution

0.3/2=0.15<0.250.3 / 2 = 0.15 < 0.25, so Δ←Δ/4\Delta \leftarrow \Delta/4, but 0.15>0.10.15 > 0.1 so x\mathbf{x} moves.

Exercise 2: The Cauchy point

For m(p)=gTp+12pTBpm(\mathbf{p}) = \mathbf{g}^T\mathbf{p} + \frac{1}{2}\mathbf{p}^TB\mathbf{p} with g=(2,0)\mathbf{g} = (2, 0), B=diag⁡(4,1)B = \operatorname{diag}(4, 1), find the minimizer along −g-\mathbf{g}.

Answer

p=(−0.5,0)\mathbf{p} = (-0.5, 0).

Solution

τ=gTggTBg=416=0.25\tau = \frac{\mathbf{g}^T\mathbf{g}}{\mathbf{g}^TB\mathbf{g}} = \frac{4}{16} = 0.25, and p=−0.25 g=(−0.5,0)\mathbf{p} = -0.25\,\mathbf{g} = (-0.5, 0).

Exercise 3: A saddle point start (code)

Start SciPy's trust-exact on f(x,y)=x2−y2+y4f(x, y) = x^2 - y^2 + y^4 at the saddle region point (1,0.01)(1, 0.01). Where does it go?

Answer

To one of the two minima (0,±12)(0, \pm\frac{1}{\sqrt{2}}), here (0,−0.7071)(0, -0.7071) with f=−0.25f = -0.25.

Solution
python · try it yourself
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 y=0y = 0; 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…

  1. grow the radius
  2. shrink the radius
  3. switch to integer variables
  4. stop

Why can a trust-region method use an indefinite Hessian directly?

  1. The subproblem is bounded, so it always has a solution
  2. It ignores the Hessian
  3. It makes the function convex
  4. It only works with positive definite Hessians

The dogleg path goes from the origin to…

  1. the Cauchy point, then toward the Newton step
  2. the Newton step, then back
  3. a random point
  4. the boundary along +g+\mathbf{g}