@@ -14,10 +14,11 @@ use `MoreThuente`, `HagerZhang` or `BackTracking`.
1414* `c_2 = 0.9` : second (strong) Wolfe condition
1515* `ρ = 2.0` : bracket growth
1616"""
17- @with_kw struct StrongWolfe{T}
17+ @with_kw struct StrongWolfe{T} <: AbstractLineSearch
1818 c_1:: T = 1e-4
1919 c_2:: T = 0.9
2020 ρ:: T = 2.0
21+ cache:: Union{Nothing,LineSearchCache{T}} = nothing
2122end
2223
2324"""
@@ -49,9 +50,11 @@ Both `alpha` and `ϕ(alpha)` are returned.
4950"""
5051function (ls:: StrongWolfe )(ϕ, dϕ, ϕdϕ,
5152 alpha0:: T , ϕ_0, dϕ_0) where T<: Real
52- @unpack c_1, c_2, ρ = ls
53+ @unpack c_1, c_2, ρ, cache = ls
54+ emptycache! (cache)
5355
5456 zeroT = convert (T, 0 )
57+ pushcache! (cache, zeroT, ϕ_0, dϕ_0)
5558
5659 # Step-sizes
5760 a_0 = zeroT
@@ -71,17 +74,21 @@ function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
7174
7275 while a_i < a_max
7376 ϕ_a_i = ϕ (a_i)
77+ pushcache! (cache, a_i, ϕ_a_i)
7478
7579 # Test Wolfe conditions
7680 if (ϕ_a_i > ϕ_0 + c_1 * a_i * dϕ_0) ||
7781 (ϕ_a_i >= ϕ_a_iminus1 && i > 1 )
7882 a_star = zoom (a_iminus1, a_i,
7983 dϕ_0, ϕ_0,
80- ϕ, dϕ, ϕdϕ)
84+ ϕ, dϕ, ϕdϕ, cache )
8185 return a_star, ϕ (a_star)
8286 end
8387
8488 dϕ_a_i = dϕ (a_i)
89+ if cache != = nothing
90+ push! (cache. slopes, dϕ_a_i)
91+ end
8592
8693 # Check condition 2
8794 if abs (dϕ_a_i) <= - c_2 * dϕ_0
@@ -91,7 +98,7 @@ function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
9198 # Check condition 3
9299 if dϕ_a_i >= zeroT # FIXME untested!
93100 a_star = zoom (a_i, a_iminus1,
94- dϕ_0, ϕ_0, ϕ, dϕ, ϕdϕ)
101+ dϕ_0, ϕ_0, ϕ, dϕ, ϕdϕ, cache )
95102 return a_star, ϕ (a_star)
96103 end
97104
@@ -117,6 +124,7 @@ function zoom(a_lo::T,
117124 ϕ,
118125 dϕ,
119126 ϕdϕ,
127+ cache,
120128 c_1:: Real = convert (T, 1 )/ 10 ^ 4 ,
121129 c_2:: Real = convert (T, 9 )/ 10 ) where T
122130
@@ -133,8 +141,10 @@ function zoom(a_lo::T,
133141 iteration += 1
134142
135143 ϕ_a_lo, ϕprime_a_lo = ϕdϕ (a_lo)
144+ pushcache! (cache, a_lo, ϕ_a_lo, ϕprime_a_lo)
136145
137146 ϕ_a_hi, ϕprime_a_hi = ϕdϕ (a_hi)
147+ pushcache! (cache, a_hi, ϕ_a_hi, ϕprime_a_hi)
138148
139149 # Interpolate a_j
140150 if a_lo < a_hi
@@ -150,6 +160,7 @@ function zoom(a_lo::T,
150160
151161 # Evaluate ϕ(a_j)
152162 ϕ_a_j = ϕ (a_j)
163+ pushcache! (cache, a_j, ϕ_a_j)
153164
154165 # Check Armijo
155166 if (ϕ_a_j > ϕ_0 + c_1 * a_j * dϕ_0) ||
@@ -158,6 +169,9 @@ function zoom(a_lo::T,
158169 else
159170 # Evaluate ϕprime(a_j)
160171 ϕprime_a_j = dϕ (a_j)
172+ if cache != = nothing
173+ push! (cache. slopes, ϕprime_a_j)
174+ end
161175
162176 if abs (ϕprime_a_j) <= - c_2 * dϕ_0
163177 return a_j
0 commit comments