options for td3 agent -凯发k8网页登录
options for td3 agent
since r2020a
description
use an rltd3agentoptions
object to specify options for
twin-delayed deep deterministic policy gradient (td3) agents. to create a td3 agent, use
rltd3agent
.
for more information see twin-delayed deep deterministic (td3) policy gradient 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 td3 agent using all default options. you can
modify the object properties using dot notation.opt
= rltd3agentoptions
creates the options set opt
= rltd3agentoptions(name=value
)opt
and sets its properties using one
or more name-value arguments. for example,
rltd3agentoptions(discountfactor=0.95)
creates an option set with a
discount factor of 0.95
. you can specify multiple name-value
arguments.
properties
explorationmodel
— exploration noise model options
gaussianactionnoise
object (default) | ornsteinuhlenbeckactionnoise
object
noise model options, specified as a gaussianactionnoise
object or
an ornsteinuhlenbeckactionnoise
object. for more information on noise
models, see noise models.
for an agent with multiple actions, if the actions have different ranges and units, it is likely that each action requires different noise model parameters. if the actions have similar ranges and units, you can set the noise parameters for all actions to the same value.
for example, for an agent with two actions, set the standard deviation of each action to a different value while using the same decay rate for both standard deviations.
opt = rltd3agentoptions; opt.explorationmodel.standarddeviation = [0.1 0.2]; opt.explorationmodel.standarddeviationdecayrate = 1e-4;
to use ornstein-uhlenbeck action noise, first create a default
ornsteinuhlenbeckactionnoise
object. then, specify any nondefault
model properties using dot notation.
opt = rltd3agentoptions; opt.explorationmodel = rl.option.ornsteinuhlenbeckactionnoise; opt.explorationmodel.standarddeviation = 0.05;
targetpolicysmoothmodel
— target smoothing noise model options
gaussianactionnoise
object
target smoothing noise model options, specified as a
gaussianactionnoise
object. this model helps the policy exploit
actions with high q-value estimates. for more information on noise models, see noise models.
for an agent with multiple actions, if the actions have different ranges and units, it is likely that each action requires different smoothing noise model parameters. if the actions have similar ranges and units, you can set the noise parameters for all actions to the same value.
for example, for an agent with two actions, set the standard deviation of each action to a different value while using the same decay rate for both standard deviations.
opt = rltd3agentoptions; opt.targetpolicysmoothmodel.standarddeviation = [0.1 0.2]; opt.targetpolicysmoothmodel.standarddeviationdecayrate = 1e-4;
policyupdatefrequency
— number of steps between policy updates
2
(default) | positive integer
number of steps between policy updates, specified as a positive integer.
actoroptimizeroptions
— actor optimizer options
rloptimizeroptions
object
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)
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 .
example: batchdataregularizeroptions =
rlbehaviorcloningregularizeroptions(behaviorcloningregularizerweight=10)
targetsmoothfactor
— smoothing factor for target actor and critic updates
0.005
(default) | positive scalar less than or equal to 1
smoothing factor for target actor and critic updates, specified as a positive scalar less than or equal to 1. for more information, see .
example: targetsmoothfactor=1e-2
targetupdatefrequency
— number of steps between target actor and critic updates
2
(default) | positive integer
number of steps between target actor and critic updates, specified as a positive integer. for more information, see .
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, specified as a positive integer. this value must be greater than 1
when using a recurrent neural network 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.
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
rltd3agent | twin-delayed deep deterministic (td3) policy gradient reinforcement learning agent |
examples
create td3 agent options object
create an rltd3agentoptions
object that specifies the mini-batch size.
opt = rltd3agentoptions(minibatchsize=48)
opt = rltd3agentoptions with properties: sampletime: 1 discountfactor: 0.9900 explorationmodel: [1x1 rl.option.gaussianactionnoise] experiencebufferlength: 10000 minibatchsize: 48 sequencelength: 1 actoroptimizeroptions: [1x1 rl.option.rloptimizeroptions] criticoptimizeroptions: [1x2 rl.option.rloptimizeroptions] numstepstolookahead: 1 policyupdatefrequency: 2 targetpolicysmoothmodel: [1x1 rl.option.gaussianactionnoise] targetsmoothfactor: 0.0050 targetupdatefrequency: 2 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;
algorithms
noise models
a gaussianactionnoise
object has the following numeric value
properties.
property | description | default value
(explorationmodel ) | default value
(targetpolicysmoothmodel ) |
---|---|---|---|
mean | noise mean value | 0 | 0 |
standarddeviationdecayrate | decay rate of the standard deviation | 0 | 0 |
standarddeviation | initial value of noise standard deviation | sqrt(0.1) | sqrt(0.2) |
standarddeviationmin | minimum standard deviation, which must be less than
standarddeviation | 0.01 | 0.01 |
lowerlimit | noise sample lower limit | -inf | -0.5 |
upperlimit | noise sample upper limit | inf | 0.5 |
at each time step k
, the gaussian noise v
is
sampled as shown in the following code.
w = mean randn(actionsize).*standarddeviation(k); v(k 1) = min(max(w,lowerlimit),upperlimit);
where the initial value v(1) is defined by the initialaction
parameter. at each sample time step, the standard deviation decays as shown in the
following code.
decayedstandarddeviation = standarddeviation(k).*(1 - standarddeviationdecayrate); standarddeviation(k 1) = max(decayedstandarddeviation,standarddeviationmin);
note that standarddeviation
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
standarddeviationmin
.
an ornsteinuhlenbeckactionnoise
object has the following numeric value
properties.
property | description | default value |
---|---|---|
initialaction | initial value of action | 0 |
mean | noise mean value | 0 |
meanattractionconstant | constant specifying how quickly the noise model output is attracted to the mean | 0.15 |
standarddeviationdecayrate | decay rate of the standard deviation | 0 |
standarddeviation | initial value of noise standard deviation | 0.3 |
standarddeviationmin | minimum standard deviation | 0 |
at each sample time step k
, the noise value v(k)
is
updated using the following formula, where ts
is the agent sample
time, and the initial value v(1) is defined by the initialaction
parameter.
v(k 1) = v(k) meanattractionconstant.*(mean - v(k)).*ts standarddeviation(k).*randn(size(mean)).*sqrt(ts)
at each sample time step, the standard deviation decays as shown in the following code.
decayedstandarddeviation = standarddeviation(k).*(1 - standarddeviationdecayrate); standarddeviation(k 1) = max(decayedstandarddeviation,standarddeviationmin);
you can calculate how many samples it will take for the standard deviation to be halved using this simple formula.
halflife = log(0.5)/log(1-standarddeviationdecayrate);
note that standarddeviation
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
standarddeviationmin
.
for continuous action signals, it is important to set the noise standard deviation
appropriately to encourage exploration. it is common to set
standarddeviation*sqrt(ts)
to a value between 1% and 10% of
your action range.
if your agent converges on local optima too quickly, promote agent exploration by increasing
the amount of noise; that is, by increasing the standard deviation. also, to increase
exploration, you can reduce the standarddeviationdecayrate
.
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 r2020ar2022a: 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 td3 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
rltd3agentoptions
object and use this object to create the td3
agent.
r2021a: properties defining noise probability distribution in the gaussianactionnoise
object have changed
the properties defining the probability distribution of the gaussian action noise model have changed. this noise model is used by td3 agents for exploration and target policy smoothing.
the
variance
property has been replaced by thestandarddeviation
property.the
variancedecayrate
property has been replaced by thestandarddeviationdecayrate
property.the
variancemin
property has been replaced by thestandarddeviationmin
property.
when a gaussianactionnoise
noise object saved from a previous
matlab release is loaded, the value of variancedecayrate
is
copied to standarddeviationdecayrate
, while the square root of the
values of variance
and variancemin
are copied to
standarddeviation
and standarddeviationmin
,
respectively.
the variance
, variancedecayrate
, and
variancemin
properties still work, but they are not recommended. to
define the probability distribution of the gaussian action noise model, use the new property
names instead.
this table shows how to update your code to use the new property names for
rltd3agentoptions
object td3opt
.
not recommended | recommended |
---|---|
td3opt.explorationmodel.variance = 0.5; | td3opt.explorationmodel.standarddeviation =
sqrt(0.5); |
td3opt.explorationmodel.variancedecayrate = 0.1; | td3opt.explorationmodel.standarddeviationdecayrate =
0.1; |
td3opt.explorationmodel.variancemin = 0.1; | td3opt.explorationmodel.standarddeviationmin =
sqrt(0.1); |
r2021a: property names defining noise probability distribution in the ornsteinuhlenbeckactionnoise
object have changed
the properties defining the probability distribution of the ornstein-uhlenbeck (ou) noise model have been renamed. td3 agents use ou noise for exploration.
the
variance
property has been renamedstandarddeviation
.the
variancedecayrate
property has been renamedstandarddeviationdecayrate
.the
variancemin
property has been renamedstandarddeviationmin
.
the default values of these properties remain the same. when an
ornsteinuhlenbeckactionnoise
noise object saved from a previous
matlab release is loaded, the values of variance
,
variancedecayrate
, and variancemin
are copied in
the standarddeviation
, standarddeviationdecayrate
,
and standarddeviationmin
, respectively.
the variance
, variancedecayrate
, and
variancemin
properties still work, but they are not recommended. to
define the probability distribution of the ou noise model, use the new property names
instead.
this table shows how to update your code to use the new property names for
rltd3agentoptions
object td3opt
.
not recommended | recommended |
---|---|
td3opt.explorationmodel.variance = 0.5; | td3opt.explorationmodel.standarddeviation =
sqrt(0.5); |
td3opt.explorationmodel.variancedecayrate = 0.1; | td3opt.explorationmodel.standarddeviationdecayrate =
0.1; |
td3opt.explorationmodel.variancemin = 0.1; | td3opt.explorationmodel.standarddeviationmin =
sqrt(0.1); |
td3opt.targetpolicysmoothmodel.variance = 0.5; | td3opt.targetpolicysmoothmodel.standarddeviation =
sqrt(0.5); |
td3opt.targetpolicysmoothmodel.variancedecayrate =
0.1; | td3opt.targetpolicysmoothmodel.standarddeviationdecayrate =
0.1; |
td3opt.targetpolicysmoothmodel.variancemin = 0.1; | td3opt.targetpolicysmoothmodel.standarddeviationmin =
sqrt(0.1); |
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 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
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)