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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Joel Lynch
Joel Lynch el 31 de Mzo. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Global or Multiple Starting Point Search en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by