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 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