Using Python, develop a line search algorithm (i.e. Algorithm 4.3 and 4.4) that given a direction p, your algorithm returns the optimal point along that line (i.e. the optimal step length along p).
Naorith
Bracketing phase for the line search algorithm
Pinpoint function for the line search algorithm
Inputs: init > 0: Initial step size o: computed in outer routine, pass in to save function call 0 < 1 < I: Sufficient decrease factor 1 < 2 < 1: Sufficient curvature factor > 1: Step size increase factor (e.g. = 2) Outputs: *: Acceptable step size (satisfies the strong Wolfe conditions)
Inputs: ow: Interval endpoint with lower function value high: Interval endpoint with higher function value o, low, high, : Computed in outer routine
0 < 1 < I1: Sufficient decrease factor 1 < 2 < 1: Sufficient curvature factor Outputs: *: Step size satisfying strong Wolfe conditions 1=0 Define initial bracket 2 = init 0 = 1 = while true do = Used in pinpoint Find p in interval (low, high) Use interpolation (see Section 4.3.3) first = true Uses (low- (high, and from at least one endpoint while true do (dx) = d Also evaluate (, if derivatives available 2 = (2) Compute on this line if user provides derivatives if p > o + 1p or p > low then if [2 > + 12] or [not first and 2 > ] then high = p ufryo uosejodaqu} Digne j pue ad vhot( aepdn osjy *= pinpoint(,2,...) 1 low, 2 high else return * =(ap) If not already computed if | 2 then end if = (2) If not computed previously * = p Step is acceptable; exit line search return if || 2 then else if p (high ow) 0 then return * = 2 else if 0 then Bracketed minimum high = low *= pinpoint(2,1,...) Find acceptable step, 2 low, 1 high end if return * low = p else Slope is negative end if k = k + 1 1 = 2 end while 2 = 2 Increase step end if first = false end while