Action Wrappers
posggym.ActionWrapper
Available Action Wrappers
- class posggym.wrappers.DiscretizeActions(env: Env, num_actions: int, flatten: bool = False)
Action wrapper that discretizes continuous action space.
The base environment
envmust have an action space of typespaces.Boxfor each agent. Ifflattenis True and original action space is multi-dimensional withndimdimensions, then will create discretized space withnum_actions ** ndimactions.- Parameters:
env (posggym.Env) – The environment to apply the wrapper
num_actions (int) – The number of actions to discretize space into. For multi-dimensional continuous spaces each dimension will be discretized into this many actions.
flatten (bool) – Whether to flatten action space into one-dimensional discrete space, or keep number of dimensions of the original action space.
- class posggym.wrappers.RescaleActions(env: Env, min_action: float | int | ndarray | Dict[str, float | int | ndarray], max_action: float | int | ndarray | Dict[str, float | int | ndarray])
Action wrapper that rescales continuous action space.
Rescales actions from [min, max] range to the action space range of the environment.
The base environment
envmust have an action space of typespaces.Boxfor each agent. Ifmin_actionormax_actionare numpy arrays, the shape must match the shape of the environment’s action space for the given agent. Ifmin_actionormax_actionare 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_action (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The minimum value for the scaled actions.
max_action (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The maximum value for the scaled actions.
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
Implementation also based on similar wrapper from gymnasium: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/rescale_action.py