目录
1 主要内容
非惯性权重模型
纵横交叉策略模型
2 部分程序
3 程序结果
4 程序链接
1 主要内容
该程序参考文献《基于Sobol序列和纵横交叉策略的麻雀搜索算法》对麻雀搜索算法进行改进,实现了基于纵横交叉策略和非线性权重因子的麻雀搜索算法 改进SSA算法【matlab代码】,主要改进如下:
- 改进1:采用一种指数形式的非线性惯性权重提高算法的收敛效率。
- 改进2:应用纵横交叉策略对算法进行改进,利用横向交叉增强全局搜索能力,利用纵向交叉保持种群的多样性并防止算法陷入局部最优。
-
非惯性权重模型
-
纵横交叉策略模型
2 部分程序
% 改进1:★★非线性惯性权重★★w = exp(1-(M+t)/(M-t));x( sortIndex( i ), : ) = pX( sortIndex( i ), : ) * w; x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) ); end elsefor i = 1 : pNum x( sortIndex( i ), : ) = pX( sortIndex( i ), : )+randn(1)*ones(1,dim);x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) ); end end[~, bestII] = min(fit); bestXX = x(bestII,:); %% 跟随者位置更新 for i = ( pNum + 1 ) : pop % Equation (4) A=floor(rand(1,dim)*2)*2-1;if( i>(pop/2))x( sortIndex(i ), : )=randn(1)*exp((worse-pX( sortIndex( i ), : ))/(i)^2);elsex( sortIndex( i ), : )=bestXX+(abs(( pX( sortIndex( i ), : )-bestXX)))*(A'*(A*A')^(-1))*ones(1,dim); end x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );fit( sortIndex( i ) ) = fobj( x( sortIndex( i ), : ) );end c=randperm(numel(sortIndex)); b=sortIndex(c(1:20)); %% 警戒者位置更新 for j = 1 : length(b) % Equation (5)% 改进2.1:★★横向交叉策略★★if (mod(j,2) == 1)for i = 1 : dimr = rand();c = 2*rand()-1;x_criss( sortIndex( b(j) ), i ) = r * pX( sortIndex( b(j) ), i )+(1-r)*pX( sortIndex( b(j+1) ), i )+c*(pX( sortIndex( b(j) ), i )-pX( sortIndex( b(j+1) ), i ));endelsefor i = 1 : dimr = rand();c = 2*rand()-1;x_criss( sortIndex( b(j) ), i ) = r * pX( sortIndex( b(j-1) ), i )+(1-r)*pX( sortIndex( b(j) ), i )+c*(pX( sortIndex( b(j-1) ), i )-pX( sortIndex( b(j) ), i ));endendif fobj( x_criss( sortIndex( b(j) ), : ) ) < fobj( pX( sortIndex( b(j) ), : ) )x( sortIndex( b(j) ), : ) = x_criss( sortIndex( b(j) ), : );elsex( sortIndex( b(j) ), : ) = pX( sortIndex( b(j) ), : );endx( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub );fit( sortIndex( b(j) ) ) = fobj( x( sortIndex( b(j) ), : ) );% 改进2.2:★★纵向交叉策略★★for i = 1 : dimd1 = randperm(dim,1);d2 = randperm(dim,1);r1 = rand();x_cross(sortIndex( b(j) ), i) = r1*x( sortIndex(b(j) ), d1 ) + (1-r1)*x( sortIndex(b(j) ), d2 );endif fobj( x_cross( sortIndex( b(j) ), : ) ) < fobj( x( sortIndex( b(j) ), : ) )x( sortIndex( b(j) ), : ) = x_cross( sortIndex( b(j) ), : );elsex( sortIndex( b(j) ), : ) = x( sortIndex( b(j) ), : );endx( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub );fit( sortIndex( b(j) ) ) = fobj( x( sortIndex( b(j) ), : ) ); end
程序实现了23种测试函数,可以通过更改main函数中的“F+编号”进行多函数性能测试。
3 程序结果
测试函数1
测试函数10
结果表明:改进算法较原算法优势显著。
智能算法最重要的就是改进策略,这种策略形式也可以用到其他智能算法里面,通过其他方式的组合形成新的改进算法,也是智能算法创新的重要方向。
4 程序链接
点击直达!