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)
| 332 | |
| 333 | |
| 334 | def 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 | |
| 382 | def obs_stats(env, md_obs, cont_obs): |