Cleanup, removal of unmaintained code (#836)
* 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
2018-01-25 18:20:14 -08:00
|
|
|
import numpy as np
|
2019-01-30 22:39:55 +01:00
|
|
|
from .space import Space
|
2016-08-14 16:18:28 -04:00
|
|
|
|
2019-01-30 22:39:55 +01:00
|
|
|
|
|
|
|
class MultiDiscrete(Space):
|
2019-03-11 10:58:48 -07:00
|
|
|
"""
|
2021-07-27 07:20:29 +02:00
|
|
|
- The multi-discrete action space consists of a series of discrete action spaces with different number of actions in each
|
2019-03-11 10:58:48 -07:00
|
|
|
- It is useful to represent game controllers or keyboards where each key can be represented as a discrete action space
|
|
|
|
- It is parametrized by passing an array of positive integers specifying number of actions for each discrete action space
|
|
|
|
|
2019-06-17 13:40:11 -07:00
|
|
|
Note: Some environment wrappers assume a value of 0 always represents the NOOP action.
|
2019-03-11 10:58:48 -07:00
|
|
|
|
|
|
|
e.g. Nintendo Game Controller
|
|
|
|
- Can be conceptualized as 3 discrete action spaces:
|
|
|
|
|
|
|
|
1) Arrow Keys: Discrete 5 - NOOP[0], UP[1], RIGHT[2], DOWN[3], LEFT[4] - params: min: 0, max: 4
|
|
|
|
2) Button A: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1
|
|
|
|
3) Button B: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1
|
|
|
|
|
|
|
|
- Can be initialized as
|
|
|
|
|
|
|
|
MultiDiscrete([ 5, 2, 2 ])
|
|
|
|
|
|
|
|
"""
|
2021-07-29 02:26:34 +02:00
|
|
|
|
2021-07-26 22:07:58 +02:00
|
|
|
def __init__(self, nvec, dtype=np.int64):
|
2019-06-17 13:40:11 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* 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
2018-01-25 18:20:14 -08:00
|
|
|
"""
|
|
|
|
nvec: vector of counts of each categorical variable
|
|
|
|
"""
|
2021-07-29 02:26:34 +02:00
|
|
|
assert (np.array(nvec) > 0).all(), "nvec (counts) have to be positive"
|
2021-07-26 22:07:58 +02:00
|
|
|
self.nvec = np.asarray(nvec, dtype=dtype)
|
2019-01-30 22:39:55 +01:00
|
|
|
|
2021-07-26 22:07:58 +02:00
|
|
|
super(MultiDiscrete, self).__init__(self.nvec.shape, dtype)
|
2018-09-24 20:11:03 +02:00
|
|
|
|
2016-08-14 16:18:28 -04:00
|
|
|
def sample(self):
|
2021-07-29 15:39:42 -04:00
|
|
|
return (self.np_random.random_sample(self.nvec.shape) * self.nvec).astype(
|
|
|
|
self.dtype
|
|
|
|
)
|
2018-09-24 20:11:03 +02:00
|
|
|
|
2016-08-14 16:18:28 -04:00
|
|
|
def contains(self, x):
|
2019-04-19 14:09:44 -07:00
|
|
|
if isinstance(x, list):
|
|
|
|
x = np.array(x) # Promote list to array for contains check
|
2018-12-05 15:54:49 -08:00
|
|
|
# if nvec is uint32 and space dtype is uint32, then 0 <= x < self.nvec guarantees that x
|
|
|
|
# is within correct bounds for space dtype (even though x does not have to be unsigned)
|
2019-11-08 23:19:02 +01:00
|
|
|
return x.shape == self.shape and (0 <= x).all() and (x < self.nvec).all()
|
2018-08-28 10:51:28 -07:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* 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
2018-01-25 18:20:14 -08:00
|
|
|
def to_jsonable(self, sample_n):
|
|
|
|
return [sample.tolist() for sample in sample_n]
|
2018-09-24 20:11:03 +02:00
|
|
|
|
Cleanup, removal of unmaintained code (#836)
* 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
2018-01-25 18:20:14 -08:00
|
|
|
def from_jsonable(self, sample_n):
|
|
|
|
return np.array(sample_n)
|
2018-09-24 20:11:03 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "MultiDiscrete({})".format(self.nvec)
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
2019-03-23 23:18:19 -07:00
|
|
|
return isinstance(other, MultiDiscrete) and np.all(self.nvec == other.nvec)
|