一、神经网络-支持向量机
支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数拟合等其他机器学习问题中。 1 数学部分 1.1 二维空间 2 算法部分
二、萤火虫算法
算法基本思想描述如下:在群体中,每个萤火虫个体被随机分布在目标函数定义的空间中,初始阶段,所有的萤火虫都具有相同的荧光素值和动态决策半径。其中,每个萤火虫个体根据来自动态决策半径内所有邻居萤火虫信号的强弱来决定其移动的方向。萤火虫的动态决策半径会随着在它范围内萤火虫个体的数目而变化,每个萤火虫的荧光素也会随着决策半径内萤火虫个体的数目而改变。萤火虫群优化算法是无记忆的,无需目标函数的全局信息和梯度信息,具有计算速度快,调节参数少,易于实现等特点。萤火虫进化过程中,每次迭代都由萤火虫的部署(初始化)、荧光素更新阶段、移动概率计算阶段、位置更新阶段、邻域范围更新阶段五个部分组成,现分别介绍如下:
1、萤火虫的部署(初始化)
2、荧光素更新阶段
3、移动概率计算阶段
4、位置更新阶段
5、邻域范围更新阶段
三、代码
% The Whale Optimization Algorithm function [Leader_score,Leader_pos,Convergence_curve]=WOA(SearchAgents_no,Max_iter,lb,ub,dim,fobj) % initialize position vector and score for the leader Leader_pos=zeros(1,dim); Leader_score=inf; %change this to -inf for maximization problems %Initialize the positions of search agents % Positions=initialization(SearchAgents_no,dim,ub,lb); Positions=ceil(rand(SearchAgents_no,dim).*(ub-lb)+lb); Convergence_curve=zeros(1,Max_iter); t=0;% Loop counter % Main loop while t<Max_iter for i=1:size(Positions,1) % Return back the search agents that go beyond the boundaries of the search space Flag4ub=Positions(i,:)>ub; Flag4lb=Positions(i,:)<lb; Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb; % Calculate objective function for each search agent fitness=fobj(Positions(i,:)); % Update the leader if fitness<Leader_score % Change this to > for maximization problem Leader_score=fitness; % Update alpha Leader_pos=Positions(i,:); end end a=2-t*((2)/Max_iter); % a decreases linearly fron 2 to 0 in Eq. (2.3) % a2 linearly dicreases from -1 to -2 to calculate t in Eq. (3.12) a2=-1+t*((-1)/Max_iter); % Update the Position of search agents for i=1:size(Positions,1) r1=rand(); % r1 is a random number in [0,1] r2=rand(); % r2 is a random number in [0,1] A=2*a*r1-a; % Eq. (2.3) in the paper C=2*r2; % Eq. (2.4) in the paper b=1; % parameters in Eq. (2.5) l=(a2-1)*rand+1; % parameters in Eq. (2.5) p = rand(); % p in Eq. (2.6) for j=1:size(Positions,2) if p<0.5 if abs(A)>=1 rand_leader_index = floor(SearchAgents_no*rand()+1); X_rand = Positions(rand_leader_index, :); D_X_rand=abs(C*X_rand(j)-Positions(i,j)); % Eq. (2.7) Positions(i,j)=X_rand(j)-A*D_X_rand; % Eq. (2.8) elseif abs(A)<1 D_Leader=abs(C*Leader_pos(j)-Positions(i,j)); % Eq. (2.1) Positions(i,j)=Leader_pos(j)-A*D_Leader; % Eq. (2.2) end elseif p>=0.5 distance2Leader=abs(Leader_pos(j)-Positions(i,j)); % Eq. (2.5) Positions(i,j)=distance2Leader*exp(b.*l).*cos(l.*2*pi)+Leader_pos(j); end end end t=t+1; Convergence_curve(t)=Leader_score; % [t Leader_score] end
5.参考文献:
书籍《MATLAB神经网络43个案例分析》