%% Add Layer to Critic Representation
% Assume that you have an existing reinforcement learning agent, agent. For this example, load the trained agent from Train AC Agent to Balance Cart-Pole System:

load('MATLABCartpoleAC.mat')

%
% Further, assume that this agent has a critic representation that contains the following neural network structure with two layers:

oldCriticNetwork = [
        featureInputLayer(4,'Normalization','none','Name','state')
        fullyConnectedLayer(1,'Name','CriticFC')];

%
% Create the new network with an additional 5-neurons fully connected hidden layer:

newCriticNetwork = [
        oldCriticNetwork(1)
        fullyConnectedLayer(5,'Name','hidden');
        oldCriticNetwork(2)];

%
% Create the critic using the new network with the additional fully connected layer.

critic = rlValueRepresentation(newCriticNetwork,getObservationInfo(agent),'Observation',{'state'});

%
% Set the critic representation of the agent to the new critic.

newAgent = setCritic(agent,critic);

% Copyright 2019 The MathWorks, Inc.