如何使观察在自定义Pyenvronment中

发布于 2025-02-13 21:41:21 字数 1092 浏览 3 评论 0原文

In the 用于TF-Agent Environments的TensorFlow文档有一个简单(二十一点启发)卡游戏的环境的示例。

__ INIT __看起来如下:

class CardGameEnv(py_environment.PyEnvironment):

  def __init__(self):
    self._action_spec = array_spec.BoundedArraySpec(
        shape=(), dtype=np.int32, minimum=0, maximum=1, name='action')
    self._observation_spec = array_spec.BoundedArraySpec(
        shape=(1,), dtype=np.int32, minimum=0, name='observation')
    self._state = 0
    self._episode_ended = False

但是,如果我的观察结果不能以数字而表达而需要一个字符串,该怎么办?我不能简单地指定dtype = strdtype = pd.str,因为有min/max属性:

TypeError: Cannot find minimum value of <dtype: 'string'> with type <dtype: 'string'>.
  In call to configurable 'BoundedArraySpec' (<class 'tf_agents.specs.array_spec.BoundedArraySpec'>)

有人有任何想法吗?

In the tensorflow documentation for TF-Agents Environments there is an example of an environment for a simple (blackjack inspired) card game.

The __init__ looks like the following:

class CardGameEnv(py_environment.PyEnvironment):

  def __init__(self):
    self._action_spec = array_spec.BoundedArraySpec(
        shape=(), dtype=np.int32, minimum=0, maximum=1, name='action')
    self._observation_spec = array_spec.BoundedArraySpec(
        shape=(1,), dtype=np.int32, minimum=0, name='observation')
    self._state = 0
    self._episode_ended = False

But what if my observation can't be expressed as a number but needs a string? I can't simply specify dtype=str or dtype=pd.str because of the min/max attributes:

TypeError: Cannot find minimum value of <dtype: 'string'> with type <dtype: 'string'>.
  In call to configurable 'BoundedArraySpec' (<class 'tf_agents.specs.array_spec.BoundedArraySpec'>)

Anyone got any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文