rlberry.spaces
.Box¶
- class rlberry.spaces.Box(low, high, shape=None, dtype=<class 'numpy.float64'>)[source]¶
Bases:
Box
Class that represents a space that is a cartesian product in R^n:
[a_1, b_1] x [a_2, b_2] x … x [a_n, b_n]
Inherited from gymnasium.spaces.Box 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: Sequence[float | int]) list[numpy.ndarray[Any, numpy.dtype[Any]]] [source]¶
Convert a JSONable data type to a batch of samples from this space.
- is_bounded(manner: str = 'both') bool [source]¶
Checks whether the box is bounded in some sense.
- Args:
manner (str): One of
"both"
,"below"
,"above"
.- Returns:
If the space is bounded
- Raises:
ValueError: If manner is neither
"both"
nor"below"
or"above"
- 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]¶
Adapted from: https://raw.githubusercontent.com/openai/gym/master/gym/spaces/box.py
Generates a single random sample inside of the Box.
In creating a sample of the box, each coordinate is sampled according to the form of the interval:
[a, b] : uniform distribution
[a, oo) : shifted exponential distribution
(-oo, b] : shifted negative exponential distribution
(-oo, oo) : normal distribution
- 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.