options for training multiple reinforcement learning agents -凯发k8网页登录
options for training multiple reinforcement learning agents
since r2022a
description
use an rlmultiagenttrainingoptions
object to specify training
options for multiple agents. to train the agents using the specified options, pass this object
to train
.
for more information on training agents, see train reinforcement learning agents.
creation
description
returns the default options for training multiple reinforcement learning agents. use
training options to specify parameters for the training session, such as the maximum
number of episodes to train, criteria for stopping training, and criteria for saving
agents. after configuring the options, use trainopts
= rlmultiagenttrainingoptionstrainopts
as an input
argument for train
.
creates a training option set and sets object properties using one or more
name-value pair arguments.trainopts
= rlmultiagenttrainingoptions(name,value
)
properties
agentgroups
— agent grouping indices
"auto"
(default) | cell array of positive integers | cell array of integer arrays
agent grouping indices, specified as a cell array of positive integers or a cell array of integer arrays.
for instance, consider a training scenario with 4 agents. you can group the agents in the following ways:
allocate each agent in a separate group:
trainopts = rlmultiagenttrainingoptions("agentgroups","auto")
specify four agent groups with one agent in each group:
trainopts = rlmultiagenttrainingoptions("agentgroups",{1,2,3,4})
specify two agent groups with two agents each:
trainopts = rlmultiagenttrainingoptions("agentgroups",{[1,2],[3,4]})
specify three agent groups:
trainopts = rlmultiagenttrainingoptions("agentgroups",{[1,4],2,3})
agentgroups
and learningstrategy
must be
used together to specify whether agent groups learn in a centralized manner or
decentralized manner.
example: agentgroups={1,2,[3,4]}
learningstrategy
— learning strategy for each agent group
"decentralized"
(default) | "centralized"
learning strategy for each agent group, specified as either
"decentralized"
or "centralized"
. in
decentralized training, agents collect their own set of experiences during the episodes
and learn independently from those experiences. in centralized training, the agents
share the collected experiences and learn from them together.
agentgroups
and learningstrategy
must be
used together to specify whether agent groups learn in a centralized manner or
decentralized manner. for example, you can use the following command to configure
training for three agent groups with different learning strategies. the agents with
indices [1,2] and [3,5] learn in a centralized manner, while agent 4 learns in a
decentralized
manner.
trainopts = rlmultiagenttrainingoptions(... agentgroups={[1,2],4,[3,5]},... learningstrategy=["centralized","decentralized","centralized"] )
example: learningstrategy="centralized"
maxepisodes
— maximum number of episodes to train the agents
500
(default) | positive integer
maximum number of episodes to train the agents, specified as a positive integer.
regardless of other criteria for termination, training terminates after
maxepisodes
.
example: maxepisodes=1000
maxstepsperepisode
— maximum number of steps to run per episode
500
(default) | positive integer
maximum number of steps to run per episode, specified as a positive integer. in general, you define episode termination conditions in the environment. this value is the maximum number of steps to run in the episode if other termination conditions are not met.
example: maxstepsperepisode=1000
scoreaveragingwindowlength
— window length for averaging
5
(default) | positive integer scalar | positive integer vector
window length for averaging the scores, rewards, and number of steps for each agent, specified as a scalar or vector.
specify a scalar to apply the same window length to all agents. to use a different
window length for each agent, specify scoreaveragingwindowlength
as
a vector. in this case, the order of the elements in the vector correspond to the order
of the agents used during environment creation.
for options expressed in terms of averages,
scoreaveragingwindowlength
is the number of episodes included in
the average. for instance, if stoptrainingcriteria
is
"averagereward"
and stoptrainingvalue
is
500
for a given agent then for that agent, training terminates when
the average reward over the number of episodes specified in
scoreaveragingwindowlength
equals or exceeds
500
. for the other agents, training continues until:
all agents reach their stop criteria.
the number of episodes reaches
maxepisodes
.you stop training by clicking the stop training button in episode manager or pressing ctrl-c at the matlab® command line.
example: scoreaveragingwindowlength=10
stoptrainingcriteria
— training termination condition
"averagesteps"
(default) | "averagereward"
| "episodereward"
| "globalstepcount"
| "episodecount"
| ...
training termination condition, specified as one of the following strings:
"averagesteps"
— stop training when the running average number of steps per episode equals or exceeds the critical value specified by the optionstoptrainingvalue
. the average is computed using the window'scoreaveragingwindowlength'
."averagereward"
— stop training when the running average reward equals or exceeds the critical value."episodereward"
— stop training when the reward in the current episode equals or exceeds the critical value."globalstepcount"
— stop training when the total number of steps in all episodes (the total number of times the agent is invoked) equals or exceeds the critical value."episodecount"
— stop training when the number of training episodes equals or exceeds the critical value.
example: stoptrainingcriteria="averagereward"
stoptrainingvalue
— critical value of training termination condition
500
(default) | scalar | vector
critical value of the training termination condition, specified as a scalar or a vector.
specify a scalar to apply the same termination criterion to all agents. to use a
different termination criterion for each agent, specify
stoptrainingvalue
as a vector. in this case, the order of the
elements in the vector corresponds to the order of the agents used during environment
creation.
for a given agent, training ends when the termination condition specified by the
stoptrainingcriteria
option equals or exceeds this value. for the
other agents, the training continues until:
all agents reach their stop criteria.
the number of episodes reaches
maxepisodes
.you stop training by clicking the stop training button in episode manager or pressing ctrl-c at the matlab command line.
for instance, if stoptrainingcriteria
is
"averagereward"
and stoptrainingvalue
is
100
for a given agent, then for that agent training terminates when
the average reward over the number of episodes specified in
scoreaveragingwindowlength
equals or exceeds
100
.
example: stoptrainingvalue=100
saveagentcriteria
— condition for saving agents during training
"none"
(default) | "episodereward"
| "averagesteps"
| "averagereward"
| "globalstepcount"
| "episodecount"
| ...
condition for saving agents during training, specified as one of the following strings:
"none"
— do not save any agents during training."episodereward"
— save the agent when the reward in the current episode equals or exceeds the critical value."averagesteps"
— save the agent when the running average number of steps per episode equals or exceeds the critical value specified by the optionstoptrainingvalue
. the average is computed using the window'scoreaveragingwindowlength'
."averagereward"
— save the agent when the running average reward over all episodes equals or exceeds the critical value."globalstepcount"
— save the agent when the total number of steps in all episodes (the total number of times the agent is invoked) equals or exceeds the critical value."episodecount"
— save the agent when the number of training episodes equals or exceeds the critical value.
set this option to store candidate agents that perform well according to the
criteria you specify. when you set this option to a value other than
"none"
, the software sets the saveagentvalue
option to 500. you can change that value to specify the condition for saving the agent.
for instance, suppose you want to store for further testing any agent that yields an
episode reward that equals or exceeds 100. to do so, set
saveagentcriteria
to "episodereward"
and set the
saveagentvalue
option to 100. when an episode reward equals or
exceeds 100, train
saves the corresponding agent in a mat-file in
the folder specified by the saveagentdirectory
option. the mat-file
is called agentk.mat
, where k
is the number of the
corresponding episode. the agent is stored within that mat-file as
saved_agent
.
example: saveagentcriteria="episodereward"
saveagentvalue
— critical value of condition for saving agents
"none"
(default) | 500 | scalar | vector
critical value of the condition for saving agents, specified as a scalar or a vector.
specify a scalar to apply the same saving criterion to each agent. to save the
agents when one meets a particular criterion, specify
saveagentvalue
as a vector. in this case, the order of the
elements in the vector corresponds to the order of the agents used when creating the
environment. when a criteria for saving an agent is met, all agents are saved in the
same mat-file.
when you specify a condition for saving candidate agents using
saveagentcriteria
, the software sets this value to 500. change
the value to specify the condition for saving the agent. see the
saveagentcriteria
option for more details.
example: saveagentvalue=100
saveagentdirectory
— folder for saved agents
"savedagents"
(default) | string | character vector
folder for saved agents, specified as a string or character vector. the folder name
can contain a full or relative path. when an episode occurs that satisfies the condition
specified by the saveagentcriteria
and
saveagentvalue
options, the software saves the agents in a mat-file
in this folder. if the folder does not exist, train
creates it.
when saveagentcriteria
is "none"
, this option is
ignored and train
does not create a folder.
example: saveagentdirectory = pwd "\run1\agents"
stoponerror
— option to stop training when error occurs
"on"
(default) | "off"
option to stop training when an error occurs during an episode, specified as
"on"
or "off"
. when this option is
"off"
, errors are captured and returned in the
simulationinfo
output of train
, and training
continues to the next episode.
example: stoponerror = "off"
verbose
— option to display training progress on the command line
false
(0
) (default) | true
(1
)
option to display training progress on the command line, specified as the logical
value false
(0
) or true
(1
). set to true
to write information from each
training episode to the matlab command line during training.
example: verbose = true
plots
— option to display training progress with episode manager
"training-progress"
(default) | "none"
option to display training progress with episode manager, specified as
"training-progress"
or "none"
. by default,
calling train
opens the reinforcement learning episode manager,
which graphically and numerically displays information about the training progress, such
as the reward for each episode, average reward, number of episodes, and total number of
steps. (for more information, see train
.) to turn
off this display, set this option to "none"
.
example: plots = "none"
object functions
train | train reinforcement learning agents within a specified environment |
examples
configure options for multi agent training
create an options set for training 5 reinforcement learning agents. set the maximum number of episodes and the maximum number of steps per episode to 1000. configure the options to stop training when the average reward equals or exceeds 480, and turn on both the command-line display and reinforcement learning episode manager for displaying training results. you can set the options using name-value pair arguments when you create the options set. any options that you do not explicitly set have their default values.
trainopts = rlmultiagenttrainingoptions(... agentgroups={[1,2],3,[4,5]},... learningstrategy=["centralized","decentralized","centralized"],... maxepisodes=1000,... maxstepsperepisode=1000,... stoptrainingcriteria="averagereward",... stoptrainingvalue=480,... verbose=true,... plots="training-progress")
trainopts = rlmultiagenttrainingoptions with properties: agentgroups: {[1 2] [3] [4 5]} learningstrategy: ["centralized" "decentralized" "centralized"] maxepisodes: 1000 maxstepsperepisode: 1000 stoponerror: "on" scoreaveragingwindowlength: 5 stoptrainingcriteria: "averagereward" stoptrainingvalue: 480 saveagentcriteria: "none" saveagentvalue: "none" saveagentdirectory: "savedagents" verbose: 1 plots: "training-progress"
alternatively, create a default options set and use dot notation to change some of the values.
trainopts = rlmultiagenttrainingoptions; trainopts.agentgroups = {[1,2],3,[4,5]}; trainopts.learningstrategy = ["centralized","decentralized","centralized"]; trainopts.maxepisodes = 1000; trainopts.maxstepsperepisode = 1000; trainopts.stoptrainingcriteria = "averagereward"; trainopts.stoptrainingvalue = 480; trainopts.verbose = true; trainopts.plots = "training-progress"; trainopts
trainopts = rlmultiagenttrainingoptions with properties: agentgroups: {[1 2] [3] [4 5]} learningstrategy: ["centralized" "decentralized" "centralized"] maxepisodes: 1000 maxstepsperepisode: 1000 stoponerror: "on" scoreaveragingwindowlength: 5 stoptrainingcriteria: "averagereward" stoptrainingvalue: 480 saveagentcriteria: "none" saveagentvalue: "none" saveagentdirectory: "savedagents" verbose: 1 plots: "training-progress"
you can now use trainopts
as an input argument to the train
command.
configure options for training a multi-agent environment
create an options object for concurrently training three agents in the same environment.
set the maximum number of episodes and the maximum steps per episode to 1000
. configure the options to stop training the first agent when its average reward over 5
episodes equals or exceeds 400
, the second agent when its average reward over 10
episodes equals or exceeds 500
, and the third when its average reward over 15
episodes equals or exceeds 600
. the order of agents is the one used during environment creation.
save the agents when the reward for the first agent in the current episode exceeds 100
, or when the reward for the second agent exceeds 120
, the reward for the third agent equals or exceeds 140
.
turn on both the command-line display and reinforcement learning episode manager for displaying training results. you can set the options using name-value pair arguments when you create the options set. any options that you do not explicitly set have their default values.
trainopts = rlmultiagenttrainingoptions(... maxepisodes=1000,... maxstepsperepisode=1000,... scoreaveragingwindowlength=[5 10 15],... stoptrainingcriteria="averagereward",... stoptrainingvalue=[400 500 600],... saveagentcriteria="episodereward",... saveagentvalue=[100 120 140],... verbose=true,... plots="training-progress")
trainopts = rlmultiagenttrainingoptions with properties: agentgroups: "auto" learningstrategy: "decentralized" maxepisodes: 1000 maxstepsperepisode: 1000 stoponerror: "on" scoreaveragingwindowlength: [5 10 15] stoptrainingcriteria: "averagereward" stoptrainingvalue: [400 500 600] saveagentcriteria: "episodereward" saveagentvalue: [100 120 140] saveagentdirectory: "savedagents" verbose: 1 plots: "training-progress"
alternatively, create a default options set and use dot notation to change some of the values.
trainopts = rlmultiagenttrainingoptions; trainopts.maxepisodes = 1000; trainopts.maxstepsperepisode = 1000; trainopts.scoreaveragingwindowlength = [5 10 15]; trainopts.stoptrainingcriteria = "averagereward"; trainopts.stoptrainingvalue = [400 500 600]; trainopts.saveagentcriteria = "episodereward"; trainopts.saveagentvalue = [100 120 140]; trainopts.verbose = true; trainopts.plots = "training-progress"; trainopts
trainopts = rlmultiagenttrainingoptions with properties: agentgroups: "auto" learningstrategy: "decentralized" maxepisodes: 1000 maxstepsperepisode: 1000 stoponerror: "on" scoreaveragingwindowlength: [5 10 15] stoptrainingcriteria: "averagereward" stoptrainingvalue: [400 500 600] saveagentcriteria: "episodereward" saveagentvalue: [100 120 140] saveagentdirectory: "savedagents" verbose: 1 plots: "training-progress"
you can specify a scalar to apply the same criterion to all agents. for example, use a window length of 10
for all three agents.
trainopts.scoreaveragingwindowlength = 10
trainopts = rlmultiagenttrainingoptions with properties: agentgroups: "auto" learningstrategy: "decentralized" maxepisodes: 1000 maxstepsperepisode: 1000 stoponerror: "on" scoreaveragingwindowlength: 10 stoptrainingcriteria: "averagereward" stoptrainingvalue: [400 500 600] saveagentcriteria: "episodereward" saveagentvalue: [100 120 140] saveagentdirectory: "savedagents" verbose: 1 plots: "training-progress"
you can now use trainopts
as an input argument to the train
command.
version history
introduced in r2022a
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
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)
- 中国
- (日本語)
- (한국어)