LSTM with vector as output for multi step ahead forecasting

10 vues (au cours des 30 derniers jours)
Alexander Stein
Alexander Stein le 19 Avr 2023
Commenté : Alexander Stein le 25 Avr 2023
Hello,
I would like to build a LSTM network that outputs a vector only on the last step (Outputmode = last).
Input-data: Sequence with a fixed size of [4,1344] (4 features, 1344 steps).
Output-data: Vector of size [96,1] (Output on last step)
My attempt so far:
numFeatures = 4;
numResponses = size(YTrain{1},1);
% Input layer
layers = sequenceInputLayer(numFeatures);
% variation of layers and hidden units
for i = 1:LSTMDepth-1
layers = [layers;lstmLayer(numHiddenUnits,OutputMode="sequence")];
end
layers = [layers;lstmLayer(numHiddenUnits,OutputMode="last")];
% Output layers
layers = [ layers
fullyConnectedLayer(numResponses)
regressionLayer];
% training options
maxEpochs = 300;
miniBatchSize = 20;
options = trainingOptions("adam", ...
ExecutionEnvironment="auto", ...
MaxEpochs=maxEpochs, ...
MiniBatchSize=miniBatchSize, ...
ValidationData={XValidation,YValidation}, ...
ValidationFrequency=30, ...
InitialLearnRate=params.InitialLearnRate, ...
LearnRateDropFactor=0.2, ...
LearnRateDropPeriod=15, ...
GradientThreshold=1, ...
Shuffle="never", ...
Verbose=true);
% Training: XTrain and YTrain are cell arrays
net = trainNetwork(XTrain,YTrain,layers,options);
Can someone help me how to build such a network?
Thanks in advance
  2 commentaires
KSSV
KSSV le 19 Avr 2023
Attach your data.
Alexander Stein
Alexander Stein le 19 Avr 2023
I attached it to the original post

Connectez-vous pour commenter.

Réponse acceptée

Katja Mogalle
Katja Mogalle le 25 Avr 2023
Hello Alexander,
The network structure generally looks fine to me.
When I run your code I get the following error, is it the same as you're getting?
Error using trainNetwork
Invalid training data. For regression tasks, responses must be a vector, a matrix, or a 4-D array of real numeric responses. Responses must not contain NaNs.
To fix this error, you need to slightly reorganize your response data. Currently it's a NumObservations-by-1 cell array of NumResponses-by-1 matrices. However, you need to convert this to a large matrix of size NumObservations-by-NumResponses. To do this, you can use the following line of code:
>> YTrain = cat(2,YTrain{:})';
If you need more information, you can also look at the documentation page of trainNetwork: https://uk.mathworks.com/help/deeplearning/ref/trainnetwork.html?s_tid=doc_ta#mw_d0b3a2e4-09a0-42f9-a273-2bb25956fe66 (the link points to the explanation of the response data formats)
I hope this helps.
Katja
  1 commentaire
Alexander Stein
Alexander Stein le 25 Avr 2023
Hello Katja,
thanks for your help, it works now!
Regards
Alexander

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by