✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

⛄ 内容介绍

度,本文使用鲸鱼优化算法(WOA)来优化GRU的初始参数,并以此建立了WOA-GRU软测量模型。最后,将该方法应用于丙烯精馏塔中塔顶丙烷浓度的预测,实验结果表明,在动态建模方面WOA-GRU具有更高的预测精度。

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_sed

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_sed_02

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_神经网络_03

⛄ 部分代码

clc; clear; close all;

%Model Parameters and excitation

%--------------------------------------------------------------------------

M=[1 0; 0 1];

K=[2 -1; -1 1]*5;

C=0.1*M+0.1*K;

f=2*randn(2,10000);

fs=100;

%Apply modal superposition to get response

%--------------------------------------------------------------------------

n=size(f,1);

dt=1/fs; %sampling rate

[Vectors, Values]=eig(K,M);

Freq=sqrt(diag(Values))/(2*pi); % undamped natural frequency

steps=size(f,2);

Mn=diag(Vectors'*M*Vectors); % uncoupled mass

Cn=diag(Vectors'*C*Vectors); % uncoupled damping

Kn=diag(Vectors'*K*Vectors); % uncoupled stifness

wn=sqrt(diag(Values));

zeta=Cn./(sqrt(2.*Mn.*Kn));  % damping ratio

wd=wn.*sqrt(1-zeta.^2);

fn=Vectors'*f; % generalized input force matrix

t=[0:dt:dt*steps-dt];

for i=1:1:n

    h(i,:)=(1/(Mn(i)*wd(i))).*exp(-zeta(i)*wn(i)*t).*sin(wd(i)*t); %transfer function of displacement

    hd(i,:)=(1/(Mn(i)*wd(i))).*(-zeta(i).*wn(i).*exp(-zeta(i)*wn(i)*t).*sin(wd(i)*t)+wd(i).*exp(-zeta(i)*wn(i)*t).*cos(wd(i)*t)); %transfer function of velocity

    hdd(i,:)=(1/(Mn(i)*wd(i))).*((zeta(i).*wn(i))^2.*exp(-zeta(i)*wn(i)*t).*sin(wd(i)*t)-zeta(i).*wn(i).*wd(i).*exp(-zeta(i)*wn(i)*t).*cos(wd(i)*t)-wd(i).*((zeta(i).*wn(i)).*exp(-zeta(i)*wn(i)*t).*cos(wd(i)*t))-wd(i)^2.*exp(-zeta(i)*wn(i)*t).*sin(wd(i)*t)); %transfer function of acceleration

    qq=conv(fn(i,:),h(i,:))*dt;

    qqd=conv(fn(i,:),hd(i,:))*dt;

    qqdd=conv(fn(i,:),hdd(i,:))*dt;

    q(i,:)=qq(1:steps); % modal displacement

    qd(i,:)=qqd(1:steps); % modal velocity

    qdd(i,:)=qqdd(1:steps); % modal acceleration

end

x=Vectors*q; %displacement

v=Vectors*qd; %vecloity

a=Vectors*qdd; %vecloity

%Add noise to excitation and response

%--------------------------------------------------------------------------

f2=f+0.0*randn(2,10000);

a2=a+0.0*randn(2,10000);

v2=v+0.0*randn(2,10000);

x2=x+0.0*randn(2,10000);

%Plot displacement of first floor without and with noise

%--------------------------------------------------------------------------

figure;

subplot(2,2,1)

plot(t,f(1,:)); xlabel('Time (sec)');  ylabel('Force1'); title('First Floor');

subplot(2,2,2)

plot(t,f(2,:)); xlabel('Time (sec)');  ylabel('Force2'); title('Second Floor');

subplot(2,2,3)

plot(t,x(1,:)); xlabel('Time (sec)');  ylabel('DSP1');

subplot(2,2,4)

plot(t,x(2,:)); xlabel('Time (sec)');  ylabel('DSP2');

%Identification using neural network

%--------------------------------------------------------------------------

X=f2;                                  %Input of neural network is forces

T=x2;                                  %Output of neural network is displacement

[X,~] = tonndata(X,1,0);               %Change format of input data

[T,~] = tonndata(T,1,0);               %Change format of output data

net = narxnet(0,1,2);                  %Create (nonlinear autoregressive with external input) network with 0 input delays and 1 output delays

[Xs,Xi,Ai,Ts] = preparets(net,X,{},T); %Prepares data for training

net = train(net,Xs,Ts,Xi,Ai);          %Train the network

view(net)                              %View the network

Yopen = net(Xs,Xi,Ai);                 %Predict Output

net = closeloop(net);                  %convert to closed loop neural network

view(net);                             %view closed-loop network

[Xs,Xi,Ai,Ts] = preparets(net,X,{},T); %Prepares data for training

net = train(net,Xs,Ts,Xi,Ai);          %Train the network

Yclosed = net(Xs,Xi,Ai);               %Predict Output

%Plot output with predicted output

%--------------------------------------------------------------------------

T=cell2mat(T);

Yopen=cell2mat(Yopen);

Yclosed=cell2mat(Yclosed);

figure;

subplot(2,1,1);

plot(t(1,2:end),T(1,2:end),'b-',t(1,2:end),Yopen(1,:),'r--',t(1,2:end),Yclosed(1,:),'k-.'); xlabel('Time (sec)');  ylabel('DSP1');

legend('Actual','Predicted (openloop)','Predicted (closedloop)');

subplot(2,1,2);

plot(t(2:end),T(2,2:end),'b-',t(2:end),Yopen(2,:),'r--',t(1,2:end),Yclosed(2,:),'k-.'); xlabel('Time (sec)');  ylabel('DSP2');

⛄ 运行结果

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_Time_04

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_sed_05

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_Time_06

【GRU回归预测】基于鲸鱼优化算法优化门控循环单元WOA-GRU实现负荷数据回归预测附matlab代码_sed_07

⛄ 参考文献

[1]王康, 龚文杰, 段晓燕,等. 基于PSO算法优化GRU神经网络的短期负荷预测[J]. 广东电力, 2020, 33(4):7.

[2]李祚敏, 秦江涛. 基于WOA-GRU的销售预测研究[J]. 软件导刊, 2020, 19(9):4.

[3]杨丽娜, 赵鹏, 王佩哲. 基于GRU神经网络的数据中心能耗预测模型研究[J]. 电力信息化, 2021, 019(003):10-18.

⛳️ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料