function [fMin, bestX, Convergence_curve] = SSA(pop, M, c, d, dim,data)
P_percent = 0.2; % The population size of producers accounts for "P_percent" percent of the total population size
pNum = round( pop * P_percent ); % The population size of the producers
lb= c.*ones( 1,dim ); % Lower limit/bounds/ a vector
ub= d.*ones( 1,dim ); % Upper limit/bounds/ a vector
%Initialization
for i = 1 : pop
x( i, : ) = lb + (ub - lb) .* rand( 1, dim );
fit( i ) = fun( x( i, : ),data ) ;
end
pFit = fit;
pX = x; % The individual's best position corresponding to the pFit
[ fMin, bestI ] = min( fit ); % fMin denotes the global optimum fitness value
bestX = x( bestI, : ); % bestX denotes the global optimum position corresponding to fMin
% Start updating the solutions
for t = 1 : M
[~, sortIndex] = sort( pFit );% Sort
[fmax,B] = max( pFit );
worse = x(B,:);
r2 = rand(1);
%% 发现者位置更新
if(r2<0.8)
for i = 1 : pNum % Equation (3)
r1=rand(1);
x( sortIndex( i ), : ) = pX( sortIndex( i ), : )*exp(-(i)/(r1*M));
x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );
fit( sortIndex( i ) ) = fun( x( sortIndex( i ), : ),data );
end
else
for 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 ) ) = fun( x( sortIndex( i ), : ),data );
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);
else
x( 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 ) ) = fun( x( sortIndex( i ), : ),data );
end
c=randperm(numel(sortIndex));
b=sortIndex(c(1:20));
%% 警戒值位置更新
for j = 1 : length(b) % Equation (5)
if( pFit( sortIndex( b(j) ) )>(fMin) )
x( sortIndex( b(j) ), : )=bestX+(randn(1,dim)).*(abs(( pX( sortIndex( b(j) ), : ) -bestX)));
else
x( sortIndex( b(j) ), : ) =pX( sortIndex( b(j) ), : )+(2*rand(1)-1)*(abs(pX( sortIndex( b(j) ), : )-worse))/ ( pFit( sortIndex( b(j) ) )-fmax+1e-50);
end
x( sortIndex(b(j) ), : ) = Bounds( x( sortIndex(b(j) ), : ), lb, ub );
fit( sortIndex( b(j) ) ) = fun( x( sortIndex( b(j) ), : ),data );
end
for i = 1 : pop
if ( fit( i ) < pFit( i ) )
pFit( i ) = fit( i );
pX( i, : ) = x( i, : );
end
if( pFit( i ) < fMin )
fMin= pFit( i );
bestX = pX( i, : );
end
end
Convergence_curve(t)=fMin;
end
%Application of simple limits/bounds
function s = Bounds( s, Lb, Ub)
% Apply the lower bound vector
temp = s;
I = temp < Lb;
temp(I) = Lb(I);
% Apply the upper bound vector
J = temp > Ub;
temp(J) = Ub(J);
% Update this new move
s = temp;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
- 基于麻雀搜索i算法优化SVM参数(惩罚因子C和核参数sigma) - 可更换其他群智能算法 - 注释详细 以下是一些学习matlab的经验:1. 开始学习MATLAB之前,建议你阅读官方提供的MATLAB文档和教程,了解MATLAB的基本语法、变量和操作符等。2. MATLAB支持不同类型的数据,包括数字、字符串、矩阵和结构体等。学习如何创建、操作和处理这些数据类型是很重要的。3. MATLAB官方网站上有大量的示例和教程,可以帮助你学习各种MATLAB功能和应用。你可以按照这些示例逐步学习和实践。
资源推荐
资源详情
资源评论
收起资源包目录
SSA-SVM.rar (11个子文件)
SSA-SVM
SSA.m 3KB
main_svm.m 3KB
dataset
Parliment1984.mat 2KB
heartdata.mat 3KB
breast-cancer-wisconsin.mat 82KB
lymphography.mat 940B
winedata.mat 5KB
iris.mat 1KB
carevaluation.mat 1KB
ionosphere.mat 57KB
fun.m 354B
共 11 条
- 1
资源评论
天`南
- 粉丝: 1282
- 资源: 186
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功