How to reset the state of a LSTM neural network to its initial state in Simulink?

12 次查看(过去 30 天)
Hi everyone,
I have trained an LSTM neural network to function as a Reduced Order Model (ROM) within a Simulink model of a coupled-physics system. Specifically, this neural network will interact with the other dynamic component (the other physic of the coupled problem) in a closed-loop configuration. During the simulation, the outputs from the neural network will feed into the other dynamic block, and the inputs from that block will, in turn, be fed back into the neural network.
The training of the neural network seems to have been successful. The performance in terms of prediction against test data is satisfactory. This is achieved both by using MATLAB's predict function and by implementing the network in Simulink with the Stateful Predict block.
However, the network seems to fail to adequately predict outputs at the initial instances. This is why, while researching, I came across the issue of resetting the LSTM state.
The reference page (Stateful Predict) suggests placing the stateful predict block in a resettable subsystem. I read the reference pages on resettable systems but was unable to figure out how to define the signal that triggers the reset for my specific case. If I understand the concept in question correctly, the state of the LSTM network should reset at the start of the simulation of my coupled system. So the trigger should occur at t = 0. Consider that the simulation of the system should provide an overall response very similar to that of a damped harmonic oscillator. So a response that decreases harmonically over time.
Could you help me clarify my doubt in this regard?
Thank you very much for your support in advance.
Marco

采纳的回答

Shubham
Shubham 2024-6-17
Hi Marco,
To address your concern about resetting the LSTM state at the start of the simulation in a coupled-physics system within Simulink, you can use the concept of a resettable subsystem with a specific trigger for resetting. Since you want the reset to occur at (t = 0), you can use the simulation time as a condition for the reset signal. Here's a general approach to achieve this:
Step 1: Create a Reset Signal
  1. Use a MATLAB Function Block: You can create a simple MATLAB function block that outputs a trigger signal based on the simulation time. The function can output true (or 1) when the simulation time is at or very close to zero, and false (or 0) otherwise. Here's an example function you could use inside the MATLAB Function Block:
function reset = triggerReset(t)
% Trigger a reset at the start of the simulation
if t <= 1e-5 % Adjust this threshold as needed
reset = 1;
else
reset = 0;
end
end
Connect the simulation time to this block. You can get the simulation time using a Clock block from the Simulink/Sources library.
Step 2: Implement the Resettable Subsystem
  1. Create a Subsystem: Encapsulate the Stateful Predict block within a subsystem. You can do this by selecting the block and then using the Simulink editor options to create a subsystem from the selection.
  2. Enable Resetting: Make the subsystem resettable by configuring its block parameters. Right-click on the subsystem, go to Block Parameters (Subsystem), and then under the States tab, check the option to enable state resetting. This will allow the subsystem to listen for a reset signal.
  3. Connect the Reset Signal: Connect the output of the MATLAB Function Block you created to the reset input of the subsystem. This will ensure that the subsystem receives the reset trigger at the start of the simulation.
Step 3: Configure the Simulation
  1. Ensure that your simulation is set up to start from (t = 0). This is usually the default setting, but it's good to verify.
  2. If your simulation involves multiple runs or needs to be reset at specific intervals beyond the initial start, you might need to adjust the logic in the MATLAB Function Block to accommodate these conditions.
Final Note
This setup ensures that your LSTM network within the resettable subsystem is reset at the beginning of the simulation, addressing the initial prediction issue. The use of a small threshold ((1e-5) in the example) instead of exactly (0) helps to avoid potential issues with the simulation's initialization phase where the exact comparison to (0) might not work as expected due to how simulation time is handled internally.
Remember, the threshold and logic for the reset signal can be adjusted based on the specific requirements of your simulation, such as resetting at other specific times or under certain conditions beyond the initial start.

更多回答(0 个)

类别

Help CenterFile 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!

Translated by