rlberry.spaces.MultiDiscrete

class rlberry.spaces.MultiDiscrete(nvec, dtype=<class 'numpy.int64'>)[source]

Bases: MultiDiscrete

Inherited from gymnasium.spaces.MultiDiscrete 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.

from_jsonable(sample_n: list[Sequence[int]]) list[numpy.ndarray[Any, numpy.dtype[numpy.integer[Any]]]][source]

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

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.

reseed(seed_seq=None)[source]

Get new random number generator.

Parameters:
seed_seqnp.random.SeedSequence, rlberry.seeding.Seeder or int, defaultNone

Seed sequence from which to spawn the random number generator. If None, generate random seed. If int, use as entropy for SeedSequence. If seeder, use seeder.seed_seq

sample()[source]

Generates a single random sample this space.

Args:
mask: An optional mask for multi-discrete, expects tuples with a np.ndarray mask in the position of each

action with shape (n,) where n is the number of actions and dtype=np.int8. Only mask values == 1 are possible to sample unless all mask values for an action are 0 then the default action self.start (the smallest element) is sampled.

Returns:

An np.ndarray of shape space.shape

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

Seed the PRNG of this space and possibly the PRNGs of subspaces.

property shape: tuple[int, ...]

Has stricter type than gym.Space - never None.

to_jsonable(sample_n: Sequence[ndarray[Any, dtype[integer[Any]]]]) list[Sequence[int]][source]

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