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!