rlberry.spaces
.MultiBinary¶
- class rlberry.spaces.MultiBinary(n)[source]¶
Bases:
MultiBinary
Inherited from gymnasium.spaces.MultiBinary 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.int8]]] [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 from this space.
A sample is drawn by independent, fair coin tosses (one toss per binary variable of the space).
- Args:
- mask: An optional np.ndarray to mask samples with expected shape of
space.shape
. For
mask == 0
then the samples will be0
andmask == 1` then random samples will be generated. The expected mask shape is the space shape and mask dtype is ``np.int8
.
- mask: An optional np.ndarray to mask samples with expected shape of
- Returns:
Sampled values from space
- 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.