Particle Swarm Optimization info
5 views (last 30 days)
Show older comments
Marco Marchese
on 27 Dec 2018
Commented: Marco Marchese
on 28 Jan 2019
I am trying to find the values of 19 free variables from my data, using the psw optimization algorithm. I got interest in seeing the evolution of the 19 variables together with the minimization of the objective function, over the iterations. I then want to compare this againnst the genetic algorithm.
with the genetic algorithm I am able to to so, and get information (see code below), but with the psw I am no cabable of doing it. With the ga, I call this function from gaoptimset('PlotFcns',{@gaplotbestf, @gapop_func},...
Can you help me with this? Thank you a lot
function [state,options,optchanged] = gapop_func(options,state,flag)
persistent best r history_min history_max %h1
optchanged = false;
switch flag
case 'init'
best = state.Population;
assignin('base','gapopbestx',best);
case 'iter'
ibest = state.Best(end);
ibest = find(state.Score == ibest,1,'last');
bestx = state.Population(ibest,:);
best = [best; bestx];
assignin('base','gapop_max_best',history_max);
case 'done'
assignin('base','gapopbestx',best);
end
0 Comments
Accepted Answer
Alan Weiss
on 28 Dec 2018
The syntaxes for output functions differ between ga and particleswarm. For an example of a particleswarm output function, see this example. For the correct way to set options for particleswarm, see the same example (you must use optimoptions to set options).
Alan Weiss
MATLAB mathematical toolbox documentation
5 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!