matlab中temppos,[转载]MATLAB-PSO工具箱

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

%%%%%%%%%%% 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

% 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

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画出的图形

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值