tf_agents.specs.BoundedArraySpec
Stay organized with collections
Save and categorize content based on your preferences.
An ArraySpec
that specifies minimum and maximum values.
Inherits From: ArraySpec
tf_agents.specs.BoundedArraySpec(
shape, dtype, minimum=None, maximum=None, name=None
)
Used in the notebooks
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 .
|
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.
|
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.
|
num_values
|
Returns the number of values for discrete BoundedArraySpec.
|
shape
|
Returns a tuple specifying the array shape.
|
Methods
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(
spec, name=None
)
Construct a spec from the given spec.
replace
View source
replace(
shape=None, dtype=None, minimum=None, maximum=None, name=None
)
__eq__
View source
__eq__(
other
)
Checks if the shape and dtype of two specs are equal.
__ne__
View source
__ne__(
other
)
Return self!=value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf_agents.specs.BoundedArraySpec\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L270-L458) |\n\nAn `ArraySpec` that specifies minimum and maximum values.\n\nInherits From: [`ArraySpec`](../../tf_agents/specs/ArraySpec)\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf_agents.specs.array_spec.BoundedArraySpec`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/specs/BoundedArraySpec)\n\n\u003cbr /\u003e\n\n tf_agents.specs.BoundedArraySpec(\n shape, dtype, minimum=None, maximum=None, name=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Tutorial on Multi Armed Bandits in TF-Agents](https://www.tensorflow.org/agents/tutorials/bandits_tutorial) - [Networks](https://www.tensorflow.org/agents/tutorials/8_networks_tutorial) - [Environments](https://www.tensorflow.org/agents/tutorials/2_environments_tutorial) - [Policies](https://www.tensorflow.org/agents/tutorials/3_policies_tutorial) |\n\n#### Example usage:\n\n # Specifying the same minimum and maximum for every element.\n spec = BoundedArraySpec((3, 4), np.float64, minimum=0.0, maximum=1.0)\n\n # Specifying a different minimum and maximum for each element.\n spec = BoundedArraySpec(\n (2,), np.float64, minimum=[0.1, 0.2], maximum=[0.9, 0.9])\n\n # Specifying the same minimum and a different maximum for each element.\n spec = BoundedArraySpec(\n (3,), np.float64, minimum=-10.0, maximum=[4.0, 5.0, 3.0])\n\nBounds are meant to be inclusive. This is especially important for\ninteger types. The following spec will be satisfied by arrays\nwith values in the set {0, 1, 2}: \n\n spec = BoundedArraySpec((3, 4), np.int, minimum=0, maximum=2)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|---------------------------------------------------------------------------------------------------------|\n| `shape` | An iterable specifying the array shape. |\n| `dtype` | numpy dtype or string specifying the array dtype. |\n| `minimum` | Number or sequence specifying the maximum element bounds (inclusive). Must be broadcastable to `shape`. |\n| `maximum` | Number or sequence specifying the maximum element bounds (inclusive). Must be broadcastable to `shape`. |\n| `name` | Optional string containing a semantic name for the corresponding array. Defaults to `None`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `minimum` or `maximum` are not broadcastable to `shape` or if the limits are outside of the range of the specified dtype. |\n| `TypeError` | If the shape is not an iterable or if the `dtype` is an invalid numpy dtype. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------------|------------------------------------------------------------------|\n| `dtype` | Returns a numpy dtype specifying the array dtype. |\n| `maximum` | Returns a NumPy array specifying the maximum bounds (inclusive). |\n| `minimum` | Returns a NumPy array specifying the minimum bounds (inclusive). |\n| `name` | Returns the name of the ArraySpec. |\n| `num_values` | Returns the number of values for discrete BoundedArraySpec. |\n| `shape` | Returns a `tuple` specifying the array shape. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `check_array`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L436-L442) \n\n check_array(\n array\n )\n\nReturn true if the given array conforms to the spec.\n\n### `from_array`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L248-L256) \n\n @staticmethod\n from_array(\n array, name=None\n )\n\nConstruct a spec from the given array or number.\n\n### `from_spec`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L383-L393) \n\n @classmethod\n from_spec(\n spec, name=None\n )\n\nConstruct a spec from the given spec.\n\n### `replace`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L444-L452) \n\n replace(\n shape=None, dtype=None, minimum=None, maximum=None, name=None\n )\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L427-L434) \n\n __eq__(\n other\n )\n\nChecks if the shape and dtype of two specs are equal.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L224-L225) \n\n __ne__(\n other\n )\n\nReturn self!=value."]]