Corrected, improved and cleaned BackTracking#172
Conversation
|
Thank you for a thorough explanation and sorry for missing this in a very busy fall for me. I'll review it. The diff is a bit hard to follow because everything was done in one commit and a lot of lines change place (from line search time to constructor time), but I'll do my best :) |
|
I'm sure this is not always easy, but maybe you can "work your way backwards" on an example to generate a test? I'm not going to put this as a hard requirement, but .. if you had an idea for a good test set. I know testing iterative methods can be difficult for corner cases, but maybe you could come up with a case where it hit it in the first iteration? |
|
Hi @pkofod and thank you for taking a look at my pull request. I have been trying to come up with an example in which the current implementation and my revision of The current implementation finds a step of |
|
Hi @AlexandreMagueresse ! I have not forgotten you. I will review this and @timholy 's other PR (you're also both welcome to give comments on each others' PR :) ) I just had a busy week and will have a busy weekend, but I promise to get back to you soon. |
| iterations::TI | ||
| order::TI | ||
| maxstep::TF | ||
| end |
There was a problem hiding this comment.
Since the rest of the package uses 4-space indentation, this should too.
There was a problem hiding this comment.
Thank you for pointing this out. The last commit solves this issue.
| msg = """ | ||
| The upper bound for the backtracking factor has to lie between | ||
| 0 and 1. | ||
| Setting ρ_hi = $(ρ_hi). | ||
| """ | ||
| warn(msg) |
There was a problem hiding this comment.
| msg = """ | |
| The upper bound for the backtracking factor has to lie between | |
| 0 and 1. | |
| Setting ρ_hi = $(ρ_hi). | |
| """ | |
| warn(msg) | |
| @warn """ | |
| The upper bound for the backtracking factor has to lie between | |
| 0 and 1. | |
| Setting ρ_hi = $(ρ_hi). | |
| """ |
warn isn't a function anymore? Did you test this? With @warn you can use @test_logs.
Same issue below. These really need tests.
There was a problem hiding this comment.
I have indeed not tested these checks. We could write some more tests to cover them. I replaced warn with @warn in my last commit.
|
|
||
| # Evaluate f(x) at proposed position | ||
| ϕx_0, ϕx_1 = ϕx_1, ϕ(α_2) | ||
| # Ensure termination |
There was a problem hiding this comment.
Hm, I think this will cause the whole optimize call to fail with this error in Optim.jl, right?
There was a problem hiding this comment.
Indeed. This is already what happens in the current implementation. I just moved current lines 77-81 at the end of the loop.
There is a small mistake in
BackTracking.jlwhen computingα_tmpwith the cubic interpolation: when the leading coefficient is close to zero, the expression ofα_tmpmisses a negative sign, and in the other case when the leading coefficient is not zero, the expression ofα_tmpis 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$ .
I also made some edits for clarity and performance:
order in (2, 3)atl. 44is now made in the constructor ofBackTrackingrather than in the line search function.α_0, consistently withα_1andα_2, and with the other implementations of(ls::BackTracking)(...). The variablesϕx_0andϕx_1are nowϕ_1andϕ_2respectively in the whole file. This is more consistent with the notationϕ_0.α_1is slightly improved, andϕx_0 - ϕ_0 - dϕ_0 * α_1is only evaluated once. I made similar edits forα_2. These are very minor improvements.