gxm.spaces#

Spaces for defining action and observation spaces.

class Box(low, high, shape)#

Bases: Space

A bounded box in \(\mathbb{R}^n\).

contains(x)#

Check whether specific object is within space.

Parameters:

x (Any) – Object to be checked.

Return type:

Array

Returns:

Whether the object is within the space.

high: Array#

Upper bound of the box.

low: Array#

Lower bound of the box.

property n: int#
sample(key, shape=())#

Sample uniformly from the box.

Parameters:
  • key (Array) – JAX random key.

  • shape (Tuple[int, ...]) – Shape of the sample to be drawn.

Return type:

Any

Returns:

Sample drawn from the box.

shape: Tuple[int, ...]#

Shape of the box.

class Discrete(n)#

Bases: Space

A discrete space consiting of \(\{0, 1, ..., n-1\}\).

contains(x)#

Check whether specific object is within space.

Parameters:

x (Any) – The object to be checked.

Return type:

Array

Returns:

Whether the object is contained in the space.

property n: int#
sample(key, shape=())#

Sample random action uniformly from \(\{0, 1, ..., n-1\}\).

Parameters:
  • key (Array) – A JAX random key used for sampling.

  • shape (Tuple[int, ...]) – The shape of the returned sample.

Return type:

Array

Returns:

The sampled value.

class Space#

Bases: object

Abstract base class for action and observation spaces.

contains(x)#
Return type:

Any

property n: int#
sample(key, shape=())#
Return type:

Any

class Tree(spaces)#

Bases: Space

Space composed of multiple subspaces in a tree structure.

contains(x)#

Check whether dimensions of object are within subspace.

Parameters:

x (Array) – Object to be checked.

Return type:

bool

Returns:

True if object is within all subspaces, False otherwise.

property n: int#
sample(key, shape=())#

Sample random action from all subspaces, retaining the original structure.

Parameters:
  • key (Array) – JAX random key.

  • shape (Tuple[int, ...]) – Shape of the sample to be drawn from each subspace.

Return type:

Any

Returns:

A tree-structured object with samples from each subspace.