Why LSTM training is not done properly?

4 visualizzazioni (ultimi 30 giorni)
Nazila Pourhajy
Nazila Pourhajy il 5 Set 2021
Hi everyone!
I'm trying to train LSTM with 17521 data points. But with this amount of data, network training is not done properly. When I reduce the data to 8785(data for one year), the training is done to the end. But by increasing the data to 17521(data for two years), I receive NaN value in the YPred variable. This is my code:
YTrain = cell2mat(A_orig(2:17521,end))';
XTrain = cell2mat(A_orig(2:17521,3:end-1))';
XTrain = num2cell(XTrain,1);
YTrain = num2cell(YTrain,1);
%%Define Network Architecture
numResponses = size(YTrain{1},1);
featureDimension = size(XTrain{1},1);
numHiddenUnits = 500;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(500) %%50
dropoutLayer(0.1) %%0.5
fullyConnectedLayer(numResponses)
regressionLayer];
maxepochs = 500;
options = trainingOptions('adam', ... %%adam
'MaxEpochs',maxepochs, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
%%Train the Network
net = trainNetwork(XTrain,YTrain,layers,options);
%%Test the Network
YTest = cell2mat(A_orig(17546:26305,end))';
XTest = cell2mat(A_orig(17546:26305,3:end-1))';
XTest = num2cell(XTest,1);
YTest = num2cell(YTest,1);
net = resetState(net);
YPred = predict(net,XTest);
figure;
subplot(2,1,1);
y1 = (cell2mat(YPred(1:end, 1:end))); %have to transpose as plot plots columns
plot(y1);
title('Forcasted');
subplot(2,1,2);
y2 = (cell2mat(YTest(1:end, 1:end))');
plot(y2);
title('Observed');
When Number of data is 8785, the output for training is:
Please help me.Thanks alot.

Risposte (1)

the cyclist
the cyclist il 5 Set 2021
I doubt that it is actually the size of the data that is the problem.
You could test that idea by running the second year (which is about the same size dataset as the one that runs) by itself. Perhaps the problem is something in the 2nd-year data, and not the size.
It's difficult to diagnose the problem without seeing the data. Can you upload the data in a MAT file?
  7 Commenti
the cyclist
the cyclist il 6 Set 2021
Sorry, I have no experience in this.
Nazila Pourhajy
Nazila Pourhajy il 6 Set 2021
Ok. Thank you for your time.

Accedi per commentare.

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by