main content

validate custom reinforcement learning environment -凯发k8网页登录

validate custom reinforcement learning environment

since r2019a

description

example

validateenvironment(env) validates a reinforcement learning environment. this function is useful when:

when you create a custom environment using rlfunctionenv or rlneuralnetworkenvironment, the software runs validateenvironment automatically after creating the environment object.

validateenvironment resets the environment, generates an initial observation and action, and simulates the environment for one or two steps (see algorithms). if there are no errors during these operations, validation is successful, and validateenvironment returns no result. if errors occur, these errors appear in the matlab® command window. use the errors to determine what to change in your observation specification, action specification, custom functions, or simulink model.

examples

this example shows how to validate a simulink environment.

create and validate and environment for the rlwatertank model, which represents a control system containing a reinforcement learning agent (for details about this model, see create simulink environment and train agent.)

open_system("rlwatertank")

create observation and action specifications for the environment.

obsinfo = rlnumericspec([3 1],...
    lowerlimit=[-inf -inf 0  ]',...
    upperlimit=[ inf  inf inf]');
obsinfo.name = "observations";
obsinfo.description = 'integrated error, error, and measured height';
numobservations = obsinfo.dimension(1);
actinfo = rlnumericspec([1 1]);
actinfo.name = "flow";
numactions = numel(actinfo);

create an environment from the model.

env = rlsimulinkenv("rlwatertank","rlwatertank/rl agent",obsinfo,actinfo);

now you use validateenvironment to check whether the model is configured correctly.

validateenvironment(env)
error using rl.env.simulinkenvwithagent/validateenvironment (line 187) 
simulink environment validation requires an agent in the matlab base workspace 
or in a data dictionary linked to the model. specify the agent in the simulink model. 

validateenvironment attempts to compile the model, initialize the environment and the agent, and simulate the model. in this case, the rl agent block is configured to use an agent called agent, but no such variable exists in the matlab® workspace. thus, the function returns an error indicating the problem.

create an appropriate agent for this system using the commands detailed in the create simulink environment and train agent example. in this case, load the agent from the rlwatertankddpgagent.mat file.

load rlwatertankddpgagent

now, run validateenvironment again.

validateenvironment(env)

input arguments

environment to validate, specified as a reinforcement learning environment object, such as:

  • a custom matlab environment you create with rlcreateenvtemplate. in this case, validateenvironment checks that the observations and actions generated during simulation of the environment are consistent in size, data type, and value range with the observation specification and action specification. it also checks that your custom step and reset functions run without error. when you create a custom environment using rlfunctionenv or rlneuralnetworkenvironment, the software runs validateenvironment automatically before returning the environment object.

  • a custom simulink environment you create using rlsimulinkenv. if you use a simulink environment, you must also have an agent defined and associated with the rl agent block in the model. for a simulink model, validateenvironment checks that the model compiles and runs without error. the function does not dirty your model.

for more information about creating and configuring environments, see:

algorithms

validateenvironment works by running a brief simulation of the environment and making sure that the generated signals match the observation and action specifications you provided when you created the environment.

matlab environments

for matlab environments, validation includes the following steps.

  1. reset the environment using the reset function associated with the environment.

  2. obtain the first observation and check whether it is consistent with the dimension, data type, and range of values in the observation specification.

  3. generate a test action based on the dimension, data type, and range of values in the action specification.

  4. simulate the environment for one step using the generated action and the step function associated with the environment.

  5. obtain the new observation signal and check whether it is consistent with the dimension, data type, and range of values in the observation specification.

if any of these operations generates an error, validateenvironment returns the error. if validateenvironment returns no result, then validation is successful.

simulink environments

for simulink environments, validation includes the following steps.

  1. reset the environment.

  2. simulate the model for two time steps.

if any of these operations generates an error, validateenvironment returns the error. if validateenvironment returns no result, then validation is successful.

validateenvironment performs these steps without dirtying the model, and leaves all model parameters in the state they were in when you called the function.

version history

introduced in r2019a

网站地图