フィルターのクリア

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 Center および File ExchangeParticle Swarm についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by