MATLAB-PSO工具箱

2017-01-16  by:CAE仿真在線  來源:互聯(lián)網(wǎng)

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

%%%%%%%%%%% PSO工具箱函數(shù) %%%%%%%%%%%%%%%

pso PSO主程序

psoopt PSO參數(shù)項(xiàng)

psooptimset  PSO參數(shù)項(xiàng)設(shè)置

psooptimget  PSO參數(shù)項(xiàng)獲取

psoplot    PSO圖示

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

各函數(shù)調(diào)用格式

% [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主函數(shù)程序代碼

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工具箱






開放分享:優(yōu)質(zhì)有限元技術(shù)文章,助你自學(xué)成才

相關(guān)標(biāo)簽搜索:MATLAB-PSO工具箱 MatLab培訓(xùn) MatLab培訓(xùn)課程 MatLab在線視頻教程 MatLab技術(shù)學(xué)習(xí)教程 MatLab軟件教程 MatLab資料下載 MatLab代做 MatLab基礎(chǔ)知識(shí) Fluent、CFX流體分析 HFSS電磁分析 Ansys培訓(xùn) Abaqus培訓(xùn) 

編輯
在線報(bào)名:
  • 客服在線請(qǐng)直接聯(lián)系我們的客服,您也可以通過下面的方式進(jìn)行在線報(bào)名,我們會(huì)及時(shí)給您回復(fù)電話,謝謝!
驗(yàn)證碼

全國服務(wù)熱線

1358-032-9919

廣州公司:
廣州市環(huán)市中路306號(hào)金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓(xùn)QQ咨詢:點(diǎn)擊咨詢 點(diǎn)擊咨詢
項(xiàng)目QQ咨詢:點(diǎn)擊咨詢
email:kf@1cae.com