Hi, I’m using Interior-Point Newton to solve a constrained optimization problem where my objective function is not (always) defined outside the constraint set. I found that Interior-Point Newton sometimes tries points outside of the constraint set. Does that mean that I should use a different solution method, or am I doing something wrong? See the below MWE in which I tried to replicate the behaviour.
using Optim, ForwardDiff, Random, Distributions
Random.seed!(42)
f_unforced(x) = -prod(x)
f_forced(x) = sum(x .^ 2) < 1 ? -prod(x) : error("The value $([xi.value for xi in x]) is not allowed")
norm_c!(c, x) = (c[1] = sum(y -> y^2, x); c)
function check_optims(d)
con = TwiceDifferentiableConstraints(norm_c!, -ones(d), ones(d), [-Inf], [1.])
for i in 1:1000
x_init = rand(d)
while sum(x_init .^ 2) > 1
x_init = rand(d)
end
x_init_copy = copy(x_init)
# If we use a function that does not force the constraint, there is no problem
opt2 = Optim.optimize(f_unforced, con, x_init, IPNewton(); autodiff = :forward)
try
# If we use a function that forces the constraint, we may get an error
opt1 = Optim.optimize(f_forced, con, x_init, IPNewton(); autodiff = :forward)
catch
display("Failed at the i'th attempt: $i")
if sum(x_init_copy .^ 2) > 1
display("Initial value was $x_init_copy, which is not allowed")
else
display("Initial value was $x_init_copy, which is allowed")
end
error()
end
end
return nothing
end
check_optims(2)
gives
"Failed at the i'th attempt: 1"
"Initial value was [0.6293451231426089, 0.4503389405961936], which is allowed"
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] check_optims(d::Int64)
@ Main ~/Documents/ConOptStop_Julia_v0.1/test_optim.jl:30
[3] top-level scope
@ ~/Documents/ConOptStop_Julia_v0.1/test_optim.jl:36
caused by: The value [0.9466761003329859, 0.45177899946620614] is not allowed
# A long stacktrace
If I should use a different solver, I’m curious about your suggestions, so please let me outline my set-up: I typically have box-constraints + a norm constraint in dimensions 1-3, and the objective is (roughly) polynomial in shape (although I do not have a nice closed form available!). It needs to be computed many times (10.000s of times). These repetitions are independent, so I’m currently multithreading the optimizations; I’d like to keep that (or a similar optimization) in there! Of course I can “fix” f_forced
by setting it to be f_unforced
if the constraint is met, and infinity otherwise, but I’m not sure if that interferes with how interior-point Newton works?