1 简介
支持向量机 (Support Vector Machines, SVM) 是一种应用广泛的机器学习方法, 具有理论知识清晰完备,适应性和泛化能力良好的优点, 核心思想是在特征空间中寻找到一个最优超平面将两类样本尽可能大的分开, 能够较好的处理小样本、非线性和克服“维数灾难”问题, 并且表现出优秀的分类能力和泛化能力而被广泛应用于分类和回归等领域. 但是 SVM 对核函数的参数选取对分类效果影响很大, 不合适的参数可能使得分类器性能大大降低. 针对 SVM 核参数的选取问题, 目前尚没有统一有效的方法. 传统的参数选择方法如实验法、网格搜索法等由于耗时过长和不必要的验证流程等缺点, 更常用的方法是群智能算法如蚁群算法、遗传算法和粒子群算法等优化支持向量机核参数.粒子群算法由于算法结构简单、寻优能力相对较好, 近年来选择哈里斯鹰算法优化 SVM 参数成为研究热点之一.。
2 部分代码
%%
function [Rabbit_Energy,Rabbit_Location,CNVG] = NCHHO_IoV(N,T,lb,ub,dim,fobj)
% initialize the location and Energy of the rabbit
Rabbit_Location=zeros(1,dim);
Rabbit_Energy=0;
%Initialize the locations of Harris' hawks
X=initialization(N,dim,ub,lb);
CNVG=zeros(1,T);
t=0; % Loop counter
while t<T
for i=1:size(X,1)
% Check boundries
FU=X(i,:)>ub;FL=X(i,:)<lb;X(i,:)=(X(i,:).*(~(FU+FL)))+ub.*FU+lb.*FL;
% fitness of locations
fitness=fobj(X(i,:));
% Update the location of Rabbit
if fitness>Rabbit_Energy
Rabbit_Energy=fitness;
Rabbit_Location=X(i,:);
end
end
E1=abs(2*(1-(t/T))-2); % factor to show the decreaing energy of rabbit
a1 = 4; % Initial chaotic map parameter configuration
teta = 0.7; % Initial chaotic map parameter configuration
% Update the location of Harris' hawks
for i=1:size(X,1)
for ii=1:4
Cm(1,ii) = abs((a1/4)*sin(pi*teta));
teta = Cm(1,ii);
end
E0=2*rand()-1; %-1<E0<1
Escaping_Energy=E1*(E0); % escaping energy of rabbit
if abs(Escaping_Energy)>=1
%% Exploration:
% Harris' hawks perch randomly based on 2 strategy:
q=rand();
rand_Hawk_index = floor(N*rand()+1);
X_rand = X(rand_Hawk_index, :);
if q<0.5
% perch based on other family members
X(i,:)=X_rand-Cm(1,1)*abs(X_rand-2*Cm(1,2)*X(i,:));
elseif q>=0.5
% perch on a random tall tree (random site inside group's home range)
X(i,:)=(Rabbit_Location(1,:)-mean(X))-Cm(1,3)*((ub-lb)*Cm(1,4)+lb);
end
elseif abs(Escaping_Energy)<1
%% Exploitation:
% Attacking the rabbit using 4 strategies regarding the behavior of the rabbit
%% phase 1: surprise pounce (seven kills)
% surprise pounce (seven kills): multiple, short rapid dives by different hawks
r=rand(); % probablity of each event
if r>=0.5 && abs(Escaping_Energy)<0.5 % Hard besiege
X(i,:)=(Rabbit_Location)-Escaping_Energy*abs(Rabbit_Location-X(i,:));
end
if r>=0.5 && abs(Escaping_Energy)>=0.5 % Soft besiege
Jump_strength=2*(1-rand()); % random jump strength of the rabbit
X(i,:)=(Rabbit_Location-X(i,:))-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:));
end
%% phase 2: performing team rapid dives (leapfrog movements)
if r<0.5 && abs(Escaping_Energy)>=0.5 % Soft besiege % rabbit try to escape by many zigzag deceptive motions
w1=2*exp(-(8*t/T)^2); % Non-linear control Parameter
Jump_strength=2*(1-rand());
X1=w1*Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:));
if fobj(X1)>fobj(X(i,:)) % improved move?
X(i,:)=X1;
else % hawks perform levy-based short rapid dives around the rabbit
X2=w1*Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:))+rand(1,dim).*Levy(dim);
if (fobj(X2)>fobj(X(i,:))) % improved move?
X(i,:)=X2;
end
end
end
if r<0.5 && abs(Escaping_Energy)<0.5 % Hard besiege % rabbit try to escape by many zigzag deceptive motions
% hawks try to decrease their average location with the rabbit
w1=2*exp(-(8*t/T)^2);
Jump_strength=2*(1-rand());
X1=w1*Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(X));
if fobj(X1)>fobj(X(i,:)) % improved move?
X(i,:)=X1;
else % Perform levy-based short rapid dives around the rabbit
X2=w1*Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(X))+rand(1,dim).*Levy(dim);
if (fobj(X2)>fobj(X(i,:))) % improved move?
X(i,:)=X2;
end
end
end
%%
end
end
t=t+1;
CNVG(t)=Rabbit_Energy;
end
end
% ___________________________________
function o=Levy(d)
beta=1.5;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);
u=randn(1,d)*sigma;v=randn(1,d);step=u./abs(v).^(1/beta);
o=step;
end
3 仿真结果
4 参考文献
[1]颜晓娟. 基于改进遗传算法寻优的SVM风能短期预测. Diss. 广西大学, 2015.
部分理论引用网络文献,若有侵权联系博主删除。