%% Add Layer to Actor Representation
% Assume that you have an existing reinforcement learning agent, agent. For this example, load the trained agent from Train DDPG Agent to Control Double Integrator System:

load('DoubleIntegDDPG.mat','agent')

%
% Further, assume that this agent has an actor representation that contains the following neural network structure:

oldActorNetwork = [
        featureInputLayer(2,'Normalization','none','Name','state')
        fullyConnectedLayer(1,'Name','action')];

% Create the new network with the additional fully connected hidden layer:

newActorNetwork = [
        featureInputLayer(2,'Normalization','none','Name','state')
        fullyConnectedLayer(3,'Name','hidden');
        fullyConnectedLayer(1,'Name','action')];

%
% Create the corresponding actor representation:

actor = rlDeterministicActorRepresentation(newActorNetwork,...
    getObservationInfo(agent),getActionInfo(agent),...
    'Observation',{'state'},...
    'Action',{'action'})

%
% Set the actor representation of the agent to the new augmented actor:

agent = setActor(agent,actor);

% To check your agent, use getAction to return the action from a random observation.

getAction(agent,{rand(2,1)})

% You can now test and train the agent against the environment.
% Copyright 2019 The MathWorks, Inc.