Build the quasi-Newton machinery of Murphy's Probabilistic Machine Learning. Notation: st=θt+1−θt, yt=gt+1−gt, ρt=1/(yt⊤st).
bfgs_inverse_update(C, s, y): the BFGS update of an inverse-Hessian approximation, returned as a new array:
C+=(I−ρsy⊤)C(I−ρys⊤)+ρss⊤
lbfgs_direction(g, s_hist, y_hist): return −Hg, where H is the inverse-Hessian approximation obtained by starting from H0=γI with γ=sk⊤yk/(yk⊤yk) for the most recent pair (sk,yk) and applying the update above for every stored pair from oldest to newest. Do it in O(MD) with the two-loop recursion; never form a D×D matrix. With empty histories return −g.
wolfe_line_search(f, grad, x, d, c1=1e-4, c2=0.9, max_iter=60): weak-Wolfe bisection. Let ϕ0=f(x) and ϕ0′=d⊤∇f(x). Start with lo=0, hi=∞, η=1 and repeat at most max_iter times:
- if f(x+ηd)>ϕ0+c1ηϕ0′: set hi=η and η=(lo+hi)/2;
- else if d⊤∇f(x+ηd)<c2ϕ0′: set lo=η, then η=2lo if hi=∞, otherwise η=(lo+hi)/2;
- else stop.
Return η.
minimize_lbfgs(f, grad, x0, m=5, max_iter=200, tol=1e-8): starting at x0, for each iteration: stop if ∥g∥2< tol; otherwise take d from lbfgs_direction, η from wolfe_line_search, move to x+ηd, and store the pair (s,y) only if y⊤s>10−12, keeping the m most recent pairs. Return (x, n_iter) where n_iter is the number of steps taken.