stevengj / nlopt

library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization
Other
1.88k stars 584 forks source link

Question: Returning NaNs to the optimizer #279

Open MichaelRThompson opened 5 years ago

MichaelRThompson commented 5 years ago

Currently I'm working on optimizing a very sensitive problem, and especially for global optimization algorithms, there are some inputs that the objective function isn't able to evaluate. All of the optimization variables are within the bound constraints, but for some specific combinations, it's too numerical difficult to evaluate.

Is there a way to return something to the optimizer to tell it to ignore that result? For example, I like the idea of something as simple as returning NaNs or something along those lines.

jschueller commented 5 years ago

I dont think most solvers will like being fed nans.

MichaelRThompson commented 5 years ago

I certainly don't think so either, which is why I was asking if there is an easier way.

For now I'm working around it by using the augmented Lagrangian algorithm, and essentially using the successful evaluation of the objective function as an equality constraint. A bit of a weird workaround, but it's mostly working for now.

tepperly commented 5 years ago

I have the same question. It would be very useful if the objective function could throw an exception or return a value indicating that the current x is infeasible or the objective function can't be evaluated at x for unspecified reasons. I don't want the optimization to stop. In absence of another approach, I suppose the best thing to do is to return a value that's large compared to normal function values for a minimization problem or a value that's small compared to normal function values for a maximization problem.

Martin-Oehler commented 5 years ago

I am facing the same problem. Currently, I just do return std::numeric_limits<double>::max(); which seems to work fine.

stevengj commented 5 years ago

The ORIG_DIRECT algorithm actually lets you return NaN to indicate infeasible points: https://github.com/stevengj/nlopt/blob/master/src/algs/direct/README