How to Update LSTM Network State with Observed Values using "Stateful Predict" block in SIMULINK?

7 次查看(过去 30 天)
Hello everyone,
I am simulating an LSTM in Simulink using "Stateful Predict" block. In help of this block mentioned "This block updates the state of the network with every prediction."
I would like to know if it is possible to update the sataes of the network with observed value instead of every prediction.
Similar work to this example https://uk.mathworks.com/help/deeplearning/ug/time-series-forecasting-using-deep-network-designer.html that has two parts after training network. 1) Forecast Future Time Steps 2) Update Network State with Observed Values
I would be grateful if you could please advise me how to simulate this.

回答(1 个)

Sanjana
Sanjana 2023-10-31
Hi Leila.
I understand that you are trying to achieve predictions and update the network State based on Observed values instead of predicted values as mentioned in the attached example in Simulink.
YPred = [];
numTimeStepsTest = numel(XTest);
for i = 1:numTimeStepsTest
[net,YPred(:,i)] = predictAndUpdateState(net,XTest(:,i),'ExecutionEnvironment','cpu');
end
As mentioned in the above code, “predictAndUpdateState” is used to update the state of the network and based on the observed values.
The same is achieved through “Stateful Predict” block. If you check the implementation inside the mask of the “Stateful Predict”,
“SequenceNetworkPredict” internally uses “dlnetworkPredictAndUpdateState”, and thereby the state of the network can be easily obtained by passing the “XTest” values as the input to “StatefulPredict” block.
Please refer to the following documentation for further information,
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by