fmincon/multistart won't debug/display errors in OutputFcn

1 回表示 (過去 30 日間)
Joel Lynch
Joel Lynch 2022 年 3 月 31 日
回答済み: Joel Lynch 2022 年 3 月 31 日
If "x=b" is uncommented, the code still runs and does not break on error or display the line number.
This means debugging a more complex fcontrol function is quite difficult. Is there a way to force pause on errors in multistart?
% Fmincon problem
rng default % For reproducibility
opts = optimoptions(@fmincon,'OutputFcn', @fcontrol);
problem = createOptimProblem( 'fmincon','objective', ...
@(x) x.^2 + 4*sin(5*x),'x0',3,'lb',-5,'ub',5,'options',opts);
% Run Problem
[ x, f ] = run(MultiStart( 'Display','iter'),problem,5);
function stop = fcontrol(x, optimValues, state)
stop = false; % default continue
% x=b;
end

採用された回答

Joel Lynch
Joel Lynch 2022 年 3 月 31 日
I figured out the issue, 'OutputFcn' must be added in Multistart, not fmincon. This also means using different syntax for the call:
% Fmincon problem
rng default % For reproducibility
opts = optimoptions(@fmincon);
problem = createOptimProblem( 'fmincon','objective', ...
@(x) x.^2 + 4*sin(5*x),'x0',3,'lb',-5,'ub',5,'options',opts);
% Run Problem
ms = MultiStart( 'Display','iter','OutputFcn', @fcontrol);
[ x, f ] = run(ms,problem,5);
function stop = fcontrol(optimValues, state)
x = optimValues.localsolution.X;
stop = false; % default continue
% x=b;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by