- “X” holds the current 15-value input window.
- “predict” generates the next forecast.
- The prediction is appended to the window for the next iteration.
- This loop continues for as many future time steps as needed.
How to predict a few future values (closed loop) with LSTM which has been trained on the base many predictors (max(Delays) = 15)?
40 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yury Mikh
le 5 Août 2025
Modifié(e) : Yury Mikh
le 13 Août 2025 à 8:45
A LSTM has been trained on the base many predictors (max(Delays) = 15). How to predict a few future values (closed loop) with such trained LSTM ? The problem of usual instructions (predict and predictAndUpdateState) is the prediction sequences are of feature dimension 1 but the input layer expects sequences of feature dimension 15.
0 commentaires
Réponse acceptée
Darshak
le 12 Août 2025 à 11:24
This is a common point of confusion when working with sequence models like LSTM in MATLAB.
When you train your LSTM with “maxDelay” = 15, the model learns to expect a 15-dimensional input vector at each time step. In the case of univariate data, this usually means: [x(t-15), x(t-14), ..., x(t-1)]
So, during inference, especially in closed-loop forecasting, you need to maintain a sliding window of the most recent 15 values. If you try to feedback just the last predicted value (1×1), MATLAB will throw an error because the input shape doesn’t match what the model expects (1×15).
To do it correctly, this approach can be followed:
% Assume 'net' is your trained LSTM network
% Assume 'data' is a column vector of your time series
delays = 15;
numPredict = 10;
X = data(end - delays + 1:end)'; % 1×15 input vector
[net, ~] = resetState(net);
YPred = zeros(1, numPredict);
for i = 1:numPredict
[net, y] = predict(net, X);
YPred(i) = y;
X = [X(2:end), y];
end
disp('Predicted future values:');
disp(YPred);
This approach ensures that the input dimensions remain consistent throughout the prediction process.
The following documentation links might be useful -
“predict” – Predicts output given the current state of the network.
“resetState” – Resets the internal state of the LSTM.
For a complete walkthrough, MATLAB provides a helpful example on time series forecasting with LSTM:
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sequence and Numeric Feature Data Workflows 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!