stacked LSTm Code for time series forecasting
11 次查看(过去 30 天)
显示 更早的评论
Can anyone guide me how to write code for stacked lstm in the below code:
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
0 个评论
回答(3 个)
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: -
0 个评论
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
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!