Skip to content

Wrappers

Christian Kauten edited this page Jul 22, 2018 · 20 revisions

nes-py includes a full collection of OpenAI Gym wrappers for standard functionality. These functions are located in the nes_py.wrappers module.

  • easily converting the 256 action binary space to a smaller space
  • clipping rewards in {-1, 0, 1}
  • downsampling frames to B&W with a smaller size via linear interpolation
  • stacking the previous k frames into a frame tensor
  • normalizing rewards in [-1, 1] using the L-infinity norm
  • penalizing deaths using the done flag
  • caching unmodified rewards for analysis

BinarySpaceToDiscreteSpaceEnv

A simple way to define a much smaller action space. The initializer takes an environment and a list of button lists:

from nes_py.wrappers import BinarySpaceToDiscreteSpaceEnv
env = BinarySpaceToDiscreteSpaceEnv(env, [
    ['NOP'],
    ['right', 'A'],
    ['left', 'A'],
    ['A'],
])

Each button list should contain at least one of:

  • 'right'
  • 'left'
  • 'down'
  • 'up'
  • 'start'
  • 'select'
  • 'B'
  • 'A'
  • 'NOP'

Note

It is recommended for custom environments to use this wrapper by default. If there are multiple mappings, the package should provide each list and either register a different environment for each, or make note in the documentation for end users. See gym-super-mario-bros for an example of multiple button lists in the actions.py module.

ClipRewardEnv

A wrapper to clip rewards based on their sign. i.e.

  • reward = 1 if reward > 0
  • reward = -1 if reward < 0
  • reward = 0 if reward == 0
from nes_py.wrappers import ClipRewardEnv
env = ClipRewardEnv(env)

DownsampleEnv

from nes_py.wrappers import DownsampleEnv

FrameStackEnv

from nes_py.wrappers import FrameStackEnv

NormalizeRewardEnv

from nes_py.wrappers import NormalizeRewardEnv

PenalizeDeathEnv

from nes_py.wrappers import PenalizeDeathEnv

RewardCacheEnv

from nes_py.wrappers import RewardCacheEnv

wrap

from nes_py.wrappers import wrap
Clone this wiki locally