How to implement reinforcement learning using code generation

13 vues (au cours des 30 derniers jours)
Yihao Wan
Yihao Wan le 26 Fév 2021
Commenté : Mayank le 12 Nov 2025 à 10:33
I want to implement the reinforcement learning block in dSPACE using code generation, while the simulink will pop out the error 'The 'AgentWrapper' class does not suppot code generation'. Is there a way how to solve it?
Or is it possible to extract the neural work of reinforcement learning agent and import it into deep learning toolbox?
Thank you very much. Any suggestions are appreciated.

Réponse acceptée

Kishen Mahadevan
Kishen Mahadevan le 1 Mar 2021
As of R2020b, the RL Agent block does not support Code Generation (we are working on it) and is currently only used for training a Reinforcement Learning Agent in Simulink.
However, in R2020b, native Simulink blocks such as 'Image Classifier' and 'Predict' were introduced in Deep Learning Toolbox, and the MATLAB function block was enhanced to model Deep Learning networks in Simulink. These blocks allow using pre-trained networks including Reinforcement Learning policies in Simulink to perform inference.
Also, in R2021a, plain C Code generation for Deep Learning networks is supported (so no dependence on 3p libraries like one-dnn), which enables code generation from the native DL blocks and the enhanced MATLAB function block mentioned above.
Using these features, steps you could follow in R2021a are:
1) Use either Predict or the MATLAB function block to replace the existing RL Agent block, and pull in your trained agent into Simulink
2) Leverage the Plain C Code generation feature to generate code for your Reinforcement Learning Agent
Note:
To create a function that can be used within the 'MATLAB function' block to evaluate the learned policy (pre-trained agent), or to create agentData that can be imported into the 'Predict' block, please refer to the 'generatePolicyFunction' API.
  7 commentaires
Mayank
Mayank le 12 Nov 2025 à 10:33
I am facing issue in generating c code , can someone help
Mayank
Mayank le 12 Nov 2025 à 10:33
This is for an Opal RT based HIL using RL agent

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by