Skip to content

Commit

Permalink
Add Enum observation space unflattening (from one hot encoding)
Browse files Browse the repository at this point in the history
  • Loading branch information
iksnagreb committed Oct 4, 2021
1 parent 784937e commit 8a4c607
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gym_csgo/spaces/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ def flatten_enum(space, x):
onehot[space.values.tolist().index(x)] = 1
# Return one hot encoded flat enum space
return onehot

# Reverse the flatten_enum operation
@gym.spaces.unflatten.register(Enum)
def unflatten_enum(space, x):
# Lookup enum value at encoded position
return space.values[np.nonzero(x)[0][0]]

0 comments on commit 8a4c607

Please sign in to comment.