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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by