机器学习之基于matlab的神经网络粒子群优化算法的实现

实现算法的论文,代码源码,测试函数,请见本人的git账户:
https://github.com/qiu997018209/MachineLearning

以下是mymain.m文件内容

 clear 
% mex cec13_func.cpp -DWINDOWS
func_num=1;
D=10;
VRmin=-100;
VRmax=100;
N=40;
Max_Gen=5000;
runs=1
fhd=str2func('cec14_func');



for i=1
    func_num=i;
    for j=1:runs

    [gbest,gbestval,pop]=myfunc(fhd,D,N,Max_Gen,VRmin,VRmax,func_num);
    xbest(i,:)=gbest
    fbest(i,j)=gbestval
   % plot(pbest(:,1)
   % plot(x,y)
    %plot(x,yy)
   % hold(a1,a2);
    %axis([500 5000,10^2 10^5]);
    %title(['适应度曲线  ' '终止代数=' num2str(Max_Gen)]);
     %xlabel('进化代数');ylabel('适应度');
    end
    f_mean(i)=mean(fbest(i,j))

end

以下是myfunc.m文件内容


function[gbest,gbestval,pop]=myfunc(fhd,D,N,Max_Gen,VRmin,VRmax,varargin);
%------给定初始化条件----------------------------------------------
%问题要么在邻域部分,要么在速度更新。我在只更换速度公式的时候是可以得到一个明显的改善的

clc;
rand('state',sum(100*clock));
c=[0.5+log(2),0.5+log(2)];
%c=[2 2];
%w=1/(2*log(2));
w=0.9-(1:Max_Gen).*(0.5./Max_Gen)
Vmax=50;
Vmin=-50;
%------初始化种群的个体------------
%pbest 个体最佳,lbest 邻域最佳,gbest,全局最佳,VRmax,粒子范围,Vmin速度范围。
pop=VRmin+(VRmax-VRmin).*rand(N,D);
vel=0.5*(Vmin+(Vmax-Vmin).*rand(N,D)-pop);
%vel=Vmin+2.*Vmax.*rand(N,D)
e=feval(fhd,pop',varargin{:});


%% 个体极值和群体极值
pbest=pop; %个体最佳
pbestval=e;%个体最佳适应度值
[gbestval bestindex]=min(e);
gbest=pbest(bestindex,:);%全局最佳
%gbestrep=repmat(gbest,N,1);
n(1)=gbestval;

k=3;
%拓扑结构
for i=1:N;
   a1=[1:i-1,i+1:N];
   a1= a1(randperm(N-1));
   a2=a1(1:k);
   a3(i,:)=[a2,i];
   a4=a3(i,:);
   [lbestval(i),a5]=min(pbestval(a3(i,:)));
    a6=a4(a5);
   lbest(i,:)=pbest(a6,:);%邻域
end
%在更换速度公式的时候,可以更换变量
%gbestrep=repmat(gbest,N,1);
%aa=c(1).*rand(N,D).*(pbest-pop)+c(2).*rand(N,D).*(gbestrep-pop);
%vel=w(j).*vel+aa;


%% 迭代寻优

for j=2:Max_Gen;
    %更新速度
       l=pop+c(2)*rand(N,D).*(lbest-pop);%邻域
       p=pop+c(1)*rand(N,D).*(pbest-pop);%个体最佳
       G=(p+l+pop)/3;
       %aa=c(1).*rand(N,D).*(pbest-pop)+c(2).*rand(N,D).*(gbestrep-pop);
       %vel=w(j).*vel+aa;
       R=abs(G-pop);
       vel=w(j).*vel+G+(-1+rand(N,D)*2).*R
       vel=(vel>Vmax).*Vmax+(vel<=Vmax).*vel;
       vel=(vel<Vmin).*Vmin+(vel>=Vmin).*vel;
      %更新位置 
       pop=vel+pop;
       pop=((pop>=VRmin)&(pop<=VRmax)).*pop...
            +(pop<VRmin).*(VRmin+0.25.*(VRmax-VRmin).*rand(N,D))+(pop>VRmax).*(VRmax-0.25.*(VRmax-VRmin).*rand(N,D));
      %pop=((pop>=VRmin)&(pop<=VRmax)).*pop...
          %+(pop<VRmin).*(VRmin)+(pop>VRmax).*(VRmax);
       vel=((pop>=Vmin)&(pop<=Vmax)).*vel+(pop<Vmin).*0+(pop>Vmax).*0;
      %获取适应值
       e=feval(fhd,pop',varargin{:});
       %更新pbest,历史最佳
       t=(e<pbestval);
       m=repmat(t',1,D);
       pbest=m.*pop+(1-m).*pbest;
       pbestval=t.*e+(1-t).*pbestval;
       %更新lbest,局部最佳
       for i=1:N;
        a7=a3(i,:);
       [lbestval(i),m1]=min(pbestval(a3(i,:)))
       a8=a7(m1);
       lbest(i,:)=pbest(a8,:);
       end
      %得到全局最佳
       [gbestval id]=min(pbestval);
        n(j)=gbestval;
        gbest=pbest(id,:);
        gbestrep=repmat(gbest,N,1)
        %变更拓扑结构
       if isequal(n(j-1),n(j));
          for i=1:N;
          a1=[1:i-1,i+1:N];
          a1= a1(randperm(N-1));
          a2=a1(1:k);
          a3(i,:)=[a2,i];
          a4=a3(i,:);
          [lbestval(i),a5]=min(pbestval(a3(i,:)));
           a6=a4(a5);
           lbest(i,:)=pop(a6,:);
          end
       end
end



end

















  • 7
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
粒子群优化算法是一种新颖的仿生、群智能优化算法。该算法原理简单、需调整的参数少、收敛速度快而且易于实现,因此近年来粒子群算法引起了广大学者的关注。然而到目前为止粒子群算法的在理论分析和实践应用方面尚未成熟,仍有大量的问题需进一步研究。本文针对粒子群算法易出现“早熟”陷入局部极小值问题对标准粒子群算法进行改进并将改进的粒子群算法应用于BP神经网络中。本文的主要工作如下:本文首先介绍了粒子群算法的国内外的研究现状与发展概况,较系统地分析了粒子群优化算法的基本理论,总结常见的改进的粒子群优化算法。其次介绍了Hooke-Jeeves模式搜索法的算法分析、基本流程及应用领域。针对标准粒子群优化算法存在“早熟”问题,易陷入局部极小值的缺点,本文对标准粒子群算法进行改进。首先将原始定义的初始种群划分为两个相同的子种群,采用基于适应度支配的思想分别将每个子种群划分为两个子集,Pareto子集和N_Pareto子集;然后将两个子群中的适应度较优的两个Pareto子集合为新种群。Griewank和Rastrigin由于新种群的参数设置区别于标准粒子群算法的参数设置,新的粒子与标准种群中的粒子飞行轨迹不同,种群的探索范围扩大,从而使算法的全局搜索能力有所提高。 为平衡粒子群算法的全局寻优能力和局部寻优能力,提高粒子群算法的求解精度和效率,本文在新种群寻优过程中引入具有强收敛能力Hooke-Jeeves搜索法,提出了IMPSO算法。雅文网www.lunwendingzhi.com,并用IMPSO算法对标准基准测试函数进行实验,将得到的实验结果并与标准粒子群算法对基准函数的实验结果进行对比,仿真结果证明了该改进的粒子群算法的有效性。 最后本文研究改进的粒子群算法在BP神经网络中的应用。首先介绍人工神经网络的原理及基于BP算法的多层前馈神经网络,其次用IMPSO算法训练BP神经网络并给出训练流程图。 将IMPSO算法训练的BP神经网络分别应用于齿轮热处理中硬化层深的预测以及用于柴油机的缸盖与缸壁的故障诊断中,并将预测结果、诊断结果与BP神经网络、标准粒子群优化算法训练的BP神经网络的实验结果进行对比,实验结果证明了改进的粒子群算法训练BP网络具有更强的优化性能和学习能力。 英文简介: Particle swarm optimization algorithm is a novel bionic, swarm intelligence optimization algorithm. The algorithm principle is simple, less need to adjust the parameters and convergence speed is fast and easy to implement, so in recent years, particle swarm optimization (pso) to cause the attention of many scholars. So far, however, the particle swarm algorithm are not mature in theory analysis and practice applications, there are still a lot of problems need further research. Based on particle swarm algorithm is prone to "premature" into a local minimum value problem to improve the standard particle swarm algorithm and improved particle swarm optimization (pso) algorithm was applied to BP neural network. This paper's main work is as follows: at first, this paper introduces the particle swarm algorithm in the general situation of the research status and development at home and abroad, systematically analyzes the basic theory of particle swarm optimization algorithm, summarizes the common improved particle swarm optimization algorithm. Secondly introduces the analysis method of Hooke - Jeeves pattern search algorithm, the basic process and application fields. In view of the standard particle swarm optimization algorithm "precocious" problems, easy to fall into local minimum value, in this paper, the standard particle swarm algorithm was improved. First of all, the original definition of the initial population is divided into two identical sub populations, based on the fitness of thought respectively each child population is divided into two subsets, and Pareto subset N_Pareto subset; And then has a better fitness of two subgroups of two Pareto set for the new population. Griewank and Rastrigin because of the new population parameter setting differs from the standard particle swarm algorithm of the parameter is set, the new particles and particle trajectories in the different standard population, population expanding, which makes the algorithm's global search ability have improved. To balance the global search capability of the particle swarm algorithm and local optimization ability, and improve the precision and efficiency of particle swarm optimization (pso) algorithm, introduced in this article in the new population optimization process has a strong convergence ability to search method of Hooke - Jeeves, IMPSO algorithm is proposed. And standard benchmark test functions with IMPSO algorithm experiment, will receive the results with the standard particle swarm algorithm, comparing the experimental results of benchmark functions, the simulation results prove the validity of the improved particle swarm algorithm. At the end of the paper research the improved particle swarm algorithm in the application of the BP neural network. First this paper introduces the principle of artificial neural network and based on the multi-layer feed-forward neural network BP algorithm, secondly by IMPSO algorithm training the BP neural network and training flow chart is given. IMPSO algorithm training the BP neural network respectively used in the gear heat treatment hardening layer depth prediction and used for fault diagnosis of diesel engine cylinder head and cylinder wall, and the predicted results, the diagnostic results, the standard particle swarm optimization algorithm with BP neural network of training BP neural network, comparing the experimental results of the experimental results show that the improved particle swarm optimization (pso) training BP network has better optimization performance and learning ability.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值