Clear Filters
Clear Filters

Is there a method to predict one point in the future based on multiple point of past prediction? (LSTM univariate)

2 views (last 30 days)
To explain the title above, how do i get prediction for i+1 based on i and i-1 combined?
I had already done the training and got the training info inside variable net.
This is an example of the code for LSTM trained net to predict 1 value into the future from Mathworks website.
for i=1:numTimeStepsTest
[net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1));
end
I appreciate if anyone can help direct me to any forum/article regarding this matter if it has been answered previously.
Thank you.

Answers (1)

Aman Banthia
Aman Banthia on 22 Sep 2023
Hi Revaldo,
I understand that you want to obtain a prediction for the next time step (i+1) based on the previous two time steps (i and i-1) using a trained LSTM network in MATLAB.
To get a prediction for ‘i+1’ based on ‘i’ and ‘i-1’ combined using a trained LSTM network in MATLAB, you can modify the code you provided as follows:
% Assuming you have already trained the LSTM network and have it stored in the variable 'net'
% Initialize variables
numTimeStepsTest = ...; % Specify the number of time steps for testing
YPred = zeros(...); % Initialize the prediction array
% Perform prediction for each time step
for i = 2:numTimeStepsTest
% Combine inputs for prediction
combinedInput = [YPred(:, i-1), YPred(:, i-2)]; % Combine previous predictions
% Predict the next time step and update the network state
[net, YPred(:, i)] = predictAndUpdateState(net, combinedInput);
end
Please refer to the following MATLAB File Exchange link for more information:
Please refer to the following MATLAB Documentation link to know more about LSTM:
Hope the above solution helps.
Best Regards,
Aman Banthia

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!