Hi Gonzalo,
As per my understanding of the question, you are facing trouble in updating the model based on the outputs you get.
The function "UpdateState" you mentioned may not be suitable for achieving your specific objective. There is a function called “predictAndUpdateState” which serves the exact purpose you are trying to serve.
Refer to the documentation here for more information on the “predictAndUpdateState” function:
I had put a line in the code (line 23) to check if the network and data have any dimensionality issues, but I have commented it now and the rest of the code is running.
I have reproduced the updated code on my end and you can find the code attached below.
XTrain = INPUTSP5LSTM;
YTrain = OUTPUTSP1TRAIN;
XTest = INPUTSP5LSTMTEST;
YTest = OUTPUTSP1TEST;
layers = [
sequenceInputLayer(14,"Name","sequence")
lstmLayer(128,"Name","lstm_1")
lstmLayer(128,"Name","lstm_2")
fullyConnectedLayer(1,"Name","fc")
regressionLayer("Name","regressionoutput")];
options = trainingOptions("adam", ...
'MaxEpochs', 100, ...
'GradientThreshold', 1, ...
'InitialLearnRate', 0.005, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropPeriod', 125, ...
'LearnRateDropFactor', 0.2, ...
'Verbose', 0, ...
'Plots', 'training-progress');
% net = trainNetwork(XTrain, YTrain, layers, options);
% You can uncomment the above line to try training the network, I did this
% to ensure that the network and dataset are not having any dimensionality
% issues.
offset = 50;
numTimeSteps = 687;
numPredictionTimeSteps = numTimeSteps - offset;
Y = zeros(numPredictionTimeSteps, 1);
% Reset the network state
net = resetState(net);
for t = 1:numPredictionTimeSteps
% Predict using the updated state
[net,Y(:, t)] = predictAndUpdateState(net, XTest(:, offset+t));
end
Hope this helps!
Regards
Akshat Wadhwa