- “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)?
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Darshak
2025-8-12
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:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!