Main Content

rlACAgentOptions

Options for AC agent

Description

Use an rlACAgentOptions object to specify options for creating actor-critic (AC) agents. To create an actor-critic agent, use rlACAgent

For more information see Actor-Critic (AC) Agent.

For more information on the different types of reinforcement learning agents, see Reinforcement Learning Agents.

Creation

Description

opt = rlACAgentOptions creates a default option set for an AC agent. You can modify the object properties using dot notation.

opt = rlACAgentOptions(Name=Value) creates the options set opt and sets its properties using one or more name-value arguments. For example, rlDQNAgentOptions(DiscountFactor=0.95) creates an options set with a discount factor of 0.95. You can specify multiple name-value arguments.

example

Properties

expand all

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

Discount factor applied to future rewards during training, specified as a positive scalar less than or equal to 1.

Example: DiscountFactor=0.9

Entropy loss weight, specified as a scalar value between 0 and 1. A higher entropy loss weight value promotes agent exploration by applying a penalty for being too certain about which action to take. Doing so can help the agent move out of local optima.

When gradients are computed during training, an additional gradient component is computed for minimizing this loss function.

Example: EntropyLossWeight=0.01

Actor optimizer options, specified as an rlOptimizerOptions object. It allows you to specify training parameters of the actor approximator such as learning rate, gradient threshold, as well as the optimizer algorithm and its parameters. For more information, see rlOptimizerOptions and rlOptimizer.

Example: ActorOptimizerOptions = rlOptimizerOptions(LearnRate=2e-3)

Critic optimizer options, specified as an rlOptimizerOptions object. It allows you to specify training parameters of the critic approximator such as learning rate, gradient threshold, as well as the optimizer algorithm and its parameters. For more information, see rlOptimizerOptions and rlOptimizer.

Example: CriticOptimizerOptions = rlOptimizerOptions(LearnRate=5e-3)

Number of steps the agent interacts with the environment before learning from its experience, specified as a positive integer. When the agent uses a recurrent neural network, NumStepsToLookAhead is treated as the training trajectory length. When the agent is trained in parallel, NumStepsToLookAhead is ignored, and the whole episode is used to compute the gradients.

Example: NumStepsToLookAhead=64

Options to save additional agent data, specified as a structure containing a field named Optimizer.

You can save an agent object in one of the following ways:

  • Using the save command

  • Specifying saveAgentCriteria and saveAgentValue in an rlTrainingOptions object

  • Specifying an appropriate logging function within a FileLogger object

When you save an agent using any method, the fields in the InfoToSave structure determine whether the corresponding data is saved with the agent. For example, if you set the Optimizer field to true, then the actor and critic optimizers are saved along with the agent.

You can modify the InfoToSave property only after the agent options object is created.

Example: options.InfoToSave.Optimizer=true

Option to save the actor and critic optimizers, specified as a logical value. If you set the Optimizer field to false, then the actor and critic optimizers (which are hidden properties of the agent and can contain internal states) are not saved along with the agent, therefore saving disk space and memory. However, when the optimizers contain internal states, the state of the saved agent is not identical to the state of the original agent.

Example: true

Object Functions

rlACAgentActor-critic (AC) reinforcement learning agent

Examples

collapse all

Create an AC agent options object, specifying the discount factor.

opt = rlACAgentOptions(DiscountFactor=0.95)
opt = 
  rlACAgentOptions with properties:

                SampleTime: 1
            DiscountFactor: 0.9500
         EntropyLossWeight: 0
     ActorOptimizerOptions: [1x1 rl.option.rlOptimizerOptions]
    CriticOptimizerOptions: [1x1 rl.option.rlOptimizerOptions]
       NumStepsToLookAhead: 32
                InfoToSave: [1x1 struct]

You can modify options using dot notation. For example, set the agent sample time to 0.5.

opt.SampleTime = 0.5;

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.

Version History

Introduced in R2019a

expand all