1 简介
为了提高核极限学习机(KELM)数据分类的精度,提出了遗传算法(GA)的KELM分类器参数优化方法(GA-KELM),将CV训练所得多个模型的平均精度作为GA的适应度评价函数,为KELM的参数优化提供评价标准,用获得GA优化最优参数的KELM算法进行数据分类.利用UCI中数据集进行仿真.
2 部分代码
%清空运行空间
clc;
clear;
close all;
wmax=0.9;
wmin=0;%速度的上限及下限
itmax=50;%迭代代数
%速度更新参数
c1=2;
c2=2;
for iter=1:itmax
W(iter)=wmax-((wmax-wmin)/itmax)*iter;
end;
a=-1;
b=2;
N=200;
D=2;
m=0.1;
n=3;
tcl=0.05;
f='x.*sin(4*pi.*x)-y.*sin(4*pi.*y+pi+1)';
[x,y]=meshgrid(a:tcl:b,a:tcl:b);
vxp=x;
vyp=y;
vzp=eval(f);
x=[];
vmfit=[];
x=a+(b-a)*rand(N,D,1);
V=wmin+(wmax-wmin)*rand(N,D,1);
for i=1:N
F(i,1,1)=x(i,1,1)*sin(4*pi*x(i,1,1))-x(i,2,1)*sin(4*pi*x(i,2,1)+pi+1);
end;
media=mean(F(:,1,1));
vmfit=[vmfit media];
[C,I]=max(abs(F(:,1,1)));
B(1,1,1)=C;
gbest(1,1,1)=x(I,1,1);
gbest(1,2,1)=x(I,1,1);
for p=1:N
for r=1:D
G(p,r,1)=gbest(1,r,1);
end
end
Fbest(1,1,1)=G(1,1,1)*sin(4*pi.*G(1,1,1))-G(1,2,1)*sin(4*pi.*G(1,2,1)+pi+1);
for i=1:N
pbest(i,:,1)=x(i,:,1);
pbest
end
Fb(1,1,1)=gbest(1,1,1)*sin(4*pi.*gbest(1,1,1))-gbest(1,2,1)*sin(4*pi.*gbest(1,2,1)+pi+1);
for j=2:itmax
V(:,:,j)=W(j-1)*V(:,:,j-1)+c1*rand*(pbest(:,:,j-1)-x(:,:,j-1))+c2*rand*(G(:,:,j-1)-x(:,:,j-1))
x(:,:,j)=x(:,:,j-1)+V(:,:,j);
for xx=1:N
for yy=1:D
if x(xx,yy,j)<a
x(xx,yy,j)=a;
end;
if x(xx,yy,j)>b
x(xx,yy,j)=b;
end;
end;
end;
for i=1:N
F(i,1,j)=x(i,1,j)*sin(4*pi.*x(i,1,j))-x(i,2,j)*sin(4*pi.*x(i,2,j)+pi+1);
end;
media=mean(F(:,1,j));
vmfit=[vmfit media];
[C,I]=max(abs(F(:,:,j)));
B(1,1,j)=C;
gbest(1,1,j)=x(I,1,j);
gbest(1,2,j)=x(I,2,j);
Fb(1,1,j)=gbest(1,1,j)*sin(4*pi.*gbest(1,1,j))-gbest(1,2,j)*sin(4*pi.*gbest(1,2,j)+pi+1);
[C,I]=max(Fb(1,1,:));
if C>Fb(1,1,j)
gbest(1,1,j)=gbest(1,1,I);
gbest(1,2,j)=gbest(1,2,I);
end;
for p=1:N
for r=1:D
G(p,r,j)=gbest(1,r,j);
end;
end;
Fbest(1,1,j)=G(1,1,j)*sin(4*pi.*G(1,1,j))-G(1,2,j)*sin(4*pi.*G(1,2,j)+pi+1);
for i=1:N
[C,I]=max(F(i,1,:));
if F(i,1,j)>=C
pbest(i,:,j)=x(i,:,j);
else
pbest(i,:,j)=x(i,:,I);
end;
end;
end
gbest(1,:,itmax)
Fbest(1,1,itmax)
%Random deployment algorithm
sx=a+(b-a)*rand(N,D,1);
sy=a+(b-a)*rand(N,D,1);
sz=a+(b-a)*rand(N,D,1);
%
%Gradient direction algorithm
figure(1);
mesh(vxp,vyp,vzp);
hold on;
plot3(x(:,1,1),x(:,2,1),F(:,1,1),'k*')
title('Gradient direction algorithm hydrophone distribution');
%Left view
%view(-90,0)
xlabel('Simulated underwater area width(kilometre)');
ylabel('Simulated underwater area length(kilometre)');
zlabel('Simulated water depth(kilometre)');
grid on;
figure(2)
mesh(vxp,vyp,vzp);
hold on;
plot3(sx,sy,sz,'k*','MarkerSize',5)
title('Random deployment algorithm hydrophone distribution');
%Left view
%view(-90,0)
xlabel('Simulated underwater area width(kilometre)');
ylabel('Simulated underwater area length(kilometre)');
zlabel('Simulated water depth(kilometre)');
grid on;
figure(3);
i_draw4=1:itmax;
Fbest1(i_draw4)=Fbest(1,1,i_draw4);
i_draw4=i_draw4';
plot(i_draw4,Fbest1);
hold on;
plot(vmfit,'r');
hold off;
title('Optimal, average function value change trend');
xlabel('Generations');
ylabel('J(\theta)');
grid on;
3 仿真结果
4 参考文献
[1]何敏, 刘建伟, 胡久松. 遗传优化核极限学习机的数据分类算法[J]. 传感器与微系统, 2017, 36(10):3.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。