Florian_sawallich asked . 2021-09-06

How to export and use only the end product of a reinforcement learning algorithm ?

Hello
 
I have used reinforcement learning to train a TD3 agent. Now I want to use this agent and actually deploy it as a controller in a simulink model, then possibly on an embedded platform. From what I understand about reinforcement learning, the actor network is the actual end product which computes the control action. Therefore, I don't want to export everything else with it as a RL agent representation, just the neural net. Is there something I should be wary of when doing this ? Also what simulink block can I use for a deep NN controller ? I am not sure if the predict block is suitable here as the task is not classification and the output should be an action, rather than likelihood percentages.
 
Also, I have created a TD3 agent with LSTM layers on MATLAB R2021a. When I try to import the agent to R2020b, which it is incompatible with, the agent surprisingly does get imported but when I try to simulate it to validate the results I get very different ones from when I try to do it on R2021a. Are the LSTM layers inside of the agent not working properly in R2020b or are they completely incompatible (for simulating the agent only, not training) ? Would doing something I described above (importing only the neural net as a controller) allow me to use the network as a controller on older versions of MATLAB?

reinforcement lear...t , d3 , deep neural network , deep learning , lstm

Expert Answer

Neeta Dsouza answered . 2024-12-21 22:46:41

To deploy trained RL agent you need to:
  1. Extract trained policy from RL agent. For that you use generatePolicyFunction. As the doc explains, this function will create a function evaluatePolicy.m and agentData.mat file.
  2. To run inference on trained policy in Simulink, use MATLAB Function block in Simulink. In MATLAB Funciton block call evaluatePolicy
  3. You are done! You can now simulate your trained policy in Simulink. Starting with 21a we support ANSI C code gen for deep learning networks. So you can generate ANSI C code from your Simulink model that contains whetever algorithms you have plus trained RL policy represented by MATLAB Function Block.
  4. The generated code should be compatible with any microcontroller, or with a rapid prototyping setup, for example, with speedgoat machine.
To see the details on what layers currently support ANSI C (generic C),
 
As for the second question, T3D support for LSTMs came in 21a in Reinforcement Learning Toolbox. So as you point out you would not be able to use this agent in 20b. However, you should be able to extract trained policy as described above and run inference on it in 20b. In 21a we added a Simulink block to Deep Learning Toolbox for simulating LSTMs, but I think you should be able to simulate in 20b using MATLAB Function block. If you can;t or reults don't make sense, please reach out to tech support.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.