• PUDN用户
    了解作者
  • Others
    开发工具
  • 2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2015-04-02 20:46
    上传日期
基于粒子群优化算法的的数据挖掘算法对比,用Matlab编写
PSO.zip
  • PSO
  • pso.m
    6KB
内容介绍
function [pso F] = pso() %FUNCTION Optimization --------USE Particle Swarm Optimization Algorithm % % % % %global present; % close all; pop_size = 10; % pop_size part_size = 2; % partible_size , ** =n-D gbest = zeros(1,part_size+1); % gbest the best value so far max_gen = 80; % max_gen max generation region=zeros(part_size,2); % define searching regions region=[-1,1;-1,1]; % define the size of regions rand('state',sum(100*clock)); % reset the state of random machine arr_present = ini_pos(pop_size,part_size); % present position, random initialization,rand() from 0~1 v=ini_v(pop_size,part_size); % initialized velocity pbest = zeros(pop_size,part_size+1); % pbest the best result, last column contain the parameter as well w_max = 0.9; % w_max maximum of weight w_min = 0.4; % w_min minumum of weitht v_max = 2; % ** maximum of velocity c1 = 2; % learning parameter 1 c2 = 2; % learning parameter 2 best_record = zeros(1,max_gen); % best_record remember the best particle's parameters % ———————————————————————— % Calulate the paricles affinity and initialization % ———————————————————————— arr_present(:,end)=ini_fit(arr_present,pop_size,part_size); % for k=1:pop_size % present(k,end) = fitness(present(k,1:part_size)); % % end pbest = arr_present; %initialized all best value for particles [best_value best_index] = min(arr_present(:,end)); %initialize the global optima gbest = arr_present(best_index,:); %v = zeros(pop_size,1); % v % ———————————————————————— % Evolving % ———————————————————————— % global m; % m = moviein(1000); % x=[-1:0.01:1]; y=[-1:0.01:1]; z=@(x,y) cos(2 * pi .* x) .* cos(2 * pi .* y) .* exp(-0.1 * (x.^2 + y.^2)); for i=1:max_gen grid on; % plot3(x,y,z); % subplot(121),ezmesh(z),hold on,grid on,plot3(arr_present(:,1),arr_present(:,2),arr_present(:,3),'*'),hold off; % subplot(122),ezmesh(z),view([145,90]),hold on,grid on,plot3(arr_present(:,1),arr_present(:,2),arr_present(:,3),'*'),hold off; ezmesh(z,[-1,1,-1,1]),hold on,grid on,plot3(arr_present(:,1),arr_present(:,2),arr_present(:,3),'*'),hold off; drawnow F(i)=getframe; % ezmesh(z) % % view([-37,90]) % hold on; % grid on; % % plot(-0.0898,0.7126,'ro'); % plot3(arr_present(:,1),arr_present(:,2),arr_present(:,3),'*'); % % axis([-2*pi,2*pi,-pi,pi,-50,10]); % hold off; pause(0.01); % m(:,i) = getframe; % w = w_max-(w_max-w_min)*i/max_gen; % fprintf('# %i !\n',i); % Decide whether reset the particles because they may converge—————————————————————————————— reset = 0; % reset = 1 if reset==1 bit = 1; for k=1:part_size bit = bit&(range(arr_present(:,k))<0.1); end if bit==1 % bit=1, reset position and velocity arr_present = ini_pos(pop_size,part_size); % present position v = ini_v(pop_size,part_size); % velocity initialization for k=1:pop_size % re-calculate affinity arr_present(k,end) = fitness(arr_present(k,1:part_size)); end warning('Reset particle because they already converged……'); display(i); end end for j=1:pop_size v(j,:) = w.*v(j,:)+c1.*rand.*(pbest(j,1:part_size)-arr_present(j,1:part_size))... +c2.*rand.*(gbest(1:part_size)-arr_present(j,1:part_size)); % renew velocity (a) % The abs(velocity) must <5———————————————————————————— c = find(abs(v)>6); v(c) = sign(v(c))*6; %if v>3.14则,v=3.14 arr_present(j,1:part_size) = arr_present(j,1:part_size)+v(j,1:part_size); % renew position (b) arr_present(j,end) = fitness(arr_present(j,1:part_size)); if (arr_present(j,end)>pbest(j,end))&(Region_in(arr_present(j,:),region)) % renew pbest pbest(j,:) = arr_present(j,:); end end [best best_index] = max(arr_present(:,end)); if best>gbest(end)&(Region_in(arr_present(best_index,:),region)) % if the result better than before, save to gbest gbest = arr_present(best_index,:); end best_record(i) = gbest(end); end pso = gbest; display(gbest); % figure; % plot(best_record); % movie2avi(F,'pso_2D1.avi','compression','MSVC'); % *************************************************************************** % Calculate Affinity % *************************************************************************** function fit = fitness(present) fit=cos(2 * pi .* present(1)) .* cos(2 * pi .* present(1)) .* exp(-0.1 * (present(1).^2 + present(2).^2)); function ini_present=ini_pos(pop_size,part_size) ini_present = 3*rand(pop_size,part_size+1); %initialized particles positions, randomly separate them in the region %** 6即为自变量范围 function ini_velocity=ini_v(pop_size,part_size) ini_velocity =3/2*(rand(pop_size,part_size)); %initialized particles velocity, randomly separate them in the region function flag=Region_in(pos_present,region) [m n]=size(pos_present); flag=1; for j=1:n-1 flag=flag&(pos_present(1:j)>=region(j,1))&(pos_present(1:j)<=region(j,2)); end function arr_fitness=ini_fit(pos_present,pop_size,part_size) for k=1:pop_size arr_fitness(k,1) = fitness(pos_present(k,1:part_size)); %calculate the initial population affinity end
评论
    相关推荐
    • 粒子群算法优化极限学习机PSO_ELM.zip
      PSO粒子群算法优化极限学习机ELM参数,即PSO-ELM
    • pso优化elm.zip
      pso优化elman神经网络 使其精度更高
    • PSO_ELM.zip
      粒子群优化极限学习机的参数。最佳粒子位置即为最优输入权值和隐层阈值。自己跑过的,放数据匹配一下就可以用
    • pso_svm.zip
      粒子群优化算法(Particle Swarm optimization,PSO)又翻译为粒子群算法、微粒群算法、或微粒群优化算法。是通过模拟鸟群觅食行为而发展起来的一种基于群体协作的随机搜索算法。通常认为它是群集智能 (Swarm ...
    • PSO优化LSSVM的参数.zip
      据集源自意大利葡萄酒种类的数据,支持向量机为libsvm。采用SVM、遗传算法优化SVM、粒子群算法优化SVM优化c、g参数,进行分类识别的结果对比
    • 智能优化算法
      哈里斯鹰优化算法,实际可用,已验证算法收敛性,均用于多种参数优化处理。
    • 【预测模型】基于粒子群算法PSO优化极限学习机ELM实现数据预测matlab源码.zip
      【预测模型】基于粒子群算法PSO优化极限学习机ELM实现数据预测matlab源码.zip
    • pso粒子群算法.zip
      pso粒子群的随机优化技术,模仿昆虫鸟群的群集行为
    • PSO_ELM.zip
      粒子群算法优化极限学习机的输入层和隐含层之间的权值和隐含层阈值
    • matlabcnhelp.rar
      matlab中文帮助很难找的,快速下载