stacked LSTm Code for time series forecasting

10 ビュー (過去 30 日間)
NN
NN 2020 年 12 月 11 日
回答済み: NGR MNFD 2021 年 7 月 2 日
Can anyone guide me how to write code for stacked lstm in the below code:
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];

回答 (3 件)

Abhishek Gupta
Abhishek Gupta 2020 年 12 月 15 日
Hi,
As per my understanding, you want to define an LSTM model comprise of multiple LSTM layers. One can perform this task as follows: -
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits1)
lstmLayer(numHiddenUnits2)
fullyConnectedLayer(numClasses)
regressionLayer];
Referring to the following documentation for more information: -

nahed zemouri
nahed zemouri 2021 年 1 月 11 日
hello
ihave a question about times series forecasting using LSTM
this is my program and i have this error please help me
close all; clear; clc;
load Tucson;
Input1= GHI_hour_Y1;
Input2=GHI_hour_Y2;
Pmpp=[Input1, Input2];%%%%%vecteur
%Output data
for i=1:length(Pmpp)
if Pmpp(i) <0
Pmpp(i)=0;
else
Pmpp(i)=Pmpp(i);
end
end
%Partition the training and test data.
numTimeStepsTrain = floor(0.7*numel(Pmpp));
dataTrain_S = Pmpp(1:numTimeStepsTrain+1);
dataTest_S = Pmpp(numTimeStepsTrain+1:end);
dataTrain_Pmpp = Pmpp(1:numTimeStepsTrain+1);
dataTest_Pmpp = Pmpp(numTimeStepsTrain+1:end);
%%Standardize Data
mu_S = mean(dataTrain_S);
sig_S = std(dataTrain_S);
dataTrainStandardized_S = (dataTrain_S - mu_S) / sig_S;
mu_Pmpp = mean(dataTrain_Pmpp);
sig_Pmpp = std(dataTrain_Pmpp);
dataTrainStandardized_Pmpp = (dataTrain_Pmpp - mu_Pmpp) / sig_Pmpp;
%%Prepare Predictors and Responses
XTrain = dataTrainStandardized_S(1:end-1);
XTrain = XTrain';
YTrain = dataTrainStandardized_Pmpp(1:end-1);
YTrain = YTrain';
for i=1:length(YTrain)
if YTrain(i) <0
YTrain(i)=0;
else
YTrain(i)=YTrain(i);
end
end
%%Define LSTM Network Architecture
numFeatures = 1;
numResponses = 1;
numHiddenUnits = 2;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',2, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
%%Train LSTM Network
net = trainNetwork(XTrain',YTrain',layers,options);
return
%%Forecast Future Time Steps
%Standardize the test data using the same parameters as the training data.
net = predictAndUpdateState(net,XTrain);
Error using nnet.internal.cnn.util.NetworkDataValidator/assertValidSequenceInput
(line 493)
The prediction sequences are of feature dimension 4949 but the input layer expects
sequences of feature dimension 1.
  1 件のコメント
Abhishek Gupta
Abhishek Gupta 2021 年 1 月 11 日
To get a quick answer, I suggest you create a new question rather than posting it as an answer here.
For more information: -

サインインしてコメントする。


NGR MNFD
NGR MNFD 2021 年 7 月 2 日
Hello . I hope you have a good day. I sent the article to your service. I implemented the coding part in the MATLAB software, but to implement my network, two lines of setlayers, training MATLAB 2014 give me an error. What other function do you think I should replace? Do you think the codes I wrote are correct?( I used gait-in-neurodegenerative-disease-database in physionet website.) Thanks a lot

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by