MATLAB-PSO工具箱

2017-01-16  by:CAE仿真在线  来源:互联网

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%% PSO工具箱函数 %%%%%%%%%%%%%%%

pso PSO主程序

psoopt PSO参数项

psooptimset  PSO参数项设置

psooptimget  PSO参数项获取

psoplot    PSO图示

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

各函数调用格式

% [x,fval,output]=pso(fun,nvars);
% [x,fval,output]=pso(fun,nvars,options);


% optoins = psodefaultopt;
% options = psodefaultopt('default')


% options = psooptimset(options,defaultopt);
% options = psooptimset(options,value);
% options = psooptimset(options,name,value);
% options = psooptimset(options,name1,value1,name2,value2,...);


% options = psooptimget('default');
% [name,values]=psooptimget(options);
% value = psooptimget(options,name);

% psoplot(output,options)
% h = psoplot(output,options)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

以下给出PSO主函数程序代码

function [x,fval,output]=pso(fun,nvars,options)
% PSO
% [x,fval,output]=pso(fun,nvars);
% [x,fval,output]=pso(fun,nvars,options);

% fun: function handle
% nvars: dimension of problem
% options: pso options setting
%
% call subfunction: bestinitialize, updatepbest, updategbest,
% updateparticle, chkerrgoal, limitpos, limitvel
% See also: psoopt, psoopitmset, psooptimget, readjust, psoplot

% Author: J.H.Zhu<jhzhu99@gmail.com>
% Date: Nov. 1, 2010.
% Copyright reserved by Author

% Check number of input arguments
error(nargchk(1,3,nargin));

if nargin<3
options =[];
end

defaultopt = psoopt('default');

% Take defaults for parameters that are not in options structure
options = psooptimset(options,defaultopt);

rand('state',options.RandState); %#ok<RAND>
popsize = options.PopulationSize;
poprange = options.PopRange;
partvel = options.ParticleVelocity;
% initialize population of particles and their velocities
pos = readjust(rand(popsize,nvars),poprange,1);
vel = readjust(rand(popsize,nvars),partvel,1);


% initial partial and global best pos
[pbest,pbestval,gbest,gbestval]=bestinitialize(fun,pos,options);

output.gbest(1,:)=gbest;
output.gbestval(1)=gbestval;
output.counter=0;

counter2=0;
for i = 1:options.MaxEpoch

for j =1:options.PopulationSize

funval(j) = feval_r(fun,pos(j,:));

% update pbest
[pbest(j,:),pbestval(j)]=...
updatepbest(pbest(j,:),pbestval(j),pos(j,:),funval(j),options);

% update gbest
[gbest,gbestval]=...
updategbest(gbest,gbestval,pbest,pbestval,options);

% update velocities and positions
[pos(j,:),vel(j,:)]=...
updateparticle(i,pos(j,:),vel(j,:),gbest,pbest(j,:),options);



end % end popsize

% check the condition of end loop
output.gbest(i,:)=gbest;
output.gbestval(i)=gbestval;
output.counter=i;


[ExitFlag,counter2]=chkerrgoal(output,counter2,options);

% figure plots
if ~isempty(options.PlotFcn) && options.Display
feval_r(options.PlotFcn,output,options);
end

if (~ExitFlag)

x = gbest;
fval = gbestval;
break;

end

end %% end maxepoch



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

psoplot画出的图形


MATLAB-PSO工具箱






开放分享:优质有限元技术文章,助你自学成才

相关标签搜索:MATLAB-PSO工具箱 MatLab培训 MatLab培训课程 MatLab在线视频教程 MatLab技术学习教程 MatLab软件教程 MatLab资料下载 MatLab代做 MatLab基础知识 Fluent、CFX流体分析 HFSS电磁分析 Ansys培训 Abaqus培训 

编辑
在线报名:
  • 客服在线请直接联系我们的客服,您也可以通过下面的方式进行在线报名,我们会及时给您回复电话,谢谢!
验证码

全国服务热线

1358-032-9919

广州公司:
广州市环市中路306号金鹰大厦3800
电话:13580329919
          135-8032-9919
培训QQ咨询:点击咨询 点击咨询
项目QQ咨询:点击咨询
email:kf@1cae.com