Skip to content

Commit 75d2b0a

Browse files
Update test/multivariate/solvers/constrained/fminbox.jl
Extend tests of `initial_mu` and `Fminbox` for additional cases, such as half-bounded parameters. Co-authored-by: Patrick Kofod Mogensen <patrick.mogensen@gmail.com>
1 parent 8785236 commit 75d2b0a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

test/multivariate/solvers/constrained/fminbox.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,31 @@
182182
)
183183
end
184184
@testset "Guard against gbarrier_norm == 0 in computation of initial mu #1233" begin
185-
optimize(exponential, fill(-Inf,2), fill(Inf,2), initial_x, Fminbox(), Optim.Options())
185+
l_inf, u_inf = fill(-Inf, 2), fill(Inf, 2)
186+
187+
# gnorm > 0, gbarrier_norm == 0: previously mu = gnorm/0 = Inf
188+
res = optimize(exponential, l_inf, u_inf, initial_x, Fminbox(), Optim.Options())
189+
@test Optim.converged(res)
190+
@test Optim.minimizer(res) [2.0, 3.0] atol = 1e-3
191+
192+
# gnorm == 0 and gbarrier_norm == 0: previously mu = 0/0 = NaN
193+
# ([2.0, 3.0] is the stationary point of `exponential`)
194+
res = optimize(exponential, l_inf, u_inf, [2.0, 3.0], Fminbox(), Optim.Options())
195+
@test Optim.converged(res)
196+
@test Optim.minimizer(res) [2.0, 3.0]
197+
198+
# initial_mu unit tests
199+
box_inf = Optim.BoxBarrier(l_inf, u_inf)
200+
@test Optim.initial_mu(box_inf, [0.0, 0.0], [1.0, 1.0], Fminbox()) == 0 # Inf case
201+
@test Optim.initial_mu(box_inf, [0.0, 0.0], [0.0, 0.0], Fminbox()) == 0 # NaN case
202+
203+
# half-bounded box: a single finite bound must still give mu > 0
204+
box_half = Optim.BoxBarrier([-Inf, 0.0], [Inf, Inf])
205+
@test Optim.initial_mu(box_half, [0.0, 1.0], [1.0, 1.0], Fminbox()) > 0
206+
207+
# explicitly non-finite user-supplied mu0 should still throw
208+
@test_throws ArgumentError Optim.initial_mu(box_inf, [0.0, 0.0], [1.0, 1.0],
209+
Fminbox(LBFGS(); mu0 = Inf))
186210
end
187211
end
188212
end

0 commit comments

Comments
 (0)