@@ -173,6 +173,57 @@ function update_stopping_criterion!(c::StopAfterIteration, ::Val{:MaxIteration},
173
173
return c
174
174
end
175
175
176
+ """
177
+ StopWhenSubgradientNormLess <: StoppingCriterion
178
+
179
+ A stopping criterion based on the current subgradient norm.
180
+
181
+ # Constructor
182
+
183
+ StopWhenSubgradientNormLess(ε::Float64)
184
+
185
+ Create a stopping criterion with threshold `ε` for the subgradient, that is, this criterion
186
+ indicates to stop when [`get_subgradient`](@ref) returns a subgradient vector of norm less than `ε`.
187
+ """
188
+ mutable struct StopWhenSubgradientNormLess <: StoppingCriterion
189
+ threshold:: Float64
190
+ reason:: String
191
+ StopWhenSubgradientNormLess (ε:: Float64 ) = new (ε, " " )
192
+ end
193
+ function (c:: StopWhenSubgradientNormLess )(
194
+ mp:: AbstractManoptProblem , s:: AbstractManoptSolverState , i:: Int
195
+ )
196
+ M = get_manifold (mp)
197
+ (i == 0 ) && (c. reason = " " ) # reset on init
198
+ if (norm (M, get_iterate (s), get_subgradient (s)) < c. threshold) && (i > 0 )
199
+ c. reason = " The algorithm reached approximately critical point after $i iterations; the subgradient norm ($(norm (M,get_iterate (s),get_subgradient (s))) ) is less than $(c. threshold) .\n "
200
+ return true
201
+ end
202
+ return false
203
+ end
204
+ function status_summary (c:: StopWhenSubgradientNormLess )
205
+ has_stopped = length (c. reason) > 0
206
+ s = has_stopped ? " reached" : " not reached"
207
+ return " |subgrad f| < $(c. threshold) : $s "
208
+ end
209
+ indicates_convergence (c:: StopWhenSubgradientNormLess ) = true
210
+ function show (io:: IO , c:: StopWhenSubgradientNormLess )
211
+ return print (
212
+ io, " StopWhenSubgradientNormLess($(c. threshold) )\n $(status_summary (c)) "
213
+ )
214
+ end
215
+ """
216
+ update_stopping_criterion!(c::StopWhenSubgradientNormLess, :MinSubgradNorm, v::Float64)
217
+
218
+ Update the minimal subgradient norm when an algorithm shall stop
219
+ """
220
+ function update_stopping_criterion! (
221
+ c:: StopWhenSubgradientNormLess , :: Val{:MinSubgradNorm} , v:: Float64
222
+ )
223
+ c. threshold = v
224
+ return c
225
+ end
226
+
176
227
"""
177
228
StopWhenChangeLess <: StoppingCriterion
178
229
0 commit comments