Skip to content

Commit cdf8730

Browse files
authored
Fix strong wolfe branch. (#152)
1 parent 8144541 commit cdf8730

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/strongwolfe.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
6464

6565
# Check condition 2
6666
if abs(dϕ_a_i) <= -c_2 * dϕ_0
67-
return a_i, dϕ_a_i
67+
return a_i, ϕ_a_i
6868
end
6969

7070
# Check condition 3

test/issues.jl

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# https://github.com/JuliaNLSolvers/LineSearches.jl/issues/151
2+
using LineSearches, LinearAlgebra, Test
3+
4+
A = randn(100, 100)
5+
x0 = randn(100)
6+
b = A*x0
7+
8+
# Objective function and gradient
9+
f(x) = .5*norm(A*x - b)^2
10+
g!(gvec, x) = (gvec .= A'*(A*x-b))
11+
fg!(gvec, x) = (g!(gvec, x); return f(x))
12+
13+
# Init
14+
x = 1f1*randn(100)
15+
gv = similar(x)
16+
17+
# Line search
18+
α0 = 1f-3
19+
ϕ0 = fg!(gv, x)
20+
s = -1*gv
21+
dϕ0 = dot(gv, s)
22+
println(ϕ0, ", ", dϕ0)
23+
24+
# Univariate line search functions
25+
ϕ(α) = f(x .+ α.*s)
26+
function (α)
27+
g!(gv, x .+ α.*s)
28+
return dot(gv, s)
29+
end
30+
function ϕdϕ(α)
31+
phi = fg!(gv, x .+ α.*s)
32+
dphi = dot(gv, s)
33+
return (phi, dphi)
34+
end
35+
36+
res = (StrongWolfe())(ϕ, dϕ, ϕdϕ, α0, ϕ0, dϕ0)
37+
@test res[2] > 0
38+
@test res[2] == ϕ(res[1])

0 commit comments

Comments
 (0)