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

Function action_stats

numpy_ml/rl_models/rl_utils.py:334–379  ·  view source on GitHub ↗

Get information on `env`'s action space. Parameters ---------- md_action : bool Whether the `env`'s action space is multidimensional. cont_action : bool Whether the `env`'s action space is continuous. Returns ------- n_actions_per_dim : list of leng

(env, md_action, cont_action)

Source from the content-addressed store, hash-verified

332
333
334def action_stats(env, md_action, cont_action):
335 """
336 Get information on `env`'s action space.
337
338 Parameters
339 ----------
340 md_action : bool
341 Whether the `env`'s action space is multidimensional.
342 cont_action : bool
343 Whether the `env`'s action space is continuous.
344
345 Returns
346 -------
347 n_actions_per_dim : list of length (action_dim,)
348 The number of possible actions for each dimension of the action space.
349 action_ids : list or None
350 A list of all valid actions within the space. If `cont_action` is
351 True, this value will be None.
352 action_dim : int or None
353 The number of dimensions in a single action.
354 """
355 if cont_action:
356 action_dim = 1
357 action_ids = None
358 n_actions_per_dim = [np.inf]
359
360 if md_action:
361 action_dim = env.action_space.shape[0]
362 n_actions_per_dim = [np.inf for _ in range(action_dim)]
363 else:
364 if md_action:
365 n_actions_per_dim = [
366 space.n if hasattr(space, "n") else np.inf
367 for space in env.action_space.spaces
368 ]
369 action_ids = (
370 None
371 if np.inf in n_actions_per_dim
372 else list(product(*[range(i) for i in n_actions_per_dim]))
373 )
374 action_dim = len(n_actions_per_dim)
375 else:
376 action_dim = 1
377 n_actions_per_dim = [env.action_space.n]
378 action_ids = list(range(n_actions_per_dim[0]))
379 return n_actions_per_dim, action_ids, action_dim
380
381
382def obs_stats(env, md_obs, cont_obs):

Callers 1

env_statsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected