Skip to content

Commit 3e3d33e

Browse files
authored
As default use a minimum trust region radius of 0 (#1219)
1 parent 432fc63 commit 3e3d33e

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/multivariate/optimize/optimize.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function optimize(
5555
stopped, stopped_by_callback, stopped_by_time_limit = false, false, false
5656
f_limit_reached, g_limit_reached, h_limit_reached = false, false, false
5757
x_converged, f_converged, f_increased, counter_f_tol = false, false, false, 0
58+
small_trustregion_radius = false
5859

5960
g_converged, stopped = initial_convergence(state, options)
6061
converged = g_converged || stopped
@@ -121,6 +122,7 @@ function optimize(
121122
# because something is wrong. Wrong gradients or a non-differentiability
122123
# at the solution could be explanations.
123124
if state.delta method.delta_min
125+
small_trustregion_radius = true
124126
stopped = true
125127
end
126128
end
@@ -150,6 +152,7 @@ function optimize(
150152
f_increased = f_incr_pick,
151153
ls_failed = !ls_success,
152154
iterations = iteration == options.iterations,
155+
small_trustregion_radius,
153156
)
154157

155158
termination_code =
@@ -228,6 +231,8 @@ function _termination_code(d, gres, state, stopped_by, options)
228231
TerminationCode.GradientNotFinite
229232
elseif hasproperty(state, :H_x) && !all(isfinite, state.H_x)
230233
TerminationCode.HessianNotFinite
234+
elseif stopped_by.small_trustregion_radius
235+
TerminationCode.SmallTrustRegionRadius
231236
else
232237
TerminationCode.NotImplemented
233238
end

src/multivariate/solvers/constrained/fminbox.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ function optimize(
644644
x_converged = _x_converged,
645645
f_converged = _f_converged,
646646
g_converged = _g_converged,
647+
small_trustregion_radius = false,
647648
)
648649
termination_code = _termination_code(df, g_residual(g), BoxState(x, f_x, x_previous, f_x_previous), stopped_by, options)
649650

src/multivariate/solvers/second_order/newton_trust_region.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ NewtonTrustRegion(; initial_delta = 1.0,
269269
The constructor has 7 keywords:
270270
* `initial_delta`, the initial trust region radius. Defaults to `1.0`.
271271
* `delta_hat`, the largest allowable trust region radius. Defaults to `100.0`.
272-
* `delta_min`, the smallest allowable trust region radius. Optimization halts if the updated radius is smaller than this value. Defaults to `sqrt(eps(Float64))`.
272+
* `delta_min`, the smallest allowable trust region radius. Optimization halts if the updated radius is less than or equal to this value. Defaults to `0.0`.
273273
* `eta`, when the ratio of actual and predicted reduction is greater than `eta`, accept the step. Defaults to `0.1`.
274274
* `rho_lower`, when the ratio of actual and predicted reduction is less than `rho_lower`, shrink the trust region. Defaults to `0.25`.
275275
* `rho_upper`, when the ratio of actual and predicted reduction is greater than `rho_upper` and the proposed step is at the boundary of the trust region, grow the trust region. Defaults to `0.75`.
@@ -291,7 +291,7 @@ trust-region methods in practice.
291291
function NewtonTrustRegion(;
292292
initial_delta::Real = 1.0,
293293
delta_hat::Real = 100.0,
294-
delta_min::Real = sqrt(eps(Float64)),
294+
delta_min::Real = 0.0,
295295
eta::Real = 0.1,
296296
rho_lower::Real = 0.25,
297297
rho_upper::Real = 0.75,

src/types.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ const OptimizationTrace{Tf,T} = Vector{OptimizationState{Tf,T}}
271271
GradientNotFinite
272272
"Hessian was not finite"
273273
HessianNotFinite
274+
"The trust region radius was less than or equal to the minimum radius allowed."
275+
SmallTrustRegionRadius
274276
"For algorithms where the TerminationCode is not yet implemented."
275277
NotImplemented
276278
end

test/multivariate/solvers/second_order/newton_trust_region.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,23 @@ Random.seed!(3288)
249249
)
250250
end
251251

252-
@test_throws DomainError Optim.optimize(
252+
@test_throws DomainError NewtonTrustRegion(delta_min = -1.0)
253+
@test iszero(NewtonTrustRegion().delta_min)
254+
255+
res = Optim.optimize(
253256
t -> -ll(t[1]),
254257
[2.1],
255-
NewtonTrustRegion(delta_min = -1.0),
258+
NewtonTrustRegion(),
256259
Optim.Options(show_trace = false, allow_f_increases = false, g_tol = 1e-5),
257260
)
261+
@test Optim.termination_code(res) == Optim.TerminationCode.NoXChange
258262

259-
Optim.optimize(
263+
res = Optim.optimize(
260264
t -> -ll(t[1]),
261265
[2.1],
262-
NewtonTrustRegion(delta_min = 0.0),
266+
NewtonTrustRegion(; delta_min = 1e-8),
263267
Optim.Options(show_trace = false, allow_f_increases = false, g_tol = 1e-5),
264268
)
265-
269+
@test Optim.termination_code(res) == Optim.TerminationCode.SmallTrustRegionRadius
266270
end
267271
end

0 commit comments

Comments
 (0)