Scaling and normalization

This module implements two block transformations for applying scaling factors to subtrees of the observation and action spaces of the environment.

class gym_jiminy.common.wrappers.scale.ScaleObservation(env, nested_scale)[source]

Bases: BaseTransformObservation[Obs, Obs, Act], Generic[Obs, Act]

Apply (inverse) scaling factors on subtrees or leaves of the observation space of a given pipeline environment.

Warning

All leaf space of the observation space on which a scaling factor is applied must be gym.spaces.Box instance with floating point dtype.

Parameters:
  • env (InterfaceJiminyEnv[Obs, Act]) – Base or already wrapped jiminy environment.

  • nested_scale (Sequence[Tuple[Tuple[str | int, ...] | Tuple[Unpack[Tuple[str | int, ...]], Sequence[Tuple | int | Tuple[int | None, int | None]]], float]]) – Sequence of tuple (nested_data, scale) where ‘nested_data’ is itself sequence of nested keys, with eventually an array view spec at the end. if an array view is specified, then the nested key must map to a leaf of the corresponding nested space. The array view spec is a sequence of int, empty tuple, or pair of optional int that fully specified independent slices to extract for each dimension of the array associated with the leaf that the nested key is mapping to.

transform_observation()[source]

Compute the transformed observation from the original wrapped environment observation.

Note

The environment observation self.env.observation has been updated prior to calling this method and therefore can be safely accessed.

Note

For the sake of efficiency, this method should directly update in-place the pre-allocated transformed observation buffer self.observation instead of returning a temporary.

Return type:

None

class gym_jiminy.common.wrappers.scale.ScaleAction(env, nested_scale)[source]

Bases: BaseTransformAction[Act, Obs, Act], Generic[Obs, Act]

Apply scaling factors on subtrees or leaves of the action space of a given pipeline environment.

Warning

All leaf space of the action space on which a scaling factor is applied must be gym.spaces.Box instance with floating point dtype.

Parameters:
  • env (InterfaceJiminyEnv[Obs, Act]) – Base or already wrapped jiminy environment.

  • nested_scale (Sequence[Tuple[Tuple[str | int, ...] | Tuple[Unpack[Tuple[str | int, ...]], Sequence[Tuple | int | Tuple[int | None, int | None]]], float]]) – Sequence of tuple (nested_data, scale) where ‘nested_data’ is itself sequence of nested keys, with eventually an array view spec at the end. if an array view is specified, then the nested key must map to a leaf of the corresponding nested space. The array view spec is a sequence of int, empty tuple, or pair of optional int that fully specified independent slices to extract for each dimension of the array associated with the leaf that the nested key is mapping to.

transform_action(action)[source]

Update in-place pre-allocated transformed action buffer with the normalized action of the wrapped environment.

Parameters:

action (Act)

Return type:

None

This module implements two block transformations for normalizing the observation and action spaces of the environment.

class gym_jiminy.common.wrappers.normalize.NormalizeObservation(env, ignore_unbounded=False)[source]

Bases: BaseTransformObservation[Obs, Obs, Act], Generic[Obs, Act]

Normalize (without clipping) the observation space of a pipeline environment according to its pre-defined bounds rather than statistics over collected data.

Warning

All leaves of the observation space must have type gym.spaces.Box.

Parameters:
  • env (InterfaceJiminyEnv[Obs, Act]) – Base or already wrapped jiminy environment.

  • ignore_unbounded (bool) – If True, then spaces that are not bounded will be ignored, leaving them unchanged even if some elements are bounded. If False, it will raise an exception if in such a case.

transform_observation()[source]

Compute the transformed observation from the original wrapped environment observation.

Note

The environment observation self.env.observation has been updated prior to calling this method and therefore can be safely accessed.

Note

For the sake of efficiency, this method should directly update in-place the pre-allocated transformed observation buffer self.observation instead of returning a temporary.

Return type:

None

class gym_jiminy.common.wrappers.normalize.NormalizeAction(env, ignore_unbounded=False)[source]

Bases: BaseTransformAction[Act, Obs, Act], Generic[Obs, Act]

Normalize (without clipping) the action space of a pipeline environment according to its pre-defined bounds rather than statistics over collected data. Unbounded elements if any are left unchanged.

Warning

All leaves of the action space must have type gym.spaces.Box.

Parameters:
  • env (InterfaceJiminyEnv[Obs, Act]) – Base or already wrapped jiminy environment.

  • kwargs – Extra keyword arguments for multiple inheritance.

  • ignore_unbounded (bool)

transform_action(action)[source]

Compute the transformed action from the provided wrapped environment action.

Note

For the sake of efficiency, this method should directly update in-place the pre-allocated action buffer of the wrapped environment self.env.action instead of returning a temporary.

Parameters:

action (Act)

Return type:

None