Skip to content

Commit edafc95

Browse files
authored
Update TerminationCode names and add ObjectiveNotFinite (#1156)
* Update TerminationCode names and add ObjectiveNotFinite * Update types.jl
1 parent a4fc81d commit edafc95

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/multivariate/optimize/optimize.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,18 @@ function _termination_code(d, gres, state, stopped_by, options)
182182
if state isa NelderMeadState && gres <= options.g_abstol
183183
TerminationCode.NelderMeadCriterion
184184
elseif !(state isa NelderMeadState) && gres <= options.g_abstol
185-
TerminationCode.FirstOrder
185+
TerminationCode.GradientNorm
186186
elseif (iszero(options.x_abstol) && x_abschange(state) <= options.x_abstol) ||
187187
(iszero(options.x_reltol) && x_relchange(state) <= options.x_reltol)
188188
TerminationCode.NoXChange
189189
elseif (iszero(options.f_abstol) && f_abschange(d, state) <= options.f_abstol) ||
190190
(iszero(options.f_reltol) && f_relchange(d, state) <= options.f_reltol)
191-
TerminationCode.NoFChange
191+
TerminationCode.NoObjectiveChange
192192
elseif x_abschange(state) <= options.x_abstol || x_relchange(state) <= options.x_reltol
193193
TerminationCode.SmallXChange
194194
elseif f_abschange(d, state) <= options.f_abstol ||
195195
f_relchange(d, state) <= options.f_reltol
196-
TerminationCode.SmallFChange
196+
TerminationCode.SmallObjectiveChange
197197
elseif stopped_by.ls_failed
198198
TerminationCode.FailedLinesearch
199199
elseif stopped_by.callback
@@ -203,13 +203,15 @@ function _termination_code(d, gres, state, stopped_by, options)
203203
elseif stopped_by.time_limit
204204
TerminationCode.Time
205205
elseif stopped_by.f_limit_reached
206-
TerminationCode.FCall
206+
TerminationCode.ObjectiveCalls
207207
elseif stopped_by.g_limit_reached
208-
TerminationCode.Gcall
208+
TerminationCode.GradientCalls
209209
elseif stopped_by.h_limit_reached
210-
TerminationCode.HCall
210+
TerminationCode.HessianCalls
211211
elseif stopped_by.f_increased
212-
TerminationCode.FIncreased
212+
TerminationCode.ObjectiveIncreased
213+
elseif f_calls(d) > 0 && !isfinite(value(d))
214+
TerminationCode.GradientNotFinite
213215
elseif g_calls(d) > 0 && !all(isfinite, gradient(d))
214216
TerminationCode.GradientNotFinite
215217
elseif h_calls(d) > 0 && !(d isa TwiceDifferentiableHV) && !all(isfinite, hessian(d))

src/types.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ using EnumX
204204
"Nelder-Mead simplex converged."
205205
NelderMeadCriterion
206206
"First (partial) derivative had a magnitude below the prescribed tolerance."
207-
FirstOrder
207+
GradientNorm
208208
"The change in optimization variables was zero (the tolerance was not set by the user)."
209209
NoXChange
210210
"The change in the objective was zero (the tolerance was not set by the user)."
211-
NoFChange
211+
NoObjectiveChange
212212
"The change in the optimization variables was below the prescribed tolerance."
213213
SmallXChange
214214
"The change in the objective was below the prescribed tolerance."
215-
SmallFChange
215+
SmallObjectiveChange
216216
"The line search failed to find a point that decreased the objective."
217217
FailedLinesearch
218218
"User callback returned `true`."
@@ -222,13 +222,15 @@ using EnumX
222222
"Time budget was exceeded."
223223
Time
224224
"Objective function evaluations exceeded the maximum number allowed."
225-
FCall
225+
ObjectiveCalls
226226
"Gradient evaluations exceeded the maximum number allowed."
227-
Gcall
227+
GradientCalls
228228
"Hessian evaluations exceeded the maximum number allowed."
229-
HCall
229+
HessianCalls
230230
"Objective function value increased."
231-
FIncreased
231+
ObjectiveIncreased
232+
"Objective function was not finite"
233+
ObjectiveNotFinite
232234
"Gradient was not finite"
233235
GradientNotFinite
234236
"Hessian was not finite"

test/general/api.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161

162162

163163
resgterm = optimize(f, g!, initial_x, BFGS(), Optim.Options(g_tol = 1e12))
164-
Optim.termination_code(resgterm) == Optim.TerminationCode.FirstOrder
164+
Optim.termination_code(resgterm) == Optim.TerminationCode.GradientNorm
165165

166166
resx0term = optimize(
167167
f,

0 commit comments

Comments
 (0)