rlberry.spaces.MultiDiscrete¶
- class rlberry.spaces.MultiDiscrete(nvec, dtype=<class 'numpy.int64'>)[source]¶
Bases:
MultiDiscreteInherited 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
- 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 afterseed()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.ndarraymask in the position of each action with shape
(n,)wherenis the number of actions anddtype=np.int8. Onlymask values == 1are possible to sample unless all mask values for an action are0then the default actionself.start(the smallest element) is sampled.
- mask: An optional mask for multi-discrete, expects tuples with a
- Returns:
An
np.ndarrayofSpace.shape()
- seed(seed: int | None = None) int | list[int] | dict[str, int]¶
Seed the pseudorandom number generator (PRNG) of this space and, if applicable, the PRNGs of subspaces.
- Args:
seed: The seed value for the space. This is expanded for composite spaces to accept multiple values. For further details, please refer to the space’s documentation.
- Returns:
The seed values used for all the PRNGs, for composite spaces this can be a tuple or dictionary of values.
- property shape: tuple[int, ...]¶
Has stricter type than
gym.Space- never None.