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
- 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)
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
- 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.
- 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.
- 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
- Ensure that your simulation is set up to start from (t = 0). This is usually the default setting, but it's good to verify.
- 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.