MATLAB Answers

Invalid input argument type or size such as observation, reward, isdone or loggedSignals. (Reinforcement learning toolbox)

21 views (last 30 days)
% Create observation specifications.
numObservations = 6;
obsInfo = rlNumericSpec([numObservations 1]);
obsInfo.Name = 'observations';
obsInfo.Description = 'Information on reference voltage, measured capacitor voltage and load current';
% Create action specifications.
actInfo = rlFiniteSetSpec(num2cell(actions,2));
actInfo.Name = 'states';
agentblk = 'Reinforcement_learning_controller_discrete/RL_controller/RL Agent';
env = rlSimulinkEnv(mdl,agentblk,obsInfo,actInfo);
dnn = [
fullyConnectedLayer(24, 'Name','actorFC1') % why 24,48
fullyConnectedLayer(24, 'Name','CriticStateFC2')
agentOptions = rlDQNAgentOptions(...
agent = rlDQNAgent(critic,agentOptions);
trainingOptions = rlTrainingOptions(...
doTraining = true;
if doTraining
% Train the agent.
trainingStats = train(agent,env,trainingOptions);
% Load the pretrained agent for the example.
simOptions = rlSimulationOptions('MaxSteps',500);
experience = sim(env,agent,simOptions);
Invalid input argument type or size such as observation, reward, isdone or loggedSignals.
Unable to compute gradient from representation.
Unable to evaluate the loss function. Check the loss function and ensure it runs successfully.
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
The elements of action are 128x1 cell. It has 7 action, each with 2 possibile value, which results in 128x1 cell. When I set two possible elements in the actInfo manually, the model works well. However, the error presented above occurs when I use the 128x1 cell as the elements.


Sign in to comment.

Accepted Answer

Emmanouil Tzorakoleftherakis
Edited: Emmanouil Tzorakoleftherakis on 13 Nov 2020
It's challenging to reproduce this without having access to a reproduction model (including the environment definition).
I would recommend comparing your code with this example which is similar in nature (has multiple discrete actions) and particularly lines 237-248 in RocketLander.m. Make sure each element in your cell array has appropriate dimensions whether that's 1x2 or 2x1.
If this does not work, check the dimensions of the IsDone and reward signal as well and make sure these are scalars.


Kacjer Frank
Kacjer Frank on 22 Nov 2020
Thank you for your reply. In the example you mentioned in the link, I wondered why the number of actions numAct is the number of elements of the actionInfo although there are only two outputs.
Emmanouil Tzorakoleftherakis
If you have multiple discrete outputs, the way to set up the network currently in Reinforcement Learning Toolbox is to find all the possible combinations of those actions, and set these as outputs. So each combination is a possible output.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!