load predefined simulink environments -凯发k8网页登录

main content

load predefined simulink environments

reinforcement learning toolbox™ software provides predefined simulink® environments for which the actions, observations, rewards, and dynamics are already defined. you can use these environments to:

  • learn reinforcement learning concepts.

  • gain familiarity with reinforcement learning toolbox software features.

  • test your own reinforcement learning agents.

you can load the following predefined simulink environments using the rlpredefinedenv function.

environmentagent task
simple pendulum simulink modelswing up and balance a simple pendulum using either a discrete or continuous action space.
cart-pole simscape™ modelbalance a pole on a moving cart by applying forces to the cart using either a discrete or continuous action space.

for predefined simulink environments, the environment dynamics, observations, and reward signal are defined in a corresponding simulink model. the rlpredefinedenv function creates a simulinkenvwithagent object that the train function uses to interact with the simulink model.

simple pendulum simulink model

this environment is a simple frictionless pendulum that initially hangs in a downward position. the training goal is to make the pendulum stand upright without falling over using minimal control effort. the model for this environment is defined in the rlsimplependulummodel simulink model.

open_system('rlsimplependulummodel')

simulink model of a pendulum system in a feedback loop with an agent block.

there are two simple pendulum environment variants, which differ by the agent action space.

  • discrete — agent can apply a torque of either tmax, 0, or -tmax to the pendulum, where tmax is the max_tau variable in the model workspace.

  • continuous — agent can apply any torque within the range [-tmax,tmax].

to create a simple pendulum environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('simplependulummodel-discrete');
  • continuous action space

    env = rlpredefinedenv('simplependulummodel-continuous');

for examples that train agents in the simple pendulum environment, see:

actions

in the simple pendulum environments, the agent interacts with the environment using a single action signal, the torque applied at the base of the pendulum. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the simple pendulum environment, the agent receives the following three observation signals, which are constructed within the create observations subsystem.

  • sine of the pendulum angle

  • cosine of the pendulum angle

  • derivative of the pendulum angle

for each observation signal, the environment contains an rlnumericspec observation specification. all the observations are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment, which is constructed in the calculate reward subsystem, is

rt=(θt2 0.1θ˙t2 0.001ut12)

here:

  • θt is the pendulum angle of displacement from the upright position.

  • θ˙t is the derivative of the pendulum angle.

  • ut-1 is the control effort from the previous time step.

cart-pole simscape model

the goal of the agent in the predefined cart-pole environments is to balance a pole on a moving cart by applying horizontal forces to the cart. the pole is considered successfully balanced if both of the following conditions are satisfied:

  • the pole angle remains within a given threshold of the vertical position, where the vertical position is zero radians.

  • the magnitude of the cart position remains below a given threshold.

the model for this environment is defined in the rlcartpolesimscapemodel simulink model. the dynamics of this model are defined using simscape multibody™.

open_system('rlcartpolesimscapemodel')

simulink model of an environment in a feedback loop with an agent block.

in the environment subsystem, the model dynamics are defined using simscape components and the reward and observation are constructed using simulink blocks.

open_system('rlcartpolesimscapemodel/environment')

simulink model of a cart-pole system.

there are two cart-pole environment variants, which differ by the agent action space.

  • discrete — agent can apply a force of 15, 0, or -15 to the cart.

  • continuous — agent can apply any force within the range [-15,15].

to create a cart-pole environment, use the rlpredefinedenv function.

  • discrete action space

    env = rlpredefinedenv('cartpolesimscapemodel-discrete');
  • continuous action space

    env = rlpredefinedenv('cartpolesimscapemodel-continuous');

for an example that trains an agent in this cart-pole environment, see .

actions

in the cart-pole environments, the agent interacts with the environment using a single action signal, the force applied to the cart. the environment contains a specification object for this action signal. for the environment with a:

  • discrete action space, the specification is an rlfinitesetspec object.

  • continuous action space, the specification is an rlnumericspec object.

for more information on obtaining action specifications from an environment, see getactioninfo.

observations

in the cart-pole environment, the agent receives the following five observation signals.

  • sine of the pole angle

  • cosine of the pole angle

  • derivative of the pendulum angle

  • cart position

  • derivative of cart position

for each observation signal, the environment contains an rlnumericspec observation specification. all the observations are continuous and unbounded.

for more information on obtaining observation specifications from an environment, see getobservationinfo.

reward

the reward signal for this environment is the sum of two components (r = rqr rn rp):

  • a quadratic regulator control reward, constructed in the environment/qr reward subsystem.

    rqr=(0.1x2 0.5θ2 0.005ut12)

  • a cart limit penalty, constructed in the environment/x limit penalty subsystem. this subsystem generates a negative reward when the magnitude of the cart position exceeds a given threshold.

    rp=100(|x|3.5)

here:

  • x is the cart position.

  • θ is the pole angle of displacement from the upright position.

  • ut-1 is the control effort from the previous time step.

see also

functions

blocks

related examples

more about

    网站地图