How to apply multiple runs (essentially loop it) on optimization (such as GA and PSO)

1 次查看(过去 30 天)
I want to loop an optimization solution that i've done so that I could generate at least 25 answers (and be it stored in an array) and find the lowest among them. I understand that inside the optimization, it already gives me the optimized answer, but our professor wants us to find the lowest value among certain number of iterations.
I just want to apply loop in this block, then be it stored in an array.
% For Fminsearch
initguess=[1,2];
options=optimset('MaxIter',2000,'MaxFunEvals',2000);
[c,fmin]=fminsearch(OFVL,initguess,options);
% For Genetic Algorithm
options2=optimoptions('ga','MaxStallGenerations',5000, 'MaxGenerations',5000, 'TolFun', 1e-12);
[c_ga,fmin_ga]=ga(OFVL,2,[],[],[],[],[],[],[],options2);
%For PSO
options3 = optimoptions('particleswarm', 'MaxStallIterations',5000, 'MaxIteration', 5000, 'TolFun', 1e-12);
[c_pso, fmin_pso]=particleswarm(OFVL,2,[],[],options3);

采纳的回答

Walter Roberson
Walter Roberson 2021-4-25
for count = 1 : 3
% For Fminsearch
initguess=[1,2]+rand(1,2);
options=optimset('MaxIter',2000,'MaxFunEvals',2000);
[c(count,:),fmin(count,:)]=fminsearch(OFVL,initguess,options);
% For Genetic Algorithm
options2=optimoptions('ga','MaxStallGenerations',5000, 'MaxGenerations',5000, 'TolFun', 1e-12);
[c_ga(count,:),fmin_ga(count,:)]=ga(OFVL,2,[],[],[],[],[],[],[],options2);
%For PSO
options3 = optimoptions('particleswarm', 'MaxStallIterations',5000, 'MaxIteration', 5000, 'TolFun', 1e-12);
[c_pso(count,:), fmin_pso(count,:)]=particleswarm(OFVL,2,[],[],options3);
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