mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-08 16:55:22 +00:00
* add dtype to Box * remove board_game, debugging, safety, parameter_tuning environments * massive set of breaking changes - remove python logging module - _step, _reset, _seed, _close => non underscored method - remove benchmark and scoring folder * Improve render("human"), now resizable, closable window. * get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods * CubeCrash unit test environment * followup fixes * MemorizeDigits unit test envrionment * refactored spaces a bit fixed indentation disabled test_env_semantics * fix unit tests * fixes * CubeCrash, MemorizeDigits tested * gym backwards compatibility patch * gym backwards compatibility, followup fixes * changelist, add spaces to main namespaces * undo_logger_setup for backwards compat * remove configuration.py
22 lines
759 B
Python
22 lines
759 B
Python
import gym
|
|
from gym import spaces, Space
|
|
import numpy as np
|
|
|
|
class MultiDiscrete(Space):
|
|
def __init__(self, nvec):
|
|
"""
|
|
nvec: vector of counts of each categorical variable
|
|
"""
|
|
self.nvec = np.asarray(nvec, dtype=np.int32)
|
|
assert self.nvec.ndim == 1, 'nvec should be a 1d array (or list) of ints'
|
|
Space.__init__(self, (self.nvec.size,), np.int8)
|
|
def sample(self):
|
|
return (spaces.np_random.rand(self.nvec.size) * self.nvec).astype(self.dtype)
|
|
def contains(self, x):
|
|
return (x < self.nvec).all() and x.dtype.kind in 'ui'
|
|
def to_jsonable(self, sample_n):
|
|
return [sample.tolist() for sample in sample_n]
|
|
def from_jsonable(self, sample_n):
|
|
return np.array(sample_n)
|
|
|