rlberry.spaces.Tuple

class rlberry.spaces.Tuple(spaces)[source]

Bases: Tuple

Inherited from gymnasium.spaces.Tuple for compatibility with gym.

rlberry wraps gym.spaces to make sure the seeding mechanism is unified in the library (rlberry.seeding)

Attributes:
rngnumpy.random._generator.Generator

random number generator provided by rlberry.seeding

Methods

reseed()

get new random number generator

contains(x: Any) bool[source]

Return boolean specifying if x is a valid member of this space.

count(value) integer -- return number of occurrences of value
from_jsonable(sample_n: list[list[Any]]) list[tuple[Any, ...]][source]

Convert a JSONable data type to a batch of samples from this space.

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

property is_np_flattenable

Checks whether this space can be flattened to a spaces.Box.

property np_random: Generator

Lazily seed the PRNG since this is expensive and only needed if sampling from this space.

As seed() is not guaranteed to set the _np_random for particular seeds. We add a check after seed() to set a new random number generator.

sample(mask: tuple[Optional[Any], ...] | None = None) tuple[Any, ...][source]

Generates a single random sample inside this space.

This method draws independent samples from the subspaces.

Args:
mask: An optional tuple of optional masks for each of the subspace’s samples,

expects the same number of masks as spaces

Returns:

Tuple of the subspace’s samples

seed(seed: int | Sequence[int] | None = None) list[int][source]

Seed the PRNG of this space and all subspaces.

Depending on the type of seed, the subspaces will be seeded differently

  • None - All the subspaces will use a random initial seed

  • Int - The integer is used to seed the Tuple space that is used to generate seed values for each of the subspaces. Warning, this does not guarantee unique seeds for all of the subspaces.

  • List - Values used to seed the subspaces. This allows the seeding of multiple composite subspaces (List(42, 54, ...).

Args:

seed: An optional list of ints or int to seed the (sub-)spaces.

property shape: tuple[int, ...] | None

Return the shape of the space as an immutable property.

to_jsonable(sample_n: Sequence[tuple[Any, ...]]) list[list[Any]][source]

Convert a batch of samples from this space to a JSONable data type.