Skip to content

Commit 57d805b

Browse files
kbarrospkofod
andauthored
At linesearchmax, select alpha with minimum value (#185)
* At linesearchmax, select alpha with minimum value * Add test * Update test/captured.jl Co-authored-by: Patrick Kofod Mogensen <[email protected]> --------- Co-authored-by: Patrick Kofod Mogensen <[email protected]>
1 parent fac77e6 commit 57d805b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/hagerzhang.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,9 @@ function (ls::HagerZhang)(ϕ, ϕdϕ,
315315
iter += 1
316316
end
317317

318+
best_alpha = alphas[argmin(values)]
318319
throw(LineSearchException("Linesearch failed to converge, reached maximum iterations $(linesearchmax).",
319-
alphas[ia]))
320-
321-
320+
best_alpha))
322321
end
323322

324323
# Check Wolfe & approximate Wolfe

test/captured.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ end
3333
α, val = hz(fdf.f, fdf.fdf, 1.0, fdf.fdf(0.0)...)
3434
@test val <= minimum(tc)
3535
end
36+
37+
@testset "PR#185" begin
38+
ϕ(α) = 1/+1)
39+
(α) = -1/+1)^2
40+
ϕdϕ(α) = ϕ(α), (α)
41+
42+
α0 = 1.0
43+
ϕ0 = ϕ(0.0)
44+
dϕ0 = (0.0)
45+
46+
_error_msg = @test_throws LineSearchException (HagerZhang())(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0)
47+
@test _error_msg.value.alpha > α0 # Should be something gigantic like 1e34
48+
end

0 commit comments

Comments
 (0)