-
Notifications
You must be signed in to change notification settings - Fork 38
Corrected, improved and cleaned BackTracking #172
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,111 +8,199 @@ there exists a factor ρ = ρ(c₁) such that α' ≦ ρ α. | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| This is a modification of the algorithm described in Nocedal Wright (2nd ed), Sec. 3.5. | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| @with_kw struct BackTracking{TF, TI} | ||||||||||||||||||||||||
| c_1::TF = 1e-4 | ||||||||||||||||||||||||
| ρ_hi::TF = 0.5 | ||||||||||||||||||||||||
| ρ_lo::TF = 0.1 | ||||||||||||||||||||||||
| iterations::TI = 1_000 | ||||||||||||||||||||||||
| order::TI = 3 | ||||||||||||||||||||||||
| maxstep::TF = Inf | ||||||||||||||||||||||||
| struct BackTracking{TF,TI} | ||||||||||||||||||||||||
| c_1::TF | ||||||||||||||||||||||||
| ρ_hi::TF | ||||||||||||||||||||||||
| ρ_lo::TF | ||||||||||||||||||||||||
| iterations::TI | ||||||||||||||||||||||||
| order::TI | ||||||||||||||||||||||||
| maxstep::TF | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| BackTracking{TF}(args...; kwargs...) where TF = BackTracking{TF,Int}(args...; kwargs...) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function (ls::BackTracking)(df::AbstractObjective, x::AbstractArray{T}, s::AbstractArray{T}, | ||||||||||||||||||||||||
| α_0::Tα = real(T)(1), x_new::AbstractArray{T} = similar(x), ϕ_0 = nothing, dϕ_0 = nothing, alphamax = convert(real(T), Inf)) where {T, Tα} | ||||||||||||||||||||||||
| ϕ, dϕ = make_ϕ_dϕ(df, x_new, x, s) | ||||||||||||||||||||||||
| function BackTracking(args...; kwargs...) | ||||||||||||||||||||||||
| BackTracking{Float64}(args...; kwargs...) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if ϕ_0 == nothing | ||||||||||||||||||||||||
| ϕ_0 = ϕ(Tα(0)) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| if dϕ_0 == nothing | ||||||||||||||||||||||||
| dϕ_0 = dϕ(Tα(0)) | ||||||||||||||||||||||||
| function BackTracking{TF}(args...; kwargs...) where {TF} | ||||||||||||||||||||||||
| BackTracking{TF,Int}(args...; kwargs...) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function BackTracking{TF,TI}(; | ||||||||||||||||||||||||
| c_1::Real=1.0e-4, ρ_hi::Real=0.5, ρ_lo::Real=0.1, | ||||||||||||||||||||||||
| iterations::Integer=1_000, order::Integer=3, maxstep::Real=Inf | ||||||||||||||||||||||||
| ) where {TF,TI} | ||||||||||||||||||||||||
| # Impose 0 < ρ_hi < 1 | ||||||||||||||||||||||||
| if (ρ_hi <= 0) || (ρ_hi >= 1) | ||||||||||||||||||||||||
| ρ_hi = 1 / 2 | ||||||||||||||||||||||||
| msg = """ | ||||||||||||||||||||||||
| The upper bound for the backtracking factor has to lie between | ||||||||||||||||||||||||
| 0 and 1. | ||||||||||||||||||||||||
| Setting ρ_hi = $(ρ_hi). | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| warn(msg) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| 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.
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.