Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tf_agents.specs.BoundedArraySpec

View source on GitHub

An ArraySpec that specifies minimum and maximum values.

Inherits From: ArraySpec

tf_agents.specs.BoundedArraySpec(
    *args, **kwargs
)

Used in the notebooks

Used in the tutorials

Example usage:

# Specifying the same minimum and maximum for every element.
spec = BoundedArraySpec((3, 4), np.float64, minimum=0.0, maximum=1.0)

# Specifying a different minimum and maximum for each element.
spec = BoundedArraySpec(
    (2,), np.float64, minimum=[0.1, 0.2], maximum=[0.9, 0.9])

# Specifying the same minimum and a different maximum for each element.
spec = BoundedArraySpec(
    (3,), np.float64, minimum=-10.0, maximum=[4.0, 5.0, 3.0])

Bounds are meant to be inclusive. This is especially important for integer types. The following spec will be satisfied by arrays with values in the set {0, 1, 2}:

spec = BoundedArraySpec((3, 4), np.int, minimum=0, maximum=2)

Args:

  • shape: An iterable specifying the array shape.
  • dtype: numpy dtype or string specifying the array dtype.
  • minimum: Number or sequence specifying the maximum element bounds (inclusive). Must be broadcastable to shape.
  • maximum: Number or sequence specifying the maximum element bounds (inclusive). Must be broadcastable to shape.
  • name: Optional string containing a semantic name for the corresponding array. Defaults to None.

Attributes:

  • dtype: Returns a numpy dtype specifying the array dtype.
  • maximum: Returns a NumPy array specifying the maximum bounds (inclusive).
  • minimum: Returns a NumPy array specifying the minimum bounds (inclusive).
  • name: Returns the name of the ArraySpec.
  • shape: Returns a tuple specifying the array shape.

Raises:

  • ValueError: If minimum or maximum are not broadcastable to shape or if the limits are outside of the range of the specified dtype.
  • TypeError: If the shape is not an iterable or if the dtype is an invalid numpy dtype.

Methods

__eq__

View source

__eq__(
    other
)

Checks if the shape and dtype of two specs are equal.

__ne__

View source

__ne__(
    other
)

Return self!=value.

check_array

View source

check_array(
    array
)

Return true if the given array conforms to the spec.

from_array

View source

@staticmethod
from_array(
    array, name=None
)

Construct a spec from the given array or number.

from_spec

View source

@classmethod
from_spec(
    cls, spec, name=None
)

Construct a spec from the given spec.