Main Content

rlSACAgentOptions

Options for SAC agent

Description

Use an rlSACAgentOptions object to specify options for soft actor-critic (SAC) agents. To create a SAC agent, use rlSACAgent.

For more information, see Soft Actor-Critic Agents.

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

Creation

Description

opt = rlSACAgentOptions creates an options object for use as an argument when creating a SAC agent using all default options. You can modify the object properties using dot notation.

example

opt = rlSACAgentOptions(Name,Value) sets option properties using name-value pairs. For example, rlSACAgentOptions('DiscountFactor',0.95) creates an option set with a discount factor of 0.95. You can specify multiple name-value pairs. Enclose each property name in quotes.

Properties

expand all

Entropy tuning options, specified as an EntropyWeightOptions object with the following properties.

Initial entropy component weight, specified as a positive scalar.

Optimizer learning rate, specified as a nonnegative scalar. If LearnRate is zero, the EntropyWeight value is fixed during training and the TargetEntropy value is ignored.

Target entropy value for tuning entropy weight, specified as a scalar. A higher target entropy value encourages more exploration.

If you do not specify TargetEntropy, the agent uses –A as the target value, where A is the number of actions.

Optimizer for entropy tuning, specified as one of the following strings.

  • "adam" — Use the Adam optimizer. You can specify the decay rates of the gradient and squared gradient moving averages using the GradientDecayFactor and SquaredGradientDecayFactor fields of the OptimizerParameters option.

  • "sgdm" — Use the stochastic gradient descent with momentum (SGDM) optimizer. You can specify the momentum value using the Momentum field of the OptimizerParameters option.

  • "rmsprop" — Use the RMSProp optimizer. You can specify the decay rate of the squared gradient moving average using the SquaredGradientDecayFactor fields of the OptimizerParameters option.

For more information about these optimizers, see Stochastic Gradient Descent in Deep Learning Toolbox™.

Threshold value for the entropy gradient, specified as Inf or a positive scalar. If the gradient exceeds this value, the gradient is clipped.

Applicable parameters for the optimizer, specified as an OptimizerParameters object with the following parameters. The default parameter values work well for most problems.

ParameterDescriptionDefault
Momentum

Contribution of previous step, specified as a scalar from 0 to 1. A value of 0 means no contribution from the previous step. A value of 1 means maximal contribution.

This parameter applies only when Optimizer is "sgdm".

0.9
Epsilon

Denominator offset, specified as a positive scalar. The optimizer adds this offset to the denominator in the network parameter updates to avoid division by zero.

This parameter applies only when Optimizer is "adam" or "rmsprop".

1e-8
GradientDecayFactor

Decay rate of gradient moving average, specified as a positive scalar from 0 to 1.

This parameter applies only when Optimizer is "adam".

0.9
SquaredGradientDecayFactor

Decay rate of squared gradient moving average, specified as a positive scalar from 0 to 1.

This parameter applies only when Optimizer is "adam" or "rmsprop".

0.999

When a particular property of OptimizerParameters is not applicable to the optimizer type specified in the Optimizer option, that property is set to "Not applicable".

To change the default values, access the properties of OptimizerParameters using dot notation.

opt = rlSACAgentOptions;
opt.EntropyWeightOptions.OptimizerParameters.GradientDecayFactor = 0.95;

Number of steps between actor policy updates, specified as a positive integer. For more information, see Training Algorithm.

Number of steps between critic updates, specified as a positive integer. For more information, see Training Algorithm.

Number of steps between target critic updates, specified as a positive integer. For more information, see Target Update Methods.

Smoothing factor for target critic updates, specified as a positive scalar less than or equal to 1. For more information, see Target Update Methods.

Size of random experience mini-batch, specified as a positive integer. During each training episode, the agent randomly samples experiences from the experience buffer when computing gradients for updating the actor and critics. Large mini-batches reduce the variance when computing gradients but increase the computational effort.

Option for clearing the experience buffer before training, specified as a logical value.

Number of steps to look ahead when computing the return, specified as a positive integer.

Experience buffer size, specified as a positive integer. During training, the agent updates the actor and critics using a mini-batch of experiences randomly sampled from the buffer.

Sample time of agent, specified as a positive scalar.

Within a Simulink environment, the agent gets executed every SampleTime seconds of simulation time.

Within a MATLAB environment, the agent gets executed every time the environment advances. However, SampleTime is the time interval between consecutive elements in the output experience returned by sim or train.

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

Option for saving the experience buffer data when saving the agent, specified as a logical value. This option applies both when saving candidate agents during training and when saving agents using the save function.

For some agents, such as those with a large experience buffer and image-based observations, the memory required for saving their experience buffer is large. In such cases, to not save the experience buffer data, set SaveExperienceBufferWithAgent to false.

If you plan to further train your saved agent, you can start training with the previous experience buffer as a starting point. In this case, set SaveExperienceBufferWithAgent to true.

Number of actions to take before updating actor and critics, specified as a positive integer. By default, the NumWarmStartSteps value is equal to the MiniBatchSize value.

Number of gradient steps to take when updating actor and critics, specified as a positive integer.

Object Functions

rlSACAgentSoft actor-critic reinforcement learning agent

Examples

collapse all

Create a SAC agent options object, specifying the discount factor.

opt = rlSACAgentOptions('DiscountFactor',0.95)
opt = 
  rlSACAgentOptions with properties:

                   EntropyWeightOptions: [1x1 rl.option.EntropyWeightOptions]
                  PolicyUpdateFrequency: 1
                  CriticUpdateFrequency: 1
                      NumWarmStartSteps: 64
              NumGradientStepsPerUpdate: 1
                     TargetSmoothFactor: 1.0000e-03
                  TargetUpdateFrequency: 1
    ResetExperienceBufferBeforeTraining: 1
          SaveExperienceBufferWithAgent: 0
                          MiniBatchSize: 64
                    NumStepsToLookAhead: 1
                 ExperienceBufferLength: 10000
                             SampleTime: 1
                         DiscountFactor: 0.9500

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

opt.SampleTime = 0.5;

For SAC agents, configure the entropy weight optimizer using the options in EntropyWeightOptions. For example, set the target entropy value to –5.

opt.EntropyWeightOptions.TargetEntropy = -5;
Introduced in R2020b