MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / is_multidimensional

Function is_multidimensional

numpy_ml/rl_models/rl_utils.py:257–294  ·  view source on GitHub ↗

Check if the action and observation spaces for `env` are multidimensional or ``Tuple`` spaces. Notes ----- A multidimensional space is any space whose actions / observations have more than one element in them. This includes ``Tuple`` spaces, but also includes single act

(env)

Source from the content-addressed store, hash-verified

255
256
257def is_multidimensional(env):
258 """
259 Check if the action and observation spaces for `env` are multidimensional
260 or ``Tuple`` spaces.
261
262 Notes
263 -----
264 A multidimensional space is any space whose actions / observations have
265 more than one element in them. This includes ``Tuple`` spaces, but also
266 includes single action/observation spaces with several dimensions.
267
268 Parameters
269 ----------
270 env : ``gym.wrappers`` or ``gym.envs`` instance
271 The environment to evaluate.
272
273 Returns
274 -------
275 md_action : bool
276 Whether the `env`'s action space is multidimensional.
277 md_obs : bool
278 Whether the `env`'s observation space is multidimensional.
279 tuple_action : bool
280 Whether the `env`'s action space is a ``Tuple`` instance.
281 tuple_obs : bool
282 Whether the `env`'s observation space is a ``Tuple`` instance.
283 """
284 md_action, md_obs = True, True
285 tuple_action, tuple_obs = is_tuple(env)
286 if not tuple_action:
287 act = env.action_space.sample()
288 md_action = isinstance(act, (list, tuple, np.ndarray)) and len(act) > 1
289
290 if not tuple_obs:
291 OS = env.observation_space
292 obs = OS.low if "low" in dir(OS) else OS.sample() # sample causes problems
293 md_obs = isinstance(obs, (list, tuple, np.ndarray)) and len(obs) > 1
294 return md_action, md_obs, tuple_action, tuple_obs
295
296
297def is_continuous(env, tuple_action, tuple_obs):

Callers 1

env_statsFunction · 0.85

Calls 2

is_tupleFunction · 0.85
sampleMethod · 0.45

Tested by

no test coverage detected