Created
August 19, 2020 20:48
-
-
Save colllin/1172e042edf267d5ec667fa9802673cf to your computer and use it in GitHub Desktop.
OpenAI Gym FlattenAction wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
class FlattenAction(gym.ActionWrapper): | |
"""Action wrapper that flattens the action.""" | |
def __init__(self, env): | |
super(FlattenAction, self).__init__(env) | |
self.action_space = gym.spaces.utils.flatten_space(self.env.action_space) | |
def action(self, action): | |
return gym.spaces.utils.unflatten(self.env.action_space, action) | |
def reverse_action(self, action): | |
return gym.spaces.utils.flatten(self.env.action_space, action) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment