LineSearches.jl
LineSearches.jl copied to clipboard
Corrected, improved and cleaned BackTracking
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)
atl. 44
is now made in the constructor ofBackTracking
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.