Obtaining a matrix of all the values the optimizer tried

조회 수: 1 (최근 30일)
Spyros Polychronopoulos
Spyros Polychronopoulos 2018년 9월 25일
편집: Spyros Polychronopoulos 2018년 9월 26일
Hi there, I have this optimizer minimizing f. The optimizer is trying various values for x variable. Would you maybe have an idea how I can obtain when the optimizer finishes a matrix with the x values the optimizer tried?
clearvars
f = @(x) x.^2;
x0=5;
x_min = -10;
x_max = 10;
TimeLimit_SA = 20;
options = optimoptions(@simulannealbnd,'TimeLimit',TimeLimit_SA);
[x_best,f_best,exitflag,output]=simulannealbnd(f,x0,x_min,x_max,options);

채택된 답변

Matt J
Matt J 2018년 9월 25일
You would have to write an OutputFcn to do this.
  댓글 수: 8
Spyros Polychronopoulos
Spyros Polychronopoulos 2018년 9월 25일
That's it! Thank you very much. I will try to do it with simulannealbnd now.
Spyros Polychronopoulos
Spyros Polychronopoulos 2018년 9월 26일
편집: Spyros Polychronopoulos 2018년 9월 26일
I have done the same thing for simulated annealing but the history matrix comes up empty, plus the time constrain is not working. Any ideas?
main
zz = @(x) x; %objective function
z0=5; %starting value
LB=-20; %low bound
UB=20; %upper bound
TimeLimit_SA = 1; %time constrain
[x, fval, history] = sa_store(zz, z0 ,LB,UB,TimeLimit_SA);
sa_store
function [x, fval, history] = sa_store(objfun,x0,LB,UB,t_Lim)
history = [];
options = optimset('MaxTime',t_Lim,'OutputFcn', @myoutput);
[x, fval] = simulannealbnd(objfun,x0,LB,UB,options);
function stop = myoutput(x,~,state)
stop = false;
if isequal(state,'iter')
history = [history; x];
end
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by