rlDQNAgentOptions
Description
Use an rlDQNAgentOptions
object to specify options for deep
Q-network (DQN) agents. To create a DQN agent, use rlDQNAgent
.
For more information, see Deep Q-Network (DQN) Agents.
For more information on the different types of reinforcement learning agents, see Reinforcement Learning Agents.
Creation
Description
creates an options
object for use as an argument when creating a DQN agent using all default settings. You
can modify the object properties using dot notation.opt
= rlDQNAgentOptions
creates the options set opt
= rlDQNAgentOptions(Name=Value
)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.
Properties
UseDoubleDQN
— Option to use double DQN
true (default) | false
Option to use double DQN for value function target updates, specified as a logical value. For more information, see Deep Q-Network (DQN) Agents.
Example: UseDoubleDQN=false
EpsilonGreedyExploration
— Options for epsilon-greedy exploration
EpsilonGreedyExploration
object
Options for epsilon-greedy exploration, specified as an
EpsilonGreedyExploration
object with the following
properties.
Property | Description | Default Value |
---|---|---|
Epsilon | Probability threshold to either randomly select an action or select the action that maximizes the state-action value function. A larger value of Epsilon means that the agent randomly explores the action space at a higher rate. | 1 |
EpsilonMin | Minimum value of Epsilon | 0.01 |
EpsilonDecay | Decay rate | 0.0050 |
At the end of each training time step, if Epsilon
is greater than
EpsilonMin
, then it is updated using the following
formula.
Epsilon = Epsilon*(1-EpsilonDecay)
Note that Epsilon
is conserved between the end of an episode and
the start of the next one. Therefore, it keeps on uniformly decreasing over multiple
episodes until it reaches EpsilonMin
.
If your agent converges on local optima too quickly, you can promote agent exploration by
increasing Epsilon
.
To specify exploration options, use dot notation after creating the rlDQNAgentOptions
object opt
. For example, set the epsilon value to 0.9
.
opt.EpsilonGreedyExploration.Epsilon = 0.9;
CriticOptimizerOptions
— Critic optimizer options
rlOptimizerOptions
object
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)
BatchDataRegularizerOptions
— Batch data regularizer options
[]
(default) | rlBehaviorCloningRegularizerOptions
object
Batch data regularizer options, specified as an
rlBehaviorCloningRegularizerOptions
object. These options are
typically used to train the agent offline, from existing data. If you leave this option
empty, no regularizer is used.
For more information, see rlBehaviorCloningRegularizerOptions
.
Example: BatchDataRegularizerOptions =
rlBehaviorCloningRegularizerOptions(BehaviorCloningRegularizerWeight=10)
TargetSmoothFactor
— Smoothing factor for target critic updates
1e-3
(default) | positive scalar less than or equal to 1
Smoothing factor for target critic updates, specified as a positive scalar less than or equal to 1. For more information, see Target Update Methods.
Example: TargetSmoothFactor=1e-2
TargetUpdateFrequency
— Number of steps between target critic updates
1
(default) | positive integer
Number of steps between target critic updates, specified as a positive integer. For more information, see Target Update Methods.
Example: TargetUpdateFrequency=5
ResetExperienceBufferBeforeTraining
— Option for clearing the experience buffer
false
(default) | true
Option for clearing the experience buffer before training, specified as a logical value.
Example: ResetExperienceBufferBeforeTraining=true
SequenceLength
— Maximum batch-training trajectory length when using RNN
1
(default) | positive integer
Maximum batch-training trajectory length when using a recurrent neural network for
the critic, specified as a positive integer. This value must be greater than
1
when using a recurrent neural network for the critic and
1
otherwise.
Example: SequenceLength=4
MiniBatchSize
— Size of random experience mini-batch
64
(default) | positive integer
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 critic properties. Large mini-batches reduce the variance when computing gradients but increase the computational effort.
When using a recurrent neural network for the critic,
MiniBatchSize
is the number of experience trajectories in a
batch, where each trajectory has length equal to
SequenceLength
.
Example: MiniBatchSize=128
NumStepsToLookAhead
— Number of future rewards used to estimate the value of the policy
1
(default) | positive integer
Number of future rewards used to estimate the value of the policy, specified as a positive
integer. Specifically,
ifNumStepsToLookAhead
is equal
to N, the target value of the policy at a
given step is calculated adding the rewards for the following
N steps and the discounted
estimated value of the state that caused the
N-th reward. This target is also
called N-step return.
Note
When using a recurrent neural network for the critic,
NumStepsToLookAhead
must be
1
.
For more information, see [1], Chapter 7.
Example: NumStepsToLookAhead=3
ExperienceBufferLength
— Experience buffer size
10000
(default) | positive integer
Experience buffer size, specified as a positive integer. During training, the agent computes updates using a mini-batch of experiences randomly sampled from the buffer.
Example: ExperienceBufferLength=1e6
SampleTime
— Sample time of agent
1
(default) | positive scalar | -1
Sample time of agent, specified as a positive scalar or as -1
. Setting this
parameter to -1
allows for event-based simulations.
Within a Simulink® environment, the RL Agent block
in which the agent is specified to execute every SampleTime
seconds
of simulation time. If SampleTime
is -1
, the
block inherits the sample time from its parent subsystem.
Within a MATLAB® environment, the agent is executed every time the environment advances. In
this case, SampleTime
is the time interval between consecutive
elements in the output experience returned by sim
or
train
. If
SampleTime
is -1
, the time interval between
consecutive elements in the returned output experience reflects the timing of the event
that triggers the agent execution.
Example: SampleTime=-1
DiscountFactor
— Discount factor
0.99
(default) | positive scalar less than or equal to 1
Discount factor applied to future rewards during training, specified as a positive scalar less than or equal to 1.
Example: DiscountFactor=0.9
Object Functions
rlDQNAgent | Deep Q-network (DQN) reinforcement learning agent |
Examples
Create DQN Agent Options Object
Create an rlDQNAgentOptions
object that specifies the agent mini-batch size.
opt = rlDQNAgentOptions(MiniBatchSize=48)
opt = rlDQNAgentOptions with properties: SampleTime: 1 DiscountFactor: 0.9900 EpsilonGreedyExploration: [1x1 rl.option.EpsilonGreedyExploration] ExperienceBufferLength: 10000 MiniBatchSize: 48 SequenceLength: 1 CriticOptimizerOptions: [1x1 rl.option.rlOptimizerOptions] NumStepsToLookAhead: 1 UseDoubleDQN: 1 TargetSmoothFactor: 1.0000e-03 TargetUpdateFrequency: 1 BatchDataRegularizerOptions: [] ResetExperienceBufferBeforeTraining: 0 InfoToSave: [1x1 struct]
You can modify options using dot notation. For example, set the agent sample time to 0.5
.
opt.SampleTime = 0.5;
References
[1] Sutton, Richard S., and Andrew G. Barto. Reinforcement Learning: An Introduction. Second edition. Adaptive Computation and Machine Learning. Cambridge, Mass: The MIT Press, 2018.
Version History
Introduced in R2019aR2022a: The default value of the ResetExperienceBufferBeforeTraining
property has changed
The default value of the ResetExperienceBufferBeforeTraining
has
changed from true
to false
.
When creating a new DQN agent, if you want to clear the experience buffer before
training, you must specify ResetExperienceBufferBeforeTraining
as
true
. For example, before training, set the property using dot
notation.
agent.AgentOptions.ResetExperienceBufferBeforeTraining = true;
Alternatively, you can set the property to true
in an
rlDQNAgentOptions
object and use this object to create the DQN
agent.
R2020a: Target update method settings for DQN agents have changed
Target update method settings for DQN agents have changed. The following changes require updates to your code:
The
TargetUpdateMethod
option has been removed. Now, DQN agents determine the target update method based on theTargetUpdateFrequency
andTargetSmoothFactor
option values.The default value of
TargetUpdateFrequency
has changed from4
to1
.
To use one of the following target update methods, set the
TargetUpdateFrequency
and TargetSmoothFactor
properties as indicated.
Update Method | TargetUpdateFrequency | TargetSmoothFactor |
---|---|---|
Smoothing | 1 | Less than 1 |
Periodic | Greater than 1 | 1 |
Periodic smoothing (new method in R2020a) | Greater than 1 | Less than 1 |
The default target update configuration, which is a smoothing update with a
TargetSmoothFactor
value of 0.001
, remains the
same.
This table shows some typical uses of rlDQNAgentOptions
and how to update your code to use the new option configuration.
Not Recommended | Recommended |
---|---|
opt =
rlDQNAgentOptions('TargetUpdateMethod',"smoothing"); | opt = rlDQNAgentOptions; |
opt =
rlDQNAgentOptions('TargetUpdateMethod',"periodic"); | opt = rlDQNAgentOptions; opt.TargetUpdateFrequency = 4;
opt.TargetSmoothFactor = 1; |
opt = rlDQNAgentOptions; opt.TargetUpdateMethod = "periodic";
opt.TargetUpdateFrequency = 5; | opt = rlDQNAgentOptions; opt.TargetUpdateFrequency = 5;
opt.TargetSmoothFactor = 1; |
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
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)