schola.core.spaces.dict.DictSpace
class schola.core.spaces.dict.DictSpace(space_dict=None)
: Bases: Dict
A Space representing a dictionary of spaces.
Parameters: : space_dict (Dict*[str,* gymnasium.spaces.Space]) – The dictionary of spaces to be represented.
spaces : The dictionary of spaces represented by this object.
Type: : Dict[str, gymnasium.spaces.Space]
See also
gymnasium.spaces.Dict
: The gym space object that this class is analogous to.
proto_spaces.DictSpace
: The protobuf representation of this space.
Methods
__init__ ([space_dict]) | Constructor of Dict space. |
contains (x) | Return boolean specifying if x is a valid member of this space. |
fill_proto (msg, action) | |
from_jsonable (sample_n) | Convert a JSONable data type to a batch of samples from this space. |
from_proto (message) | |
get (k[,d]) | |
items () | |
keys () | Returns the keys of the Dict. |
process_data (msg) | |
sample ([mask]) | Generates a single random sample from this space. |
seed ([seed]) | Seed the PRNG of this space and all subspaces. |
simplify () | Simplify the dictionary space by merging subspaces of the same fundamental type, if possible. |
to_jsonable (sample_n) | Convert a batch of samples from this space to a JSONable data type. |
to_normalized () | Normalize this dictionary space by normalizing all of the subspaces in this dictionary space. |
values () |
Attributes
has_only_one_fundamental_type | Check if all the subspaces in the dictionary space are of the same fundamental type. |
is_np_flattenable | Checks whether this space can be flattened to a spaces.Box . |
np_random | Lazily seed the PRNG since this is expensive and only needed if sampling from this space. |
shape | Return the shape of the space as an immutable property. |
shapes | Get the shapes of the subspaces in the dictionary space. |
__init__(space_dict=None)
: Constructor of Dict
space.
This space can be instantiated in one of two ways: Either you pass a dictionary
of spaces to __init__()
via the spaces
argument, or you pass the spaces as separate
keyword arguments (where you will need to avoid the keys spaces
and seed
)
Parameters:
: - spaces – A dictionary of spaces. This specifies the structure of the Dict
space
- seed – Optionally, you can use this argument to seed the RNGs of the spaces that make up the
Dict
space. - **spaces_kwargs – If
spaces
isNone
, you need to pass the constituent spaces as keyword arguments, as described above.
fill_proto(msg, action) : Parameters: : msg (DictPoint)
classmethod from_proto(message)
property has_only_one_fundamental_type : Check if all the subspaces in the dictionary space are of the same fundamental type.
Returns: : True if all the subspaces are of the same fundamental type, False otherwise
Return type: : bool
Examples
>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": DiscreteSpace(3)})>>> space.has_only_one_fundamental_typeFalse
>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": BoxSpace([0,0],[2,2])})>>> space.has_only_one_fundamental_typeTrue
>>> space = DictSpace({"a": DiscreteSpace(3), "b": MultiDiscreteSpace([3,3])})>>> space.has_only_one_fundamental_typeTrue
process_data(msg) : Parameters: : msg (DictPoint)
property shapes : Get the shapes of the subspaces in the dictionary space.
Returns: : A dictionary of the shapes of the subspaces in the dictionary space
Return type: : Dict[str, Tuple[int]]
Examples
>>> space = DictSpace({"a": BoxSpace(0, 1, shape=(2,)), "b": DiscreteSpace(3)})>>> space.shapes{'a': 2, 'b': 1}
simplify() : Simplify the dictionary space by merging subspaces of the same fundamental type, if possible.
Returns: : The simplified space
Return type: : gymnasium.spaces.Space
Examples
>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": BoxSpace([0,0],[2,2])})>>> space.simplify()Box(0.0, 2.0, (4,), float32)
>>> space = DictSpace({"a": DiscreteSpace(4), "b": BoxSpace([0,0],[2,2])})>>> space.simplify()Dict('a': Discrete(4), 'b': Box(0.0, 2.0, (2,), float32))
>>> space = DictSpace({"a": DiscreteSpace(4)})>>> space.simplify()Discrete(4)
to_normalized() : Normalize this dictionary space by normalizing all of the subspaces in this dictionary space.
Returns: : The normalized dictionary space. A modified version of the space this method is called on
Return type: : DictSpace
Examples
>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": DiscreteSpace(3)})>>> space.to_normalized()Dict('a': Box(0.0, 2.0, (2,), float32), 'b': Discrete(3))