-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrected, improved and cleaned BackTracking #172
base: master
Are you sure you want to change the base?
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. |
ρ_lo::TF | ||
iterations::TI | ||
order::TI | ||
maxstep::TF | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the rest of the package uses 4-space indentation, this should too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing this out. The last commit solves this issue.
src/backtracking.jl
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.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$ .
I also made some edits for clarity and performance:
order in (2, 3)
atl. 44
is now made in the constructor ofBackTracking
rather than in the line search function.α_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
.α_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.