필터 지우기
필터 지우기

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