LineSearches.jl icon indicating copy to clipboard operation
LineSearches.jl copied to clipboard

Corrected, improved and cleaned BackTracking

Open AlexandreMagueresse opened this issue 1 year ago • 4 comments

There is a small mistake in BackTracking.jl when computing α_tmp with the cubic interpolation: when the leading coefficient is close to zero, the expression of α_tmp misses a negative sign, and in the other case when the leading coefficient is not zero, the expression of α_tmp is prone to numerical cancelling.

Indeed, the interpolating polynomial reads $P(X) \doteq a X^3 + b X^2 + \phi'(0) X + \phi(0)$ for some coefficients $a$ and $b$ that are the solution to a linear system obtained from the conditions $P(\alpha_1) = \phi(\alpha_1)$ and $P(\alpha_2) = \phi(\alpha_2)$. The extrema of $P$ are reached when its derivative is zero, that is $P'(X) = 3 a X^2 + 2 b X + \phi'(0) = 0$.

  • If $a$ is equal or close to zero, the root of $P'$ is $$\alpha = -\dfrac{\phi'(0)}{2b}.$$ The negative sign is missing in the current code.
  • Otherwise, following Nocedal & Wright, the next candidate is given by $$\alpha = \dfrac{-b + \sqrt{b^2 - 3 \phi'(0) a}}{3 a}.$$ However, this formula is prone to numerical cancelling, so it should be safer to multiply by the conjugate quantity and rewrite $\alpha$ as $$\alpha = -\dfrac{\phi'(0)}{b + \sqrt{b^2 - 3 \phi'(0) a}}.$$ This expression can also be used when $a = 0$.

I also made some edits for clarity and performance:

  • The constructor now checks all the parameters and sets appropriate default values.
  • The assertion order in (2, 3) at l. 44 is now made in the constructor of BackTracking rather than in the line search function.
  • The initial step size is α_0, consistently with α_1 and α_2, and with the other implementations of (ls::BackTracking)(...). The variables ϕx_0 and ϕx_1 are now ϕ_1 and ϕ_2 respectively in the whole file. This is more consistent with the notation ϕ_0.
  • The computation of powers of α_1 is slightly improved, and ϕx_0 - ϕ_0 - dϕ_0 * α_1 is only evaluated once. I made similar edits for α_2. These are very minor improvements.

AlexandreMagueresse avatar Nov 13 '23 06:11 AlexandreMagueresse