How do we create a customize output function for the 'surrogateopt' that will show the solution at every iteration. I need am example for better understanding. Thank you.

 채택된 답변

Alan Weiss
Alan Weiss 2022년 8월 9일

1 개 추천

Try this.
lb = [-3 -3];
ub = -lb;
opts = optimoptions('surrogateopt','OutputFcn',@listout);
obj = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
[sol,fval] = surrogateopt(obj,lb,ub,opts)
function stop = listout(x,optimValues,state)
stop = false;
switch state
case 'iter'
nval = optimValues.funccount;
y = optimValues.currentX;
fprintf("Number of fevals = %g, x = [%g,%g]\n",nval,y(1),y(2))
end
end
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 3

Geopaul
Geopaul 2022년 8월 9일
Thank you so much, it works.
Geopaul
Geopaul 2022년 8월 11일
How do I save these outputs( e.g nval and y) at every iterations?
Alan Weiss
Alan Weiss 2022년 8월 11일
Alan Weiss
MATLAB mathematical toolbox documentation

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 8월 9일

댓글:

2022년 8월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by