setCritic

Set critic representation of reinforcement learning agent

Description

example

newAgent = setActor(oldAgent,critic) returns a new reinforcement learning agent, newAgent, that uses the specified critic representation. Apart from the critic representation, the new agent has the same configuration as the specified original agent, oldAgent.

Examples

collapse all

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

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

Obtain the critic representation from the agent.

critic = getCritic(agent);

Obtain the learnable parameters from the critic.

params = getLearnableParameters(critic);

Modify the parameter values. For this example, simply multiply all of the parameters by 2.

modifiedParams = cellfun(@(x) x*2,params,'UniformOutput',false);

Set the parameter values of the critic to the new modified values.

critic = setLearnableParameters(critic,modifiedParams);

Set the critic in the agent to the new modified critic.

agent = setCritic(agent,critic);

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 shallow neural network structure with two layers:

oldCriticNetwork = [
        imageInputLayer([4 1 1],'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);

Input Arguments

collapse all

Original reinforcement learning agent that contains a critic representation, specified as one of the following:

Critic representation object, specified as one of the following:

  • rlValueRepresentation object — Returned when agent is an rlACAgent, rlPGAgent, or rlPPOAgent object

  • rlQValueRepresentation object — Returned when agent is an rlQAgent, rlSARSAAgent, rlDQNAgent, rlDDPGAgent, or rlTD3Agent object with a single critic

  • Two-element row vector of rlQValueRepresentation objects — Returned when agent is an rlTD3Agent object with two critics

Output Arguments

collapse all

Updated reinforcement learning agent, returned as an agent object that uses the specified critic representation. Apart from the critic representation, the new agent has the same configuration as oldAgent.

Introduced in R2019a