@@ -14,10 +14,11 @@ use `MoreThuente`, `HagerZhang` or `BackTracking`.
14
14
* `c_2 = 0.9` : second (strong) Wolfe condition
15
15
* `ρ = 2.0` : bracket growth
16
16
"""
17
- @with_kw struct StrongWolfe{T}
17
+ @with_kw struct StrongWolfe{T} <: AbstractLineSearch
18
18
c_1:: T = 1e-4
19
19
c_2:: T = 0.9
20
20
ρ:: T = 2.0
21
+ cache:: Union{Nothing,LineSearchCache{T}} = nothing
21
22
end
22
23
23
24
"""
@@ -49,9 +50,11 @@ Both `alpha` and `ϕ(alpha)` are returned.
49
50
"""
50
51
function (ls:: StrongWolfe )(ϕ, dϕ, ϕdϕ,
51
52
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)
53
55
54
56
zeroT = convert (T, 0 )
57
+ pushcache! (cache, zeroT, ϕ_0, dϕ_0)
55
58
56
59
# Step-sizes
57
60
a_0 = zeroT
@@ -71,17 +74,21 @@ function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
71
74
72
75
while a_i < a_max
73
76
ϕ_a_i = ϕ (a_i)
77
+ pushcache! (cache, a_i, ϕ_a_i)
74
78
75
79
# Test Wolfe conditions
76
80
if (ϕ_a_i > ϕ_0 + c_1 * a_i * dϕ_0) ||
77
81
(ϕ_a_i >= ϕ_a_iminus1 && i > 1 )
78
82
a_star = zoom (a_iminus1, a_i,
79
83
dϕ_0, ϕ_0,
80
- ϕ, dϕ, ϕdϕ)
84
+ ϕ, dϕ, ϕdϕ, cache )
81
85
return a_star, ϕ (a_star)
82
86
end
83
87
84
88
dϕ_a_i = dϕ (a_i)
89
+ if cache != = nothing
90
+ push! (cache. slopes, dϕ_a_i)
91
+ end
85
92
86
93
# Check condition 2
87
94
if abs (dϕ_a_i) <= - c_2 * dϕ_0
@@ -91,7 +98,7 @@ function (ls::StrongWolfe)(ϕ, dϕ, ϕdϕ,
91
98
# Check condition 3
92
99
if dϕ_a_i >= zeroT # FIXME untested!
93
100
a_star = zoom (a_i, a_iminus1,
94
- dϕ_0, ϕ_0, ϕ, dϕ, ϕdϕ)
101
+ dϕ_0, ϕ_0, ϕ, dϕ, ϕdϕ, cache )
95
102
return a_star, ϕ (a_star)
96
103
end
97
104
@@ -117,6 +124,7 @@ function zoom(a_lo::T,
117
124
ϕ,
118
125
dϕ,
119
126
ϕdϕ,
127
+ cache,
120
128
c_1:: Real = convert (T, 1 )/ 10 ^ 4 ,
121
129
c_2:: Real = convert (T, 9 )/ 10 ) where T
122
130
@@ -133,8 +141,10 @@ function zoom(a_lo::T,
133
141
iteration += 1
134
142
135
143
ϕ_a_lo, ϕprime_a_lo = ϕdϕ (a_lo)
144
+ pushcache! (cache, a_lo, ϕ_a_lo, ϕprime_a_lo)
136
145
137
146
ϕ_a_hi, ϕprime_a_hi = ϕdϕ (a_hi)
147
+ pushcache! (cache, a_hi, ϕ_a_hi, ϕprime_a_hi)
138
148
139
149
# Interpolate a_j
140
150
if a_lo < a_hi
@@ -150,6 +160,7 @@ function zoom(a_lo::T,
150
160
151
161
# Evaluate ϕ(a_j)
152
162
ϕ_a_j = ϕ (a_j)
163
+ pushcache! (cache, a_j, ϕ_a_j)
153
164
154
165
# Check Armijo
155
166
if (ϕ_a_j > ϕ_0 + c_1 * a_j * dϕ_0) ||
@@ -158,6 +169,9 @@ function zoom(a_lo::T,
158
169
else
159
170
# Evaluate ϕprime(a_j)
160
171
ϕprime_a_j = dϕ (a_j)
172
+ if cache != = nothing
173
+ push! (cache. slopes, ϕprime_a_j)
174
+ end
161
175
162
176
if abs (ϕprime_a_j) <= - c_2 * dϕ_0
163
177
return a_j
0 commit comments