schola.core.spaces.discrete.DiscreteSpace
类定义
class schola.core.spaces.discrete.DiscreteSpace(n)基类: Discrete, UnrealSpace
表示单个离散值的空间。
另请参阅
gymnasium.spaces.Discrete– 此类所对应的 gym 空间对象proto_spaces.DiscreteSpace– 此空间的 protobuf 表示
参数
n
Type: int
空间中的离散值数量。例如,空间是区间 [0,n] 中的一个值
属性
n
Type: int
空间中的离散值数量。
is_np_flattenable
检查此空间是否可以展平为spaces.Box。
np_random
延迟初始化 PRNG,因为这很耗时,并且仅在从此空间采样时才需要。
shape
将空间形状作为不可变属性返回。
proto_space
别名:DiscreteSpace
方法
__init__
__init__(n)Discrete 空间的构造函数。
这将构造空间 {start, …, start + n - 1}。
参数
- n (
int) – 此空间的元素数量 - seed – 可选,您可以使用此参数为用于从
Dict空间采样的 RNG 设置种子 - start (
int) – 此空间中的最小元素
contains
contains(x)返回一个布尔值,指定 x 是否为此空间的一个有效成员。
fill_proto
fill_proto(msg, value)将此空间中的点的 Python 表示转换为 protobuf 消息。会修改 msg 以包含结果。
参数
- msg (
proto_points.FundamentalPoint) – 要填充的 protobuf 消息 - value (
Any) – 点的 Python 表示
from_jsonable
from_jsonable(sample_n)将 JSON 样本列表转换为 np.int64 列表。
from_proto
@classmethodfrom_proto(message)从 protobuf 表示创建 Space 对象。
is_empty_definition
@classmethodis_empty_definition(message)当且仅当此空间的大小为 0 时,返回 True。
参数
- message (
proto_space) – 要检查是否为空的 protobuf 消息
返回: 如果空间为空,则返回 True。
返回类型: bool
merge
@classmethodmerge(*spaces)将多个 DiscreteSpaces 合并为单个空间。
参数
- \*spaces (
List[Union[DiscreteSpace, MultiDiscreteSpace]]) – 要合并的空间
返回: 合并后的空间。
返回类型: MultiDiscreteSpace
引发: TypeError – 如果任何空间不是 Discrete 或 MultiDiscrete。
另请参见: merge_discrete_like_spaces – 将多个 Discrete 或 MultiDiscrete 空间合并为单个 MultiDiscrete 空间。
process_data
process_data(msg)将此空间中的点对应的 protobuf 消息转换为 Python 表示。
参数
- msg (
proto_points.FundamentalPoint) – 要转换的 protobuf 消息
返回: 点的 Python 表示。
返回类型: np.ndarray
sample
sample(mask=None)从此空间生成一个随机样本。
seed
seed(seed=None)为该空间及其子空间的 PRNG 设置种子。
to_jsonable
to_jsonable(sample_n)将样本列表转换为整数列表。
to_normalized
to_normalized()返回空间的标准化版本。如果空间子类未实现 to_normalized,则为空操作。
返回: 标准化后的空间。
返回类型: UnrealSpace