LSTM长短期记忆网络对车辆尾气排放进行预测
Posted studyer_domi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LSTM长短期记忆网络对车辆尾气排放进行预测相关的知识,希望对你有一定的参考价值。
1、内容简介
略
485-可以交流、咨询、答疑
2、内容说明
略
3、仿真分析
略
clc
close all
clear
data = xlsread('新建 Microsoft Excel 工作表 (2).xlsx');
[row,cln] = size(data);
%序列的前 90% 用于训练,后 10% 用于测试
numTimeStepsTrain = floor(0.9*row);
dataTrain = data(1:numTimeStepsTrain+1,:);
dataTest = data(numTimeStepsTrain+1:end,:);
%输入LSTM的时间序列交替一个时间步
mu = mean(dataTrain);
sig = std(dataTrain);
dataTrainStandardized = (dataTrain - mu) ./ sig;
XTrain = dataTrainStandardized(1:end-1,:);
YTrain = dataTrainStandardized(2:end,:);
numFeatures = cln;
numResponses = cln;
numHiddenUnits = 200;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',250, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(XTrain',YTrain',layers,options);
dataTestStandardized = (dataTest - mu) ./ sig;
XTest = dataTestStandardized(1:end-1,:);
net = predictAndUpdateState(net,XTrain');
[net,YPred] = predictAndUpdateState(net,YTrain(end,:)');
numTimeStepsTest = length(XTest);
for i = 2:numTimeStepsTest
[net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1),'ExecutionEnvironment','cpu');
end
% YPred = sig*YPred + mu;
for i = 1:numTimeStepsTest
YPred(:,i) = YPred(:,i).*sig' + mu';
end
YTest = dataTest(2:end,:)';
rmse = sqrt(mean((YPred(:,6)-YTest(:,6)).^2))
figure
plot(dataTrain(1:end-1,6))
hold on
idx = numTimeStepsTrain:(numTimeStepsTrain+numTimeStepsTest);
plot(idx,[data(numTimeStepsTrain,6) YPred(6,:)],'.-')
hold off
xlabel("time")
ylabel("排放")
title("预测")
legend(["观测量" "预测量"])
figure
subplot(2,1,1)
plot(YTest(6,:))
hold on
plot(YPred(6,:),'.-')
hold off
legend(["观测量" "预测量"])
ylabel("排放")
title("预测量")
subplot(2,1,2)
stem(YPred(6,:) - YTest(6,:))
xlabel("time")
ylabel("Error")
title("RMSE = " + rmse)
4、参考论文
略
以上是关于LSTM长短期记忆网络对车辆尾气排放进行预测的主要内容,如果未能解决你的问题,请参考以下文章
回归预测 | MATLAB实现GA-LSTM遗传算法优化长短期记忆网络的数据多输入单输出回归预测
时序预测 | MATLAB实现LSTM-SVR(长短期记忆神经网络-支持向量机)时间序列预测
Matlab基于长短期记忆网络分类LSTM实现多分类预测(Excel可直接替换数据)