Main Content

验证环境

验证自定义增强学习环境

Description

例子

验证环境(envvalidates a reinforcement learning environment. This function is useful when:

  • 您正在使用为自己提供自己的步骤和重置功能的自定义环境,例如使用rlCreateEnvTemplate

  • 您正在使用由Simulink创建的环境金宝app®模型使用rl金宝appsimulinkenv

验证环境重置环境,生成初始观察和动作,并模拟一个或两个步骤的环境(请参阅Algorithms)。If there are no errors during these operations, validation is successful, and验证环境返回没有结果。如果发生错误,这些错误会出现在MATLAB中®命令窗口。使用错误来确定在观察规范,操作规范,自定义功能或Simulink模型中要更改的内容。金宝app

Examples

collapse all

此示例显示了如何验证模拟环境。金宝app

创建和验证和环境rlwatertank代表包含加固学习代理的控制系统的模型(有关此模型的详细信息,请参阅创建Simul金宝appink环境和培训代理。)

open_system(“ rlwatertank”

为环境创建观察和行动规范。

obsInfo = rlNumericSpec([3 1],...“下限”,[ -  inf -Inf -inf 0]',,...“上限”,,,,[ inf inf inf]'); obsInfo.Name =“观察”;obsinfo.Description =“集成误差,错误和测量高度”;numObservations = obsInfo.Dimension(1); actInfo = rlNumericSpec([1 1]); actInfo.Name ='流动';numactions = numel(actinfo);

从模型创建环境。

env= rlSimulinkEnv(“ rlwatertank”,,,,'rlwatertank/RL Agent',obsinfo,actinfo);

现在您使用验证环境检查模型是否正确配置。

验证环境(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.

验证环境尝试编译模型,初始化环境和代理,并模拟模型。在这种情况下,RL代理块被配置为使用称为的代理代理人,但是MATLAB®工作区中不存在此类变量。因此,该函数返回指示问题的错误。

Create an appropriate agent for this system using the commands detailed in the创建Simul金宝appink环境和培训代理例子。在这种情况下,从rlwatertankddpgagent。matfile.

加载rlwatertankddpgagent

现在,运行验证环境again.

验证环境(env)

输入参数

collapse all

验证的环境,指定为强化学习环境对象,例如:

  • 您创建的自定义MATLAB环境rlCreateEnvTemplate。In this case,验证环境检查环境模拟期间产生的观察和动作是否在大小,数据类型和值范围内与观察规范和操作规范保持一致。它还检查您的自定义andresetfunctions run without error. (When you create a custom environment usingrlFunctionEnv,软件运行验证环境自动地。)

  • A custom Simulink environment you create usingrl金宝appsimulinkenv。If you use a Simulink environment, you must also have an agent defined and associated with theRL Agentblock in the model. For a Simulink model,验证环境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

collapse all

验证环境通过对环境进行简短的模拟来工作,并确保生成的信号与创建环境时提供的观察和操作规范匹配。

MATLABEnvironments

对于MATLAB环境,验证包括以下步骤。

  1. 使用reset与环境相关的功能。

  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. 根据操作规范中的维数,数据类型和值范围生成测试操作。

  4. 使用生成的动作和与环境相关的功能。

  5. 获取新的观察信号,并检查其是否与观察规范中的维数,数据类型和值范围一致。

如果这些操作中的任何一个都会产生错误,验证环境returns the error. If验证环境返回没有结果,然后验证成功。

金宝appEnvironments

对于Si金宝appmulink环境,验证包括以下步骤。

  1. Reset the environment.

  2. 模拟模型两个时间步骤。

如果这些操作中的任何一个都会产生错误,验证环境returns the error. If验证环境返回没有结果,然后验证成功。

验证环境执行这些步骤而不弄脏模型,并在您调用该函数时将所有模型参数留在他们所处的状态中。

版本历史记录

在R2019a中引入