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

Function is_continuous

numpy_ml/rl_models/rl_utils.py:297–331  ·  view source on GitHub ↗

Check if an `env`'s observation and action spaces are continuous. Parameters ---------- env : ``gym.wrappers`` or ``gym.envs`` instance The environment to evaluate. tuple_action : bool Whether the `env`'s action space is an instance of `gym.spaces.Tuple`

(env, tuple_action, tuple_obs)

Source from the content-addressed store, hash-verified

295
296
297def is_continuous(env, tuple_action, tuple_obs):
298 """
299 Check if an `env`'s observation and action spaces are continuous.
300
301 Parameters
302 ----------
303 env : ``gym.wrappers`` or ``gym.envs`` instance
304 The environment to evaluate.
305 tuple_action : bool
306 Whether the `env`'s action space is an instance of `gym.spaces.Tuple`
307 or `gym.spaces.Dict`.
308 tuple_obs : bool
309 Whether the `env`'s observation space is an instance of `gym.spaces.Tuple`
310 or `gym.spaces.Dict`.
311
312 Returns
313 -------
314 cont_action : bool
315 Whether the `env`'s action space is continuous.
316 cont_obs : bool
317 Whether the `env`'s observation space is continuous.
318 """
319 Continuous = gym.spaces.box.Box
320 if tuple_obs:
321 spaces = env.observation_space.spaces
322 cont_obs = all(isinstance(s, Continuous) for s in spaces)
323 else:
324 cont_obs = isinstance(env.observation_space, Continuous)
325
326 if tuple_action:
327 spaces = env.action_space.spaces
328 cont_action = all(isinstance(s, Continuous) for s in spaces)
329 else:
330 cont_action = isinstance(env.action_space, Continuous)
331 return cont_action, cont_obs
332
333
334def action_stats(env, md_action, cont_action):

Callers 1

env_statsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected