% Grey Wolf Optimizer
function [Alpha_score,Alpha_pos,Convergence_curve]=GWO(inputnum,outputnum,inputn,label_train,inputn_test,true_label)
SearchAgents_no=20; % Number of search agents
Max_iter=60; % Maximum numbef of iterations
% Load details of the selected benchmark function
ccc = 0;
dim=2;
ub = [60 0.02];
lb = [10 0.0001];
% ub = (1*ones(numsum,1))';%上边界,可以修改
% lb = (-1*ones(numsum,1))';%下边界,可以修改
% initialize alpha, beta, and delta_pos
Alpha_pos=zeros(1,dim);
Alpha_score=inf; %change this to -inf for maximization problems
Beta_pos=zeros(1,dim);
Beta_score=inf; %change this to -inf for maximization problems
Delta_pos=zeros(1,dim);
Delta_score=inf; %change this to -inf for maximization problems
%Initialize the positions of search agents
Positions=initialization(SearchAgents_no,dim,ub,lb);
Convergence_curve=zeros(1,Max_iter);
l=0;% Loop counter
% Main loop
while l<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
[predict_label,y] = fun(Positions(i,:),inputnum,outputnum,inputn,label_train,inputn_test,true_label);
fitness = 1-y;
% Update Alpha, Beta, and Delta
if fitness<Alpha_score
vvv = predict_label;
Alpha_score=fitness; % Update alpha
Alpha_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness<Beta_score
Beta_score=fitness; % Update beta
Beta_pos=Positions(i,:);
end
if fitness>Alpha_score && fitness>Beta_score && fitness<Delta_score
Delta_score=fitness; % Update delta
Delta_pos=Positions(i,:);
end
end
% a=2-l*((2)/Max_iter); % a decreases linearly fron 2 to 0
a = 1-1*(1/(exp(1))*(exp(l/Max_iter)));
% Update the Position of search agents including omegas
for i=1:size(Positions,1)
for j=1:size(Positions,2)
r1=rand(); % r1 is a random number in [0,1]
r2=rand(); % r2 is a random number in [0,1]
A1=2*a*r1-a; % Equation (3.3)
C1=2*r2; % Equation (3.4)
D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j)); % Equation (3.5)-part 1
X1=Alpha_pos(j)-A1*D_alpha; % Equation (3.6)-part 1
r1=rand();
r2=rand();
A2=2*a*r1-a; % Equation (3.3)
C2=2*r2; % Equation (3.4)
D_beta=abs(C2*Beta_pos(j)-Positions(i,j)); % Equation (3.5)-part 2
X2=Beta_pos(j)-A2*D_beta; % Equation (3.6)-part 2
r1=rand();
r2=rand();
A3=2*a*r1-a; % Equation (3.3)
C3=2*r2; % Equation (3.4)
D_delta=abs(C3*Delta_pos(j)-Positions(i,j)); % Equation (3.5)-part 3
X3=Delta_pos(j)-A3*D_delta; % Equation (3.5)-part 3
Positions(i,j)=(X1+X2+X3)/3;
end
end
l=l+1;
Convergence_curve(l)=1-Alpha_score;
disp(['GWO: At iteration ', num2str(l), ' ,the best fitness is ', num2str(Convergence_curve(l))]);
end
figure;
stem(true_label,'*')
hold on
plot(vvv,'p')
yticks(0:1:2)
xlabel('样本','fontsize',12,'fontname','TimesNewRoman');
ylabel('标签值','fontsize',12,'fontname','TimesNewRoman');
title(['GWO-LSTM分类准确率:',num2str(Convergence_curve(l)*100),'%'],'fontsize',12,'fontname','TimesNewRoman');
legend('实际值','预测值','fontsize',12,'fontname','TimesNewRoman');
%% 画方框图
confMat = confusionmat(true_label,vvv); %output_test是真实值标签
figure;
set(gca,'looseInset',[0 0 0 0])
% set(gcf,'unit','centimeters','position',[5 2 23 15])
plotConfMat(confMat.');
xlabel('预测标签','fontsize',12,'fontname','TimesNewRoman');
ylabel('真实标签','fontsize',12,'fontname','TimesNewRoman');
title(['GWO-LSTM分类准确率:',num2str(Convergence_curve(l)*100),'%'],'fontsize',12,'fontname','TimesNewRoman');
hold off
end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
GWO-LSTM数据分类预测(Matlab完整程序和数据) 多特征输入单输出的二分类及多分类模型。程序内注释详细,直接替换数据就可以用。程序语言为matlab,程序可出分类效果图,混淆矩阵图。
资源推荐
资源详情
资源评论
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/ZIP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/ZIP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 8 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- W_55577772024-03-17资源内容详尽,对我有使用价值,谢谢资源主的分享。
- shansha_zong4562024-01-02终于找到了超赞的宝藏资源,果断冲冲冲,支持!
- laotang00052023-12-12资源质量不错,和资源描述一致,内容详细,对我很有用。
![avatar](https://profile-avatar.csdnimg.cn/3899c4bd75d14bc2a043f1b2f2416dfc_m0_57362105.jpg!1)
前程算法屋
- 粉丝: 4466
- 资源: 712
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)