Observation Wrappers

posggym.ObservationWrapper

class posggym.ObservationWrapper(env: Env[StateType, ObsType, ActType])

Wraps environment to allow modular transformations of observations.

Subclasses should at least implement the observations function.

observations(obs: Dict[str, ObsType]) Dict[str, WrapperObsType]

Transforms observations received from wrapped environment.

Available Observation Wrappers

class posggym.wrappers.FlattenObservations(env: Env)

Observation wrapper that flattens the observation.

Parameters:

env (posggym.Env) – The environment to apply the wrapper

Note

This implementation is based on the similar Gymnasium wrapper: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/flatten_observation.py

class posggym.wrappers.RescaleObservations(env: Env, min_obs: float | int | ndarray | Dict[str, float | int | ndarray], max_obs: float | int | ndarray | Dict[str, float | int | ndarray])

Observation wrapper that rescales observations to the range [min_obs, max_obs].

The base environment env must have an observation space of type spaces.Box for each agent. If min_obs or max_obs are numpy arrays, the shape must match the shape of the environment’s observation space for the given agent. If min_obs or max_obs are dictionaries then they must have an entry for each possible agent ID in the wrapped environment.

Parameters:
  • env (posggym.Env) – The environment to apply the wrapper

  • min_obs (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The minimum value for the scaled observations.

  • max_obs (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The maximum value for the scaled observations.

Note

Explanation of how to scale number from one interval into new interval: https://stats.stackexchange.com/questions/281162/scale-a-number-between-a-range