rlACAgent
Actor-critic (AC) reinforcement learning agent
Description
Actor-critic (AC) agents implement actor-critic algorithms such as A2C and A3C, which are on-policy policy-gradient reinforcement learning methods for environments with a discrete or continuous action space. The actor-critic agent directly optimizes a stochastic policy and uses a value function critic to estimate the value of the policy. For continuous action spaces, this agent does not enforce constraints set in the action specification; therefore, if you need to enforce action constraints, you must do so within the environment.
For more information, see Actor-Critic (AC) Agent. For more information on the different types of reinforcement learning agents, see Reinforcement Learning Agents.
Creation
Syntax
Description
Create Agent from Observation and Action Specifications
creates an actor-critic agent for an environment with the given observation and action
specifications, using default initialization options. The actor and critic in the agent
use default deep neural networks built from the observation specification
agent
= rlACAgent(observationInfo
,actionInfo
)observationInfo
and the action specification
actionInfo
. The ObservationInfo
and
ActionInfo
properties of agent
are set to
the observationInfo
and actionInfo
input
arguments, respectively.
creates an actor-critic agent for an environment with the given observation and action
specifications. The agent uses default networks in which each hidden fully connected
layer has the number of units specified in the agent
= rlACAgent(observationInfo
,actionInfo
,initOpts
)initOpts
object. For
more information on the initialization options, see rlAgentInitializationOptions
.
Create Agent from Actor and Critic
Specify Agent Options
creates an actor-critic agent and sets the AgentOptions
property to the agent
= rlACAgent(___,agentOptions
)agentOptions
input argument. Use this syntax after
any of the input arguments in the previous syntaxes.
Input Arguments
initOpts
— Agent initialization options
rlAgentInitializationOptions
object
Agent initialization options, specified as an rlAgentInitializationOptions
object.
actor
— Actor
rlDiscreteCategoricalActor
object | rlContinuousGaussianActor
object
Actor that implements the policy, specified as an rlDiscreteCategoricalActor
or rlContinuousGaussianActor
function approximator object. For more
information on creating actor approximators, see Create Policies and Value Functions.
critic
— Critic
rlValueFunction
object
Critic that estimates the discounted long-term reward, specified as an rlValueFunction
object. For more information on creating critic approximators, see Create Policies and Value Functions.
Properties
ObservationInfo
— Observation specifications
specification object | array of specification objects
Observation specifications, specified as an rlFiniteSetSpec
or rlNumericSpec
object or an array containing a mix of such objects. Each element in the array defines
the properties of an environment observation channel, such as its dimensions, data type,
and name.
If you create the agent by specifying an actor or critic, the value of
ObservationInfo
matches the value specified in the actor and
critic objects. If you create a default agent, the agent constructor function sets the
ObservationInfo
property to the input argument
observationInfo
.
You can extract observationInfo
from an existing environment,
function approximator, or agent using getObservationInfo
. You can also construct the specifications manually
using rlFiniteSetSpec
or rlNumericSpec
.
Example: [rlNumericSpec([2 1])
rlFiniteSetSpec([3,5,7])]
ActionInfo
— Action specification
rlFiniteSetSpec
object | rlNumericSpec
object
Action specifications, specified either as an rlFiniteSetSpec
(for discrete action spaces) or rlNumericSpec
(for continuous action spaces) object. This object defines the properties of the
environment action channel, such as its dimensions, data type, and name.
Note
For this agent, only one action channel is allowed.
If you create the agent by specifying an actor and critic, the value of
ActionInfo
matches the value specified in the actor and critic
objects. If you create a default agent, the agent constructor function sets the
ActionInfo
property to the input argument
ActionInfo
.
You can extract actionInfo
from an existing environment, function
approximator, or agent using getActionInfo
. You can also construct the specification manually using
rlFiniteSetSpec
or rlNumericSpec
.
Example: rlNumericSpec([2 1])
AgentOptions
— Agent options
rlACAgentOptions
object
Agent options, specified as an rlACAgentOptions
object.
UseExplorationPolicy
— Option to use exploration policy for simulation and deployment
true
(default) | false
Option to use exploration policy when selecting actions during simulation or after deployment, specified as a one of the following logical values.
true
— Use the base agent exploration policy when selecting actions insim
andgeneratePolicyFunction
. Specifically, in this case the agent uses therlStochasticActorPolicy
policy with theUseMaxLikelihoodAction
property set tofalse
. Since the agent selects its actions by sampling its probability distribution, the policy is stochastic and the agent explores its action and observation spaces.false
— Force the agent to use the base agent greedy policy (the action with maximum likelihood) when selecting actions insim
andgeneratePolicyFunction
. Specifically, in this case the agent uses therlStochasticActorPolicy
policy with theUseMaxLikelihoodAction
property set totrue
. Since the agent selects its actions greedily the policy behaves deterministically and the agent does not explore its action and observation spaces.
Note
This option affects only simulation and deployment; it does not affect training.
When you train an agent using train
,
the agent always uses its exploration policy independently of the value of this
property.
SampleTime
— Sample time of agent
1
(default) | positive scalar | -1
Sample time of the agent, specified as a positive scalar or as -1
.
Within a MATLAB® environment, the agent is executed every time the environment advances,
so, SampleTime
does not affect the timing of the agent
execution.
Within a Simulink® environment, the RL Agent block
that uses the agent object executes every SampleTime
seconds of
simulation time. If SampleTime
is -1
the block
inherits the sample time from its input signals. Set SampleTime
to
-1
when the block is a child of an event-driven subsystem.
Note
Set SampleTime
to a positive scalar when the block is not
a child of an event-driven subsystem. Doing so ensures that the block executes
at appropriate intervals when input signal sample times change due to model
variations.
Regardless of the type of environment, the time interval between consecutive elements
in the output experience returned by sim
or
train
is
always SampleTime
.
If SampleTime
is -1
, for Simulink environments, the time interval between consecutive elements in the
returned output experience reflects the timing of the events that trigger the RL Agent block
execution, while for MATLAB environments, this time interval is considered equal to
1
.
This property is shared between the agent and the agent options object within the agent. Therefore, if you change it in the agent options object, it gets changed in the agent, and vice versa.
Example: SampleTime=-1
Object Functions
train | Train reinforcement learning agents within a specified environment |
sim | Simulate trained reinforcement learning agents within specified environment |
getAction | Obtain action from agent, actor, or policy object given environment observations |
getActor | Extract actor from reinforcement learning agent |
setActor | Set actor of reinforcement learning agent |
getCritic | Extract critic from reinforcement learning agent |
setCritic | Set critic of reinforcement learning agent |
generatePolicyFunction | Generate MATLAB function that evaluates policy of an agent or policy object |
Examples
Create Default AC Agent
Create an environment and obtain its observation and action specifications. For this example, load the environment used in the example Create DQN Agent Using Deep Network Designer and Train Using Image Observations. This environment has two observations: a 50-by-50 grayscale image and a scalar (the angular velocity of the pendulum). The action is a scalar with five possible elements (a torque of -2, -1, 0, 1, or 2 Nm applied to a swinging pole).
env = rlPredefinedEnv("SimplePendulumWithImage-Discrete");
Obtain observation and action specifications.
obsInfo = getObservationInfo(env); actInfo = getActionInfo(env);
The agent creation function initializes the actor and critic networks randomly. Ensure reproducibility by fixing the seed of the random generator.
rng(0)
Create an actor-critic agent from the environment observation and action specifications. Since actInfo
is an rlFiniteSetSpec
object, rlPGAgent
creates an agent with a discrete action space. When actInfo
is an rlNumericSpec
object, rlPGAgent
creates an agent with a continuous action space.
agent = rlACAgent(obsInfo,actInfo);
To check your agent, use getAction
to return the action from random observations.
getAction(agent,{rand(obsInfo(1).Dimension),rand(obsInfo(2).Dimension)})
ans = 1x1 cell array
{[-2]}
You can now test and train the agent within the environment. You can also use getActor
and getCritic
to extract the actor and critic, respectively, and getModel
to extract the approximator model (by default a deep neural network) from the actor or critic.
Create Default AC Agent Using Initialization Options
Create an environment and obtain its observation and action specifications. For this example, load the environment used in the example Train DDPG Agent to Swing Up and Balance Pendulum with Image Observation. This environment has two observations: a 50-by-50 grayscale image and a scalar (the angular velocity of the pendulum). The action is a scalar representing a torque ranging continuously from -2 to 2 Nm.
% Load predefined environment env = rlPredefinedEnv("SimplePendulumWithImage-Continuous"); % Obtain observation and action specifications obsInfo = getObservationInfo(env); actInfo = getActionInfo(env);
Create an agent initialization option object, specifying that each hidden fully connected layer in the network must have 128 neurons (instead of the default number, 256).
initOpts = rlAgentInitializationOptions(NumHiddenUnit=128);
The agent creation function initializes the actor and critic networks randomly. You can ensure reproducibility by fixing the seed of the random generator.
rng(0)
Create an actor-critic agent from the environment observation and action specifications. Since actInfo
is an rlNumericSpec
object, rlACAgent
creates an agent with a continuous action space. When actInfo
is an rlFiniteSetSpec
object, rlACAgent
creates an agent with a discrete action space.
agent = rlACAgent(obsInfo,actInfo,initOpts);
Extract the deep neural networks from both the agent actor and critic.
actorNet = getModel(getActor(agent)); criticNet = getModel(getCritic(agent));
To verify that each hidden fully connected layer has 128 neurons, you can display the layers on the MATLAB® command window,
criticNet.Layers
or visualize the structure interactively using analyzeNetwork
.
analyzeNetwork(criticNet)
Plot actor and critic networks
plot(actorNet)
plot(criticNet)
To check your agent, use getAction
to return the action from a random observation.
getAction(agent,{rand(obsInfo(1).Dimension),rand(obsInfo(2).Dimension)})
ans = 1x1 cell array
{[0.9228]}
You can now test and train the agent within the environment.
Create Discrete Actor-Critic Agent from Actor and Critic
Create an environment with a discrete action space and obtain its observation and action specifications. For this example, load the environment used in the example Train DQN Agent to Balance Discrete Cart-Pole System. This environment has a four-dimensional observation vector (cart position and velocity, pole angle, and pole angle derivative), and a scalar action with two possible elements (a force of either -10 or +10 N applied on the cart).
env = rlPredefinedEnv("CartPole-Discrete");
Obtain observation and action specifications.
obsInfo = getObservationInfo(env)
obsInfo = rlNumericSpec with properties: LowerLimit: -Inf UpperLimit: Inf Name: "CartPole States" Description: "x, dx, theta, dtheta" Dimension: [4 1] DataType: "double"
actInfo = getActionInfo(env)
actInfo = rlFiniteSetSpec with properties: Elements: [-10 10] Name: "CartPole Action" Description: [0x0 string] Dimension: [1 1] DataType: "double"
The agent creation function initializes the actor and critic networks randomly. You can ensure reproducibility by fixing the seed of the random generator.
rng(0)
Actor-critic agents use a parametrized value function approximator to estimate the value of the policy. A value-function critic takes the current observation as input and returns a single scalar as output (the estimated discounted cumulative long-term reward for following the policy from the state corresponding to the current observation).
To model the parametrized value function within the critic, use a neural network with one input layer (which receives the content of the observation channel, as specified by obsInfo
) and one output layer (which returns the scalar value). Note that prod(obsInfo.Dimension)
returns the total number of dimensions of the observation space regardless of whether the observation space is a column vector, row vector, or matrix.
Define the network as an array of layer objects, and get the dimension of the observation space from the environment specification objects.
criticNet = [ featureInputLayer(prod(obsInfo.Dimension)) fullyConnectedLayer(50) reluLayer fullyConnectedLayer(1) ];
Convert the network to a dlnetwork
object, and display the number of weights.
criticNet = dlnetwork(criticNet); summary(criticNet)
Initialized: true Number of learnables: 301 Inputs: 1 'input' 4 features
Create the critic approximator object using criticNet
and the observation specification. For more information on value function approximators, see rlValueFunction
.
critic = rlValueFunction(criticNet,obsInfo);
Check your critic with a random observation input.
getValue(critic,{rand(obsInfo.Dimension)})
ans = single
-0.1411
Actor-critic agents use a parametrized stochastic policy, which for discrete action spaces is implemented by a discrete categorical actor. This actor takes an observation as input and returns as output a random action sampled (among the finite number of possible actions) from a categorical probability distribution.
To model the parametrized policy within the actor, use a neural network with one input layer (which receives the content of the observation channel, as specified by obsInfo
) and one output layer. The output layer must return a vector of probabilities for each possible action, as specified by actInfo
. Note that numel(actInfo.Dimension)
returns the number of elements of the discrete action space.
Define the network as an array of layer objects.
actorNet = [ featureInputLayer(prod(obsInfo.Dimension)) fullyConnectedLayer(16) reluLayer fullyConnectedLayer(16) reluLayer fullyConnectedLayer(numel(actInfo.Dimension)) ];
Convert the network to a dlnetwork
object, and display the number of weights.
actorNet = dlnetwork(actorNet); summary(actorNet)
Initialized: true Number of learnables: 386 Inputs: 1 'input' 4 features
Create the actor using actorNet
and the observation and action specifications. For more information on discrete categorical actors, see rlDiscreteCategoricalActor
.
actor = rlDiscreteCategoricalActor(actorNet,obsInfo,actInfo);
Check your actor with a random observation input.
getAction(actor,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[10]}
Create the AC agent using the actor and the critic.
agent = rlACAgent(actor,critic)
agent = rlACAgent with properties: AgentOptions: [1x1 rl.option.rlACAgentOptions] UseExplorationPolicy: 1 ObservationInfo: [1x1 rl.util.rlNumericSpec] ActionInfo: [1x1 rl.util.rlFiniteSetSpec] SampleTime: 1
Specify some options for the agent, including training options for the actor and critic.
agent.AgentOptions.NumStepsToLookAhead=32; agent.AgentOptions.DiscountFactor=0.99; agent.AgentOptions.CriticOptimizerOptions.LearnRate=8e-3; agent.AgentOptions.CriticOptimizerOptions.GradientThreshold=1; agent.AgentOptions.ActorOptimizerOptions.LearnRate=8e-3; agent.AgentOptions.ActorOptimizerOptions.GradientThreshold=1;
Check your agent with a random observation.
getAction(agent,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[-10]}
You can now test and train the agent within the environment.
Create Continuous Actor-Critic Agent from Actor and Critic
Create an environment with a continuous action space, and obtain its observation and action specifications. For this example, load the double integrator continuous action space environment used in the example Compare DDPG Agent to LQR Controller.
env = rlPredefinedEnv("DoubleIntegrator-Continuous");
Obtain observation and action specifications.
obsInfo = getObservationInfo(env)
obsInfo = rlNumericSpec with properties: LowerLimit: -Inf UpperLimit: Inf Name: "states" Description: "x, dx" Dimension: [2 1] DataType: "double"
actInfo = getActionInfo(env)
actInfo = rlNumericSpec with properties: LowerLimit: -Inf UpperLimit: Inf Name: "force" Description: [0x0 string] Dimension: [1 1] DataType: "double"
In this example, the action is a scalar value representing a force ranging from -2 to 2 Newton. To make sure that the output from the agent is in this range, you perform an appropriate scaling operation. Store these limits so you can easily access them later.
% Make sure action space upper and lower limits are finite
actInfo.LowerLimit=-2;
actInfo.UpperLimit=2;
The actor and critic networks are initialized randomly. You can ensure reproducibility by fixing the seed of the random generator.
rng(0)
Actor-critic agents use a parametrized value function approximator to estimate the value of the policy. A value-function critic takes the current observation as input and returns a single scalar as output (the estimated discounted cumulative long-term reward for following the policy from the state corresponding to the current observation).
To model the parametrized value function within the critic, use a neural network with one input layer (which receives the content of the observation channel, as specified by obsInfo
) and one output layer (which returns the scalar value). Note that prod(obsInfo.Dimension)
returns the total number of dimensions of the observation space regardless of whether the observation space is a column vector, row vector, or matrix.
Define the network as an array of layer objects.
criticNet = [ featureInputLayer(prod(obsInfo.Dimension)) fullyConnectedLayer(20) reluLayer fullyConnectedLayer(20) reluLayer fullyConnectedLayer(1) ];
Convert the network to a dlnetwork
object, initialize it, and display the number of weights.
criticNet = dlnetwork(criticNet); criticNet = initialize(criticNet); summary(criticNet)
Initialized: true Number of learnables: 501 Inputs: 1 'input' 2 features
Create the critic approximator object using criticNet
and the observation specification. For more information on value function approximators, see rlValueFunction
.
critic = rlValueFunction(criticNet,obsInfo);
Check your critic with a random input observation.
getValue(critic,{rand(obsInfo.Dimension)})
ans = single
-0.0311
Actor-critic agents use a parametrized stochastic policy, which for continuous action spaces is implemented by a continuous Gaussian actor. This actor takes an observation as input and returns as output a random action sampled from a Gaussian probability distribution.
To approximate the mean values and standard deviations of the Gaussian distribution, you must use a neural network with two output layers, each having as many elements as the dimension of the action space. One output layer must return a vector containing the mean values for each action dimension. The other must return a vector containing the standard deviation for each action dimension.
Note that standard deviations must be nonnegative and mean values must fall within the range of the action. Therefore the output layer that returns the standard deviations must be a softplus or ReLU layer, to enforce nonnegativity, while the output layer that returns the mean values must be a scaling layer, to scale the mean values to the output range.
For this example the environment has only one observation channel and therefore the network has only one input layer.
Define each network path as an array of layer objects, and assign names to the input and output layers of each path. These names allow you to connect the paths and then later explicitly associate the network input and output layers with the appropriate environment channel.
% Input path inPath = [ featureInputLayer(prod(obsInfo.Dimension),Name="obsInLyr") fullyConnectedLayer(prod(actInfo.Dimension),Name="infc") ]; % Mean value path meanPath = [ tanhLayer(Name="tanhMean"); fullyConnectedLayer(50) reluLayer fullyConnectedLayer(prod(actInfo.Dimension)); scalingLayer( ... Name="meanOutLyr", ... Scale=actInfo.UpperLimit) % scale to range ]; % Standard deviation path sdevPath = [ tanhLayer(Name="tanhStdv"); fullyConnectedLayer(50) reluLayer fullyConnectedLayer(prod(actInfo.Dimension)); softplusLayer(Name="stdOutLyr") % nonnegative ];
Assemble dlnetwork
object.
actorNet = dlnetwork; actorNet = addLayers(actorNet,inPath); actorNet = addLayers(actorNet,meanPath); actorNet = addLayers(actorNet,sdevPath);
Connect layers.
actorNet = connectLayers(actorNet,"infc","tanhMean/in"); actorNet = connectLayers(actorNet,"infc","tanhStdv/in");
Plot network.
plot(actorNet)
Initialize network and display the number of learnable parameters (weights).
actorNet = initialize(actorNet); summary(actorNet)
Initialized: true Number of learnables: 305 Inputs: 1 'obsInLyr' 2 features
Create the actor approximator object using actorNet
and the environment specifications. For more information, on continuous Gaussian actors, see rlContinuousGaussianActor
.
actor = rlContinuousGaussianActor(actorNet, obsInfo, actInfo, ... ActionMeanOutputNames="meanOutLyr",... ActionStandardDeviationOutputNames="stdOutLyr",... ObservationInputNames="obsInLyr");
Check your actor with a random input observation.
getAction(actor,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[0.0815]}
Create the AC agent using the actor and the critic.
agent = rlACAgent(actor,critic)
agent = rlACAgent with properties: AgentOptions: [1x1 rl.option.rlACAgentOptions] UseExplorationPolicy: 1 ObservationInfo: [1x1 rl.util.rlNumericSpec] ActionInfo: [1x1 rl.util.rlNumericSpec] SampleTime: 1
Specify agent options, including training options for its actor and critic.
agent.AgentOptions.NumStepsToLookAhead = 32; agent.AgentOptions.DiscountFactor=0.99; agent.AgentOptions.CriticOptimizerOptions.LearnRate=8e-3; agent.AgentOptions.CriticOptimizerOptions.GradientThreshold=1; agent.AgentOptions.ActorOptimizerOptions.LearnRate=8e-3; agent.AgentOptions.ActorOptimizerOptions.GradientThreshold=1;
Check your agent using a random input observation.
getAction(agent,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[-0.8032]}
You can now test and train the agent within the environment.
Create a Discrete Actor-Critic Agent with Recurrent Neural Networks
For this example load the predefined environment used for the Train DQN Agent to Balance Discrete Cart-Pole System example. This environment has a four-dimensional observation vector (cart position and velocity, pole angle, and pole angle derivative), and a scalar action with two possible elements (a force of either -10 or +10 N applied on the cart).
env = rlPredefinedEnv("CartPole-Discrete");
Get observation and action information.
obsInfo = getObservationInfo(env); actInfo = getActionInfo(env);
The agent creation function initializes the actor and critic networks randomly. Ensure reproducibility by fixing the seed of the random generator.
rng(0)
To model the parametrized value function within the critic, use a recurrent neural network, which must have one input layer (which receives the content of the observation channel, as specified by obsInfo
) and one output layer (which returns the scalar value).
Define the network as an array of layer objects. To create a recurrent network, use a sequenceInputLayer
as the input layer and include at least one lstmLayer
.
criticNet = [ sequenceInputLayer(prod(obsInfo.Dimension)) lstmLayer(10) reluLayer fullyConnectedLayer(1) ];
Convert the network to a dlnetwork
object and display the number of learnable parameters (weights).
criticNet = dlnetwork(criticNet); summary(criticNet)
Initialized: true Number of learnables: 611 Inputs: 1 'sequenceinput' Sequence input with 4 dimensions
Create the critic approximator object using criticNet
and the observation specification. For more information on value function approximators, see rlValueFunction
.
critic = rlValueFunction(criticNet,obsInfo);
Check the critic with a random input observation.
getValue(critic,{rand(obsInfo.Dimension)})
ans = single
-0.0344
Since the critic has a recurrent network, the (discrete categorical) actor must also use a recurrent network. The network must have one input layer (which receives the content of the environment observation channel, as specified by obsInfo
) and one output layer (which must return a vector of probabilities for each possible action, as specified by actInfo
).
Define the recurrent network as an array of layer objects.
actorNet = [ sequenceInputLayer(prod(obsInfo.Dimension)) lstmLayer(20) reluLayer fullyConnectedLayer(numel(actInfo.Elements)) ];
Convert the network to a dlnetwork
object and display the number of weights.
actorNet = dlnetwork(actorNet); summary(actorNet)
Initialized: true Number of learnables: 2k Inputs: 1 'sequenceinput' Sequence input with 4 dimensions
Create the actor using actorNet
and the observation and action specifications. For more information on discrete categorical actors, see rlDiscreteCategoricalActor
.
actor = rlDiscreteCategoricalActor(actorNet,obsInfo,actInfo);
Check the actor with a random input observation.
getAction(actor,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[10]}
Set some training options for the critic.
criticOpts = rlOptimizerOptions( ...
LearnRate=8e-3,GradientThreshold=1);
Set some training options for the actor.
actorOpts = rlOptimizerOptions( ...
LearnRate=8e-3,GradientThreshold=1);
Specify training options for the agent, and include actorOpts
and criticOpts
. Since the agent uses recurrent neural networks, NumStepsToLookAhead
is treated as the training trajectory length.
agentOpts = rlACAgentOptions( ... NumStepsToLookAhead=32, ... DiscountFactor=0.99, ... CriticOptimizerOptions=criticOpts, ... ActorOptimizerOptions=actorOpts);
Create an AC agent using the actor, the critic, and the agent options object.
agent = rlACAgent(actor,critic,agentOpts)
agent = rlACAgent with properties: AgentOptions: [1x1 rl.option.rlACAgentOptions] UseExplorationPolicy: 1 ObservationInfo: [1x1 rl.util.rlNumericSpec] ActionInfo: [1x1 rl.util.rlFiniteSetSpec] SampleTime: 1
To check your agent, return the action from a random observation.
getAction(agent,{rand(obsInfo.Dimension)})
ans = 1x1 cell array
{[10]}
To evaluate the agent using sequential observations, use the sequence length (time) dimension. For example, obtain actions for a sequence of 9
observations.
[action,state] = getAction(agent, ...
{rand([obsInfo.Dimension 1 9])});
Display the action corresponding to the seventh element of the observation.
action = action{1}; action(1,1,1,7)
ans = -10
You can now test and train the agent within the environment.
Configure Options for A3C Training
To train an agent using the asynchronous advantage actor-critic (A3C) method, you must set the agent and parallel training options appropriately.
When creating the AC agent, set the NumStepsToLookAhead
value to be greater than 1
. Common values are 64
and 128
.
agentOpts = rlACAgentOptions(NumStepsToLookAhead=64);
Use agentOpts
when creating your agent. Alternatively, create your agent first and then modify its options, including the actor and critic options later using dot notation.
Configure the training algorithm to use asynchronous parallel training.
trainOpts = rlTrainingOptions(UseParallel=true);
trainOpts.ParallelizationOptions.Mode = "async";
You can now use trainOpts
to train your AC agent using the A3C method.
For an example on asynchronous advantage actor-critic agent training, see Train AC Agent to Balance Discrete Cart-Pole System Using Parallel Computing.
Tips
For continuous action spaces, the
rlACAgent
object does not enforce the constraints set by the action specification, so you must enforce action space constraints within the environment.
Version History
Introduced in R2019a
See Also
Apps
Functions
getAction
|getActor
|getCritic
|generatePolicyFunction
|generatePolicyBlock
|getActionInfo
|getObservationInfo
Objects
rlACAgentOptions
|rlAgentInitializationOptions
|rlValueFunction
|rlDiscreteCategoricalActor
|rlContinuousGaussianActor
|rlPGAgent
|rlPPOAgent
|rlTRPOAgent
Blocks
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)