Newton's method jumps to the stationary point of a local quadratic model, which may be a maximum or a saddle when the Hessian is indefinite. Implement the Newton step, its damped (Tikhonov) version and a trust-region loop that adapts the damping (Murphy, Probabilistic Machine Learning).
newton_step(g, H): return d=−H−1g (solve, do not invert). Accept a 1-D gradient of length D and a D×D Hessian; return a 1-D array.
damped_step(g, H, lam): return δ=−(H+λI)−1g.
trust_region_minimize(f, grad, hess, x0, lam0=1.0, n_iter=100, tol=1e-8): start at x= x0 (as a 1-D float array) with λ= lam0. Each iteration:
- Compute g and H at x. Stop if ∥g∥2<
tol.
- While the smallest eigenvalue of H+λI is ≤10−12, multiply λ by 10.
- δ =
damped_step(g, H, lam). Predicted reduction pred=−(g⊤δ+21δ⊤Hδ), actual reduction act=f(x)−f(x+δ), ratio ρ=act/pred.
- If ρ>0.75 set λ←max(λ/3,10−12); else if ρ<0.25 set λ←4λ.
- If ρ>0 accept: x←x+δ.
Return (x, n_accepted) with the number of accepted steps.