Elements problem due to the deep learning toolbox ‘Predict’

Technical Source
2 min readSep 4, 2021

I use the deep learning library predict block for RL agent in simulink, while the error indicates Invalid setting for input port dimensions due to the total number of input and output elements are not the same. While it worked well with RL block and matlab function (realized by ‘generatePolicyFunction’) and I just replace the block with Predict block. It seems the output of Predict is the whole elements sets of actions rather than single action, which is the actual output of RL agent. How do I solve it? Thank you very much.

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Hello,

I see the problem. Typically, RL policies have post-processing part, which may vary from agent to agent, and the Predict block does not account for that, meaning you would have to implement this manually.

However, there is a quick solution to that if you use generatePolicyFunction and a MATLAB Fcn block instead of the Predict block (you should still use R2021a to get the plain C code generation benefit).

Here are the steps you need to follow:

1) Execute

generatePolicyFunction(agent);

This will create a) a .mat file that contains the extracted neural network (so you don’t need to extract it yourself), and b) a matlab function called evaluatePolicy that performs inference on the policy (including any post-processing required).

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.