(self, env, minimum, maximum)
Initializes a new action scale Wrapper.

    Args:
      env: Instance of `dm_env.Environment` to wrap. Its `action_spec` must
        consist of a single `BoundedArray` with all-finite bounds.
      minimum: Scalar or array-like specifying element-wise lower bounds
        (inclusive) for the `action_spec` of the wrapped environment. Must be
        finite and broadcastable to the shape of the `action_spec`.
      maximum: Scalar or array-like specifying element-wise upper bounds
        (inclusive) for the `action_spec` of the wrapped environment. Must be
        finite and broadcastable to the shape of the `action_spec`.

    Raises:
      ValueError: If `env.action_spec()` is not a single `BoundedArray`.
      ValueError: If `env.action_spec()` has non-finite bounds.
      ValueError: If `minimum` or `maximum` contain non-finite values.
      ValueError: If `minimum` or `maximum` are not broadcastable to
        `env.action_spec().shape`.
Initializes a new action scale Wrapper.
Initializes a new action scale Wrapper .
def __init__(self, env, minimum, maximum):
    """Initializes a new action scale Wrapper.

    Args:
      env: Instance of `dm_env.Environment` to wrap. Its `action_spec` must
        consist of a single `BoundedArray` with all-finite bounds.
      minimum: Scalar or array-like specifying element-wise lower bounds
        (inclusive) for the `action_spec` of the wrapped environment. Must be
        finite and broadcastable to the shape of the `action_spec`.
      maximum: Scalar or array-like specifying element-wise upper bounds
        (inclusive) for the `action_spec` of the wrapped environment. Must be
        finite and broadcastable to the shape of the `action_spec`.

    Raises:
      ValueError: If `env.action_spec()` is not a single `BoundedArray`.
      ValueError: If `env.action_spec()` has non-finite bounds.
      ValueError: If `minimum` or `maximum` contain non-finite values.
      ValueError: If `minimum` or `maximum` are not broadcastable to
        `env.action_spec().shape`.
    """
    action_spec = env.action_spec()
    if not isinstance(action_spec, specs.BoundedArray):
      raise ValueError(_ACTION_SPEC_MUST_BE_BOUNDED_ARRAY.format(action_spec))

    minimum = np.array(minimum)
    maximum = np.array(maximum)
    shape = action_spec.shape
    orig_minimum = action_spec.minimum
    orig_maximum = action_spec.maximum
    orig_dtype = action_spec.dtype

    def validate(bounds, name):
      if not np.all(np.isfinite(bounds)):
        raise ValueError(_MUST_BE_FINITE.format(name=name, bounds=bounds))
      try:
        np.broadcast_to(bounds, shape)
      except ValueError:
        raise ValueError(_MUST_BROADCAST.format(
            name=name, bounds=bounds, shape=shape))

    validate(minimum, "minimum")
    validate(maximum, "maximum")
    validate(orig_minimum, "env.action_spec().minimum")
    validate(orig_maximum, "env.action_spec().maximum")

    scale = (orig_maximum - orig_minimum) / (maximum - minimum)

    def transform(action):
      new_action = orig_minimum + scale * (action - minimum)
      return new_action.astype(orig_dtype, copy=False)

    dtype = np.result_type(minimum, maximum, orig_dtype)
    self._action_spec = action_spec.replace(
        minimum=minimum, maximum=maximum, dtype=dtype)
    self._env = env
    self._transform = transform
def __init__ ( self , env , minimum , maximum ) : action_spec = env . action_spec ( ) if not isinstance ( action_spec , specs . BoundedArray ) : raise ValueError ( _ACTION_SPEC_MUST_BE_BOUNDED_ARRAY . format ( action_spec ) ) minimum = np . array ( minimum ) maximum = np . array ( maximum ) shape = action_spec . shape orig_minimum = action_spec . minimum orig_maximum = action_spec . maximum orig_dtype = action_spec . dtype def validate ( bounds , name ) : if not np . all ( np . isfinite ( bounds ) ) : raise ValueError ( _MUST_BE_FINITE . format ( name = name , bounds = bounds ) ) try : np . broadcast_to ( bounds , shape ) except ValueError : raise ValueError ( _MUST_BROADCAST . format ( name = name , bounds = bounds , shape = shape ) ) validate ( minimum , "minimum" ) validate ( maximum , "maximum" ) validate ( orig_minimum , "env.action_spec().minimum" ) validate ( orig_maximum , "env.action_spec().maximum" ) scale = ( orig_maximum - orig_minimum ) / ( maximum - minimum ) def transform ( action ) : new_action = orig_minimum + scale * ( action - minimum ) return new_action . astype ( orig_dtype , copy = False ) dtype = np . result_type ( minimum , maximum , orig_dtype ) self . _action_spec = action_spec . replace ( minimum = minimum , maximum = maximum , dtype = dtype ) self . _env = env self . _transform = transform