Flattening¶
This module implements a block transformation for flattening observation space of the environment.
- class gym_jiminy.common.wrappers.flatten.FlattenObservation(env, dtype=None)[source]¶
Bases:
BaseTransformObservation
[ndarray
[Any
,dtype
[float64
]],Obs
,Act
],Generic
[Obs
,Act
]Flatten the observation space of a pipeline environment. It will appear as a simple one-dimension vector.
Note
Following the general (but unusual) convention in Gym-Jiminy, the batching dimensions appears last when aggregating homogeneous data to vectorize computations. This design choice is motivated by efficiency for the default memory layout of Numpy, i.e. row-major (C-style order). Because of this, flattening a multi-dimensional array while pack together components rather than batched element. This is undesirable because values while be spread apart the whole vector after flattening when adding new batch element, which makes it very difficult to compare flattened vectors at first glance. It is also more challenging and computationally expensive to perform operations directly on the flattened vector representation such as mirroring. To get around this issue, all multi-dimensional arrays are transposed before flattening, which is sementically equivalent to data.ravel(order=’F’).
Warning
All leaves of the observation space must have type gym.spaces.Box.
- Parameters:
env (InterfaceJiminyEnv[Obs, Act]) – Environment to wrap.
dtype (dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]) – Numpy dtype of the flattened observation. If None, the most appropriate dtype to avoid lost of information if possible will be picked, following standard coercion rules. See np.promote_types for details. Optional: None by default.
- class gym_jiminy.common.wrappers.flatten.FlattenAction(env, dtype=None)[source]¶
Bases:
BaseTransformAction
[ndarray
[Any
,dtype
[float64
]],Obs
,Act
],Generic
[Obs
,Act
]Flatten the action space of a pipeline environment. It will appear as a simple one-dimension vector.
Note
Fortran-Style order is used when flattening multi-dimensional arrays. See FlattenObservation documentation for details.
Warning
All leaves of the action space must have type gym.spaces.Box.
- Parameters:
env (InterfaceJiminyEnv[Obs, Act]) – Environment to wrap.
dtype (dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]) – Numpy dtype of the flattened action. If None, the most appropriate dtype to avoid lost of information if possible will be picked, following standard coercion rules. See np.promote_types for details. Optional: None by default.