Is it possible to get fminunc or fmincon to return NA if it encounters an error rather than breaking from the program?

1 次查看(过去 30 天)
I'm running local optimization procedures via fminunc in a large loop of starting points. Sometimes, after a long time of minimization, fminunc will spit back an error because the function blows up along the path. Instead of stopping my loop, is it possible to tell fminunc, to return a NaN value so the loop can continue?

回答(2 个)

Walter Roberson
Walter Roberson 2016-8-16
If "blows up" means that it generates an error (for example subscript out of range) then you should use try/catch around the call.

Matt J
Matt J 2016-8-16
编辑:Matt J 2016-8-16
Using fmincon's SQP algorithm, the algorithm should never crash with an error if your objective function returns NaN or Inf. The SQP algorithm knows how to recover from situations where the search strays into a bad region. However, for the opimization to succeed, your "good region", the region where the objective and constraints are finite must be an open set.
You might also be able to use an Output Function, either with fminunc or fmincon, to force the algorithm to stop according to your own criterion, e.g., when the current value of the objective function is Inf.

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by