class_docstr: The DiscretizeActionsWrapper provides functionality for discretizing individual continuous actions into discrete
   ones.
  
  An example is given by having a continuous action called 'action_up' with space:
  gym.spaces.Box(shape=(5,), low=[-1,-1,-1,-1,-1], high=[1,1,1,1,1]
  
  discretization_config:
      action_up:
          num_bins: 5
          low: [-1, 0, 0.5, 0, 0]
          high: 1
  
  Now the action space will be split where each of the 5 continuous values of the box spaces are split evenly within
  the ranges of (-1,1),(0,1),(0.5,1), (0,1), (0,1) respectively.
  
  :param env: Environment/wrapper to wrap.
  :param discretization_config: The action discretization configuration.
class_docstr_tok: ["The","DiscretizeActionsWrapper","provides","functionality","for","discretizing","individual","continuous","actions","into","discrete","ones",".","An","example","is","given","by","having","a","continuous","action","called","'action_up","'","with","space",":","gym.spaces.Box","(","shape=","(","5",",",")",",","low=","[","-1",",","-1",",","-1",",","-1",",","-1","]",",","high=","[","1,1,1,1,1","]","discretization_config",":","action_up",":","num_bins",":","5","low",":","[","-1",",","0",",","0.5",",","0",",","0","]","high",":","1","Now","the","action","space","will","be","split","where","each","of","the","5","continuous","values","of","the","box","spaces","are","split","evenly","within","the","ranges","of","(","-1,1",")",",","(","0,1",")",",","(","0.5,1",")",",","(","0,1",")",",","(","0,1",")","respectively",".",":","param","env",":","Environment\/wrapper","to","wrap",".",":","param","discretization_config",":","The","action","discretization","configuration","."]
docstr: Discretize a single action space (dict) into the corresponding sub actions spaces w.r.t. the split config
  
  :param action_space: The action space to split.
  :return: The resulting (split) action space.
docstr_tok: ["Discretize","a","single","action","space","(","dict",")","into","the","corresponding","sub","actions","spaces","w.r.t",".","the","split","config",":","param","action_space",":","The","action","space","to","split",".",":","return",":","The","resulting","(","split",")","action","space","."]
code: def _discretize_action_space(
      self, action_space: gym.spaces.Dict
  ) -> gym.spaces.Dict:
      """Discretize a single action space (dict) into the corresponding sub actions spaces w.r.t. the split config
  
      :param action_space: The action space to split.
      :return: The resulting (split) action space.
      """
      new_action_space = dict()
      for (
          org_action_name,
          org_action_space,
      ) in action_space.spaces.items():
          if org_action_name in self.discretization_config:
              dis_config = self.discretization_config[org_action_name]
              if "low" in dis_config:
                  low = dis_config["low"]
                  if isinstance(dis_config["low"], (float, int)):
                      low = np.array(
                          [dis_config["low"]]
                          * org_action_space.low.shape[-1]
                      )
                  high = dis_config["high"]
                  if isinstance(dis_config["high"], (float, int)):
                      high = np.array(
                          [dis_config["high"]]
                          * org_action_space.high.shape[-1]
                      )
              else:
                  low = org_action_space.low
                  high = org_action_space.high
              bounds = np.linspace(
                  start=low, stop=high, num=dis_config["num_bins"] + 1
              )
              self._bins[org_action_name] = bounds[1:]
              self._avgs[org_action_name] = np.array(
                  list(zip(bounds, bounds[1:])), dtype=np.float32
              ).mean(axis=1)
              assert (
                  self._bins[org_action_name].shape
                  == self._avgs[org_action_name].shape
              )
              if org_action_space.shape[-1] == 1:
                  new_action_space[
                      org_action_name
                  ] = gym.spaces.Discrete(n=dis_config["num_bins"])
              else:
                  nvec = np.array(
                      [dis_config["num_bins"]]
                      * org_action_space.shape[-1]
                  )
                  new_action_space[
                      org_action_name
                  ] = gym.spaces.MultiDiscrete(nvec=nvec)
          else:
              new_action_space[org_action_name] = org_action_space
      return gym.spaces.Dict(new_action_space)
  
file_path: maze/maze/core/wrappers/discretize_actions_wrapper.py
imports: from typing import Union, Dict, List
  import gym
  import numpy
  from maze.core.annotations import override
  from maze.core.env.simulated_env_mixin import SimulatedEnvMixin
  from maze.core.env.structured_env import StructuredEnv
  from maze.core.env.structured_env_spaces_mixin import StructuredEnvSpacesMixin
  from maze.core.utils.structured_env_utils import flat_structured_space
  from maze.core.wrappers.wrapper import ActionWrapper, EnvType
label_desc: Use image node_id 3 for calling the DiscretizeActionsWrapper obj's underlying member method code with example usage: obj._discretize_action_space(action_space) and returns: gym