Passing values to PSO options
3 ビュー (過去 30 日間)
表示 古いコメント
Hi there,
How may I pass swarmSize variable value to opts in the PSO? I have included the particular code piece below. When I do as below, it seems 'swarmSize' doesn't get passed to opts. Many thanks in advance.
swarmSize = 10; %doesn't pass to opts??
opts = optimoptions(@particleswarm,...
'Display','iter',...
'PlotFcn','pswplotbestf',...
'SwarmSize', swarmSize,...
'MaxIterations',20,...
'UseVectorized',true,...
'UseParallel',false);
% Cost {function-handle}
cost = @(particlePosition) costfn(iStep,nn,swarmSize,nvars,particlePosition);
% PSO Call
[particlePosition,particleCost,exitflag,output] = particleswarm(cost,nvars-2,particlelb,particleub,opts);
0 件のコメント
回答 (1 件)
Alan Weiss
2022 年 8 月 8 日
It works for me. Here is a little test script:
fun = @(x)x(1)*exp(-norm(x)^2);
lb = [-5,-5];
ub = -lb;
opts = optimoptions('particleswarm',"SwarmSize",20,"Display","iter");
[sol,fv,ef,output] = particleswarm(fun,2,lb,ub,opts)
You see that there were 38 iterations and 780 function evaluations. This corresponds to a swarm size of 20: 20*38 = 760, plus 20 initial evaluations = 780 function evaluations.
Alan Weiss
MATLAB mathematical toolbox documentation
参考
カテゴリ
Find more on Particle Swarm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!