nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

Question: Returning NaNs to the optimizer

Open MichaelRThompson opened this issue 5 years ago • 5 comments

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.

MichaelRThompson avatar Jun 27 '19 18:06 MichaelRThompson

I dont think most solvers will like being fed nans.

jschueller avatar Jun 27 '19 18:06 jschueller

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.

MichaelRThompson avatar Jul 02 '19 18:07 MichaelRThompson

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.

tepperly avatar Jul 02 '19 18:07 tepperly

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

Martin-Oehler avatar Aug 16 '19 10:08 Martin-Oehler

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

stevengj avatar Aug 16 '19 11:08 stevengj