回归预测 | Matlab基于SO-LSTM蛇群算法优化长短期记忆神经网络的数据多输入单输出回归预测
目录
- 回归预测 | Matlab基于SO-LSTM蛇群算法优化长短期记忆神经网络的数据多输入单输出回归预测
- 效果一览
- 基本介绍
- 程序设计
- 参考资料
效果一览
基本介绍
1.Matlab基于SO-BiLSTM蛇群算法优化双向长短期记忆神经网络的数据多输入单输出回归预测(完整源码和数据);
2.优化参数为:学习率,隐含层节点,正则化参数。
3.多特征输入单输出的回归预测。程序内注释详细,直接替换数据就可以用。
4.程序语言为matlab,程序可出预测效果图,迭代优化图,相关分析图,运行环境matlab2020b及以上。评价指标包括:R2、MAE、MSE、RMSE和MAPE等。
5.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。
程序设计
- 完整源码和数据获取方式(资源处下载):Matlab基于SO-BiLSTM蛇群算法优化双向长短期记忆神经网络的数据多输入单输出回归预测。
function [fval,Xfood,gbest_t] = SO(N,T,lb,ub,dim,fobj)
%initial
vec_flag=[1,-1];
Threshold=0.25;
Thresold2= 0.6;
C1=0.5;
C2=.05;
C3=2;
X=initialization(N,dim,ub,lb);
for i=1:N
fitness(i)=feval(fobj,X(i,:));
end
[GYbest, gbest] = min(fitness);
Xfood = X(gbest,:);
%Diving the swarm into two equal groups males and females
Nm=round(N/2);%eq.(2&3)
Nf=N-Nm;
Xm=X(1:Nm,:);
Xf=X(Nm+1:N,:);
fitness_m=fitness(1:Nm);
fitness_f=fitness(Nm+1:N);
[fitnessBest_m, gbest1] = min(fitness_m);
Xbest_m = Xm(gbest1,:);
[fitnessBest_f, gbest2] = min(fitness_f);
Xbest_f = Xf(gbest2,:);
for t = 1:T
disp([' ',num2str(t),' ε '])
Temp=exp(-((t)/T)); %eq.(4)
Q=C1*exp(((t-T)/(T)));%eq.(5)
if Q>1 Q=1; end
% Exploration Phase (no Food)
if Q<Threshold
for i=1:Nm
for j=1:1:dim
rand_leader_index = floor(Nm*rand()+1);
X_randm = Xm(rand_leader_index, :);
flag_index = floor(2*rand()+1);
Flag=vec_flag(flag_index);
Am=exp(-fitness_m(rand_leader_index)/(fitness_m(i)+eps));%eq.(7)
Xnewm(i,j)=X_randm(j)+Flag*C2*Am*((ub(j)-lb(j))*rand+lb(j));%eq.(6)
end
end
for i=1:Nf
for j=1:1:dim
rand_leader_index = floor(Nf*rand()+1);
X_randf = Xf(rand_leader_index, :);
flag_index = floor(2*rand()+1);
Flag=vec_flag(flag_index);
Af=exp(-fitness_f(rand_leader_index)/(fitness_f(i)+eps));%eq.(9)
Xnewf(i,j)=X_randf(j)+Flag*C2*Af*((ub(j)-lb(j))*rand+lb(j));%eq.(8)
end
end
else %Exploitation Phase (Food Exists)
if Temp>Thresold2 %hot
for i=1:Nm
flag_index = floor(2*rand()+1);
Flag=vec_flag(flag_index);
for j=1:1:dim
Xnewm(i,j)=Xfood(j)+C3*Flag*Temp*rand*(Xfood(j)-Xm(i,j));%eq.(10)
end
end
for i=1:Nf
flag_index = floor(2*rand()+1);
Flag=vec_flag(flag_index);
for j=1:1:dim
Xnewf(i,j)=Xfood(j)+Flag*C3*Temp*rand*(Xfood(j)-Xf(i,j));%eq.(10)
end
end
else %cold
if rand>0.6 %fight
for i=1:Nm
for j=1:1:dim
FM=exp(-(fitnessBest_f)/(fitness_m(i)+eps));%eq.(13)
Xnewm(i,j)=Xm(i,j) +C3*FM*rand*(Q*Xbest_f(j)-Xm(i,j));%eq.(11)
end
end
for i=1:Nf
for j=1:1:dim
FF=exp(-(fitnessBest_m)/(fitness_f(i)+eps));%eq.(14)
Xnewf(i,j)=Xf(i,j)+C3*FF*rand*(Q*Xbest_m(j)-Xf(i,j));%eq.(12)
end
end
else%mating
for i=1:Nm
for j=1:1:dim
Mm=exp(-fitness_f(i)/(fitness_m(i)+eps));%eq.(17)
Xnewm(i,j)=Xm(i,j) +C3*rand*Mm*(Q*Xf(i,j)-Xm(i,j));%eq.(15
end
end
for i=1:Nf
for j=1:1:dim
Mf=exp(-fitness_m(i)/(fitness_f(i)+eps));%eq.(18)
Xnewf(i,j)=Xf(i,j) +C3*rand*Mf*(Q*Xm(i,j)-Xf(i,j));%eq.(16)
end
end
参考资料
[1] https://blog.csdn.net/kjm13182345320/article/details/129215161
[2] https://blog.csdn.net/kjm13182345320/article/details/128105718