Space
- class eagerx.core.space.Space(low=None, high=None, shape=None, dtype=<class 'numpy.float32'>, seed=None)[source]
A (possibly unbounded) space in R^n. Specifically, a Space represents the Cartesian product of n closed intervals. Each interval has the form of one of [a, b], (-oo, b], [a, oo), or (-oo, oo).
There are two common use cases:
- Identical bound for each dimension::
>>> Space(low=-1.0, high=2.0, shape=(3, 4), dtype="float32") Space(3, 4)
- Independent bound for each dimension::
>>> Space(low=np.array([-1.0, -2.0]), high=np.array([2.0, 4.0]), dtype="float32") Space(2,)
- contains(x)[source]
Return boolean specifying if x is a valid member of this space :param x: array to check.
- Return type
bool
- contains_space(space)[source]
Return boolean specifying if space is contained in this space. Low and high of the space must exactly match (instead of lying within the bounds) to return True :type space:
Union
[Space
,Dict
] :param space: Space that is to be checked.- Return type
bool
- classmethod from_dict(d)[source]
Create a space from a dict.
- Parameters
d (
Dict
) – Dict containing the arguments to initialize the space- Return type
- Returns
The space.
- from_jsonable(sample_n)[source]
Convert a JSONable data type to a batch of samples from this space.
- sample()[source]
Randomly sample an element of this space. Can be uniform or non-uniform sampling based on boundedness of space.
- Return type
ndarray
- seed(seed=None)[source]
Seed the PRNG of this space and possibly the PRNGs of subspaces.
- Return type
list[int]
- to_dict()[source]
Convert the space to a dict representation
- Return type
Dict
- Returns
Dict representation of the space.
- property is_fully_defined: bool
Check if space is fully defined (i.e. low, high, shape and dtype are all provided). :rtype:
bool
:return: flag
- property is_np_flattenable
Checks whether this space can be flattened.
- property np_random: numpy.random._generator.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.- Return type
Generator
- property shape: tuple[int, ...] | None
Return the shape of the space as an immutable property.