【FNN分类】基于粒子群结合引力搜索算法优化前向反馈神经网络实现数据分类附matlab代码

提出一种结合粒子群优化(PSO)与引力搜索算法(GSA)的方法,用于优化前馈神经网络(FNN)训练过程。此混合算法旨在提高FNN的全局搜索能力,减少陷入局部最小值的可能性,并加快收敛速度。通过对比实验验证了PSOGSA在训练FNN方面的优越性。

1 内容介绍

引力搜索算法(GSA)是一种基于引力定律和质量相互作用的新型启发式优化方法。实践证明,该算法具有较好的全局最优搜索能力,但在最后一次迭代中存在搜索速度较慢的问题。这项工作提出了粒子群优化 (PSO) 和 GSA 的混合体来解决上述问题。在本文中,GSA 和 PSOGSA 被用作前馈神经网络 (FNN) 的新训练方法,以研究这些算法在减少陷入局部最小值和当前进化学习算法收敛速度慢的问题方面的效率。将结果与标准的基于 PSO 的 FNN 学习算法进行比较。还研究了使用 PSO、GSA 和 PSOGSA 训练的 FNN 的准确度。实验结果表明,在收敛速度和避免局部最小值方面,PSOGSA 在训练 FNN 方面优于 PSO 和 GSA。还证明了用 PSOGSA 训练的 FNN 比用 GSA 训练的 FNN 具有更好的准确性。​

2 仿真代码

%% -------------------------------------------------------------------------

clc

clear all

close all

%% ////////////////////////////////////////////////////Data set preparation/////////////////////////////////////////////

 load iris.txt

 x=sortrows(iris,2);

 H2=x(1:150,1);

 H3=x(1:150,2);

 H4=x(1:150,3);

 H5=x(1:150,4);

 T=x(1:150,5);

 H2=H2';

 [xf,PS] = mapminmax(H2);

 I2(:,1)=xf;

 H3=H3';

 [xf,PS2] = mapminmax(H3);

 I2(:,2)=xf;

 H4=H4';

 [xf,PS3] = mapminmax(H4);

 I2(:,3)=xf;

 H5=H5';

 [xf,PS4] = mapminmax(H5);

 I2(:,4)=xf;

 Thelp=T;

 T=T';

 [yf,PS5]= mapminmax(T);

 T=yf;

 T=T';

 %% /////////////////////////////////////////////FNN initial parameters//////////////////////////////////////

HiddenNodes=15;       %Number of hidden codes

Dim=8*HiddenNodes+3;  %Dimension of masses in GSA

TrainingNO=150;       %Number of training samples

%% ////////////////////////////////////////////////////////GSA/////////////////////////////////////////////

%Configurations and initializations

noP = 30;             %Number of masses

Max_iteration  = 500;  %Maximum number of iteration

w=2;              %Inirtia weight

wMax=0.9;         %Max inirtia weight

wMin=0.5;         %Min inirtia weight

CurrentFitness =zeros(noP,1);

G0=1; %Gravitational constant

CurrentPosition = rand(noP,Dim); %Postition vector

Velocity = .3*randn(noP,Dim) ; %Velocity vector

acceleration=zeros(noP,Dim); %Acceleration vector

mass(noP)=0; %Mass vector

force=zeros(noP,Dim);%Force vector

%Vectores for saving the location and MSE of the best mass

gBestScore=inf;

gBest=zeros(1,Dim);

ConvergenceCurve=zeros(1,Max_iteration); %Convergence vector

%Main loop

Iteration = 0 ;                 

while  ( Iteration < Max_iteration )

    Iteration = Iteration + 1;  

    G=G0*exp(-20*Iteration/Max_iteration); %Equation (3.3)

    force=zeros(noP,Dim);

    mass(noP)=0;

    acceleration=zeros(noP,Dim);

%Calculate MSEs

 for i = 1:noP

        for ww=1:(7*HiddenNodes)

            Weights(ww)=CurrentPosition(i,ww);

        end

        for bb=7*HiddenNodes+1:Dim

            Biases(bb-(7*HiddenNodes))=CurrentPosition(i,bb);

        end              

        fitness=0;

        for pp=1:TrainingNO

            actualvalue=My_FNN(4,HiddenNodes,3,Weights,Biases,I2(pp,1),I2(pp,2), I2(pp,3),I2(pp,4));

            if(T(pp)==-1)

                fitness=fitness+(1-actualvalue(1))^2;

                fitness=fitness+(0-actualvalue(2))^2;

                fitness=fitness+(0-actualvalue(3))^2;

            end

            if(T(pp)==0)

                fitness=fitness+(0-actualvalue(1))^2;

                fitness=fitness+(1-actualvalue(2))^2;

                fitness=fitness+(0-actualvalue(3))^2;   

            end

            if(T(pp)==1)

                fitness=fitness+(0-actualvalue(1))^2;

                fitness=fitness+(0-actualvalue(2))^2;

                fitness=fitness+(1-actualvalue(3))^2;              

            end

        end

        fitness=fitness/TrainingNO; %Equation (5.4)

        CurrentFitness(i) = fitness;     

        

        if(gBestScore>fitness)

            gBestScore=fitness;

            gBest=CurrentPosition(i,:);

        end  

end

best=min(CurrentFitness);%Equation (3.10)

worst=max(CurrentFitness);%Equation (3.11)

for i=1:noP

    mass(i)=(CurrentFitness(i)-0.99*worst)/(best-worst);%Equation (3.9) 

end

for i=1:noP

    mass(i)=mass(i)*5/sum(mass);%Equation (3.14)  

    

end

%Calculate froces

for i=1:noP

    for j=1:Dim

        for k=1:noP

            if(CurrentPosition(k,j)~=CurrentPosition(i,j))

                %Equation (3.5)

                force(i,j)=force(i,j)+ rand()*G*mass(k)*mass(i)*(CurrentPosition(k,j)-CurrentPosition(i,j))/abs(CurrentPosition(k,j)-CurrentPosition(i,j));

                

            end

        end

    end

end

%Calculate a

for i=1:noP

       for j=1:Dim

            if(mass(i)~=0)

                acceleration(i,j)=force(i,j)/mass(i);%Equation (3.6)

            end

       end

end

%Update inertia weight

w=wMin-Iteration*(wMax-wMin)/Max_iteration;

%Calculate V

for i=1:noP

        for j=1:Dim

            %Equation (4.1)

            Velocity(i,j)=w*Velocity(i,j)+rand()*acceleration(i,j) + rand()*(gBest(j)-CurrentPosition(i,j));

        end

end

%Calculate X                                   

            

CurrentPosition = CurrentPosition + Velocity ; %Equation (4.2)

ConvergenceCurve(1,Iteration)=gBestScore; 

disp(['PSOGSA is training FNN (Iteration = ', num2str(Iteration),' ,MSE = ', num2str(gBestScore),')'])        

end

%% ///////////////////////Calculate the classification//////////////////////

        Rrate=0;

        Weights=gBest(1:7*HiddenNodes);

        Biases=gBest(7*HiddenNodes+1:Dim);

         for pp=1:TrainingNO

            actualvalue=My_FNN(4,HiddenNodes,3,Weights,Biases,I2(pp,1),I2(pp,2), I2(pp,3),I2(pp,4));

            if(T(pp)==-1)

                if (round(actualvalue(1))==1 && round(actualvalue(2))==0 && round(actualvalue(3))==0)

                    Rrate=Rrate+1;

                end

            end

            if(T(pp)==0)

                if (round(actualvalue(1))==0 && round(actualvalue(2))==1 && round(actualvalue(3))==0)

                    Rrate=Rrate+1;

                end  

            end

            if(T(pp)==1)

                if (round(actualvalue(1))==0 && round(actualvalue(2))==0 && round(actualvalue(3))==1)

                    Rrate=Rrate+1;

                end              

            end

        end

        

ClassificationRate=(Rrate/TrainingNO)*100;

disp(['Classification rate = ', num2str(ClassificationRate)]);

%% Draw the convergence curve

hold on;      

semilogy(ConvergenceCurve);

title(['Classification rate : ', num2str(ClassificationRate), '%']); 

xlabel('Iteration');

ylabel('MSE');

box on

grid on

axis tight

hold off;

3 运行结果

4 参考文献

[1] Mirjalili S A ,  Hashim S ,  Sardroudi H M . Training feedforward neural networks using hybrid particle swarm optimization and gravitational search algorithm[J]. Applied Mathematics & Computation, 2012, 218(22):11125-11137.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

粒子群优化算法是一种新颖的仿生、群智能优化算法。该算法原理简单、需调整的参数少、收敛速度快而且易于实现,因此近年来粒子群算法引起了广大学者的关注。然而到目为止粒子群算法的在理论分析和实践应用方面尚未成熟,仍有大量的问题需进一步研究。本文针对粒子群算法易出现“早熟”陷入局部极小值问题对标准粒子群算法进行改进并将改进粒子群算法应用于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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值