reinforcement learning environments
in a reinforcement learning scenario, where you train an agent to complete a task, the environment models the external system (that is the world) with which the agent interacts. a multiagent environment interacts with more than one agent at the same time.
in control systems applications, this external system is often referred to as the plant. any reference signal that might need to be tracked by some of the environment variables is also included in the environment.
the agent and the environment interact at each of a sequence of discrete time steps:
at a given time step t, the environment is in a state s(t), which results in the observation o(t).
based on o(t) and its internal policy function, the agent calculates an action a(t).
based on both the state s(t) and the action a(t), and according to its internal dynamics, the environment updates its state to s(t 1), which results in the next observation o(t 1).
based on s(t), a(t), and s(t 1), the environment also calculates a scalar reward r(t 1). the reward is an immediate measure of how good the action a(t) is.
at the next time step t 1 the agent receives the observation o(t 1) and the reward r(t 1).
based on the history of observations and rewards received, the learning algorithm updates the agent policy parameters in an attempt to improve the policy function. the parameter update may occur at each step or after a subsequence of steps.
based on o(t 1) and on its policy function, the agent calculates the next action a(t 1), and the process is repeated.
starting from time t=1 and using subscripts to indicate time, the causal sequence of events, often also called trajectory, can be summarized as o1,a1,r2,o2,a2. the interaction between the environment and the agent is also illustrated in the following figure, where the dashed lines represent a delay of one step.
by convention, the observation can be divided into one or more
channels, each of which carries a group of single elements all
belonging to either a numeric (infinite and continuous) set or a finite (discrete) set. each
group can be organized according to any number of dimensions (for example a vector or a
matrix). only one channel is allowed for the action; also, the reward must be a numeric
scalar. for more information on specification objects for actions and observations, see
rlfinitesetspec
and
rlnumericspec
.
environment objects
reinforcement learning toolbox™ represents environments with matlab® objects. such objects interact with agents using object functions (methods)
such as step
or reset
. specifically, at the
beginning of each training or simulation episode, the reset function is called (by a
training or simulation function) to set the environment initial condition. then at each
training or simulation time step, the step function is called to update the state of the
environment and return the next state along with a reward.
after you create an environment object in the matlab workspace, you can extract observation and action specifications from the
variable. you can then use these specifications to create an agent that works within your
environment. you can then use both the environment and agent variables as arguments for the
built-in functions train
and sim
, which train or
simulate the agent within the environment, respectively. alternatively, you can create your
custom training or simulation loop that calls the environment reset
and
step
functions directly.
the following sections summarize the different types of environment provided by the software.
markov decision process (mdp) environments
mdp environments are environments in which state and observation belong to finite spaces, and state transitions are in general governed by stochastic rules.
grid world environments are a special case of mdp environments. here, the state represents a position in a two-dimensional grid, while the action represents a move from the current position to the next, which an agent might attempt. grid world environments are often used in many introductory reinforcement learning examples.
you can use three types of mdp environment.
predefined grid world environments
reinforcement learning toolbox provides three predefined grid world environment object types. for predefined environments, all states, actions, and rewards are already defined. you can use them to learn basic reinforcement learning concepts and gain familiarity with reinforcement learning toolbox software features. for an introduction to predefined grid world environments, see load predefined grid world environments.
custom grid world environments
you can create custom grid worlds of any size with your own custom rewards, state transitions, and obstacle configurations. once you create a custom grid world environment, you can train and simulate agents with it as you do with a predefined environment.
for an introduction to custom grid worlds, see create custom grid world environments.
custom markov decision process (mdp) environments
you can also create custom generic mdp environments by supplying your own state and action sets. to create generic mdp environments, see
createmdp
andrlmdpenv
.
predefined control system environments
control system environments are environments that represent dynamical systems in which state and observation typically belong to infinite (and uncountable) numerical vector spaces. here, the state transition laws are deterministic and often derived by discretizing the dynamics of an underlying physical system that you want to model. note that in these environments the action can still belong to a finite set.
reinforcement learning toolbox provides several predefined control system environment objects that model dynamical systems such a double integrator or cart-pole system. in general each predefined environment comes in two versions, one with a discrete (finite) action space and the other with a continuous (infinite and uncountable) action space.
environments that rely on an underlying simulink® model for the calculation of the state transition, reward, and observation are called simulink environments. some of the predefined control system environments belong to this category.
multiagent environments are environments in which you can train and simulate multiple agents together. some of the predefined control system environments are multiagent environments.
you can use predefined control system environments to learn how to apply reinforcement learning to the control of physical systems, gain familiarity with reinforcement learning toolbox software features, or test your own agents. for an introduction to predefined control system environments, see load predefined control system environments.
custom environments
you can create different types of custom environments. once you create a custom environment, you can train and simulate agents as with any other environment.
for critical considerations on defining reward and observation signals in custom environments, see define reward and observation signals in custom environments.
you can create three different types of custom environment.
custom function environments
custom function environments rely (for the calculation of the state transition, reward, observation, and initial state) on custom
step
andreset
matlab functions.for single-agent environments, once you define your action and observation specifications and write your custom step and reset functions, you use
rlfunctionenv
to return an environment object that can interact with your agent in the same way any other environment does.for an example on custom functions environments, see create custom environment using step and reset functions.
you can also create two different kinds of custom multiagent function environments:
multiagent environments with universal sample time, in which all agents execute in the same step.
turn-based function environments, in which agents execute in turns. specifically, the environment assigns execution to only one group of agents at a time, and the group executes when it is its turn to do so. for an example, see .
for both kinds of multiagent environments, the observation and action specifications are cell arrays of specification objects in which each element corresponds to one agent.
for custom multiagent function environments with universal sample time, use
rlmultiagentfunctionenv
to return an environment object. for custom turn-based multiagent function environments, userlturnbasedfunctionenv
.to specify options for training agents in multiagent environment, create and configure a
rlmultiagenttrainingoptions
object. doing so allows you to specify, for example, whether different groups of agents are trained in a decentralized or centralized manner. in a group of agents subject to decentralized training, each agent collects its own set of experiences and learns from its own set of experiences. in a group of agents subject to centralized training, each agent shares its experiences with the other agents in the group and each agent in the group learns from the collective shared experiences.you can train and simulate your agents within a multiagent environment is using
train
andsim
, respectively.custom template environments
custom template environments are based on a modified class template.
to create a custom template environment, you use
rlcreateenvtemplate
to open a matlab script that contains a template class for an environment, then modify the template, specifying environment properties, required environment functions, and optional environment functions.while this process is more elaborate than just writing custom
step
andreset
functions, it gives you more flexibility in adding properties or methods that might be needed for your application. for example, you can write a custom plot method to plot a visual representation of the environment at a given time.for an introduction to creating environments using a template, see create custom environment from class template.
custom simulink environments
custom simulink environments are based on a simulink model that you design.
you can also use simulink to design multiagent environments. in particular, simulink allows you to model environments with multi-rate execution, in which each agent may have its own execution rates.
for an introduction to creating custom simulink environments, see create custom simulink environments.
neural network environments
neural network environments are custom environments that rely on a neural network for the calculation of the state transition. here, state and observation belong to continuous spaces and the state transitions laws can be deterministic or stochastic.
neural network environments can be used within model-based reinforcement learning agents, such as .
for more information on how to create neural network environments, see rlneuralnetworkenvironment
.
see also
functions
rlpredefinedenv
|getactioninfo
|getobservationinfo
|rlcreateenvtemplate
|validateenvironment
|rlsimulinkenv
|bus2rlspec
|createintegratedenv
objects
rlnumericspec
|rlfinitesetspec
|rlfunctionenv
|rlmultiagentfunctionenv
|rlturnbasedfunctionenv
|simulinkenvwithagent
|rlneuralnetworkenvironment