一文李青 理清Gym中的Box类
在OpenAI公司的gym库中,任何一个拥有连续状态的强化学习游戏环境都会用到Box数据类型,Box是一个类。
Box的部分官方代码如下:
import numpy as np
import warnings
from .space import Space
from gym import logger
class Box(Space):
"""
A (possibly unbounded) box in R^n. Specifically, a Box represents the
Cartesian product of n closed intervals. Each interval has the form of one
of [a, b], (-oo, b], [a, oo), or (-oo, oo).
There are two common use cases:
* Identical bound for each dimension::
>>> Box(low=-1.0, high=2.0, shape=(3, 4), dtype=np.float32)
Box(3, 4)
* Independent bound for each dimension::
>>> Box(low=np.array([-1.0, -2.0]), high=np.array([2.0, 4.0]), dtype=np.float32)
Box(2,)
"""
上面的代码来自gym的box.py文件。并且官方有对这个box类的注释,翻译过来如下:
那么究竟什么是box数据类型呢?
做一个实验你就懂了,如下:
box数据类型有两种常用方式。