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 be 0 and mask == 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) 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.