Optimisation functions: Skipping iterations if objective function returns an error or cannot run completely

5 ビュー (過去 30 日間)
I am using the optimisation toolbox (both the normal one and the Global one) for problems of a certain kind. The objective function in these cases are custom user defined functions, dependent on multiple other scripts. Thus, in certain cases, the variables to be optimised might return an error on running the objective if certain conditions (Apart from bounds and constraints) are not met. Assuming these conditions vary between test cases ie. cannot be accomodated in a constraint, the optimisation stops right when any iteration throws up an error.
Is it possible to make these optimisation functions skip the particular iteration if it returns an error, update the variables and move on to the next iteration?

採用された回答

Matt J
Matt J 2022 年 7 月 5 日
編集済み: Matt J 2022 年 7 月 5 日
Basically, the option available to you is to return inf from your objective when an error condition is reached. Some optimization algorithms will backtrack from inf values (e.g., fmincon's sqp algorithm) but not all.
function [fval]=myObjective(x)
try
%The usual code for the objective
fval=...
catch
fval=inf;
end
end
  1 件のコメント
Goutham Jyothilal
Goutham Jyothilal 2022 年 7 月 8 日
編集済み: Goutham Jyothilal 2022 年 7 月 8 日
Thank you very much. The suggested solution seemed to work perfectly. Thank you once again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver 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