tf_agents.bandits.multi_objective.multi_objective_scalarizer.HyperVolumeScalarizer
Stay organized with collections
Save and categorize content based on your preferences.
Implement the hypervolume scalarization.
Inherits From: Scalarizer
tf_agents.bandits.multi_objective.multi_objective_scalarizer.HyperVolumeScalarizer(
direction: Sequence[tf_agents.bandits.multi_objective.multi_objective_scalarizer.ScalarFloat
],
transform_params: Sequence[tf_agents.bandits.multi_objective.multi_objective_scalarizer.HyperVolumeScalarizer.PARAMS
],
multi_objective_transform: Optional[Callable[[tf.Tensor, Sequence[ScalarFloat], Sequence[ScalarFloat]],
tf.Tensor]] = None
)
Given a vector of (at least two) objectives M, a unit-length vector V with
non-negative coordinates, a slope vector A, and an offset vector B, all having
the same dimension, the hypervolume scalarization of M is defined as:
min_{i: V_i > 0} max(A_i * M_i + B_i, 0) / V_i.
See https://arxiv.org/abs/2006.04655 for more details.
Note that it is recommended for the user to set A_i and B_i in such a way to
ensure non-negativity of the transformed objectives.
Args |
direction
|
A Sequence representing a directional vector, which will be
normalized to have unit length. Coordinates of the normalized direction
whose absolute values are less than HyperVolumeScalarizer.ALMOST_ZERO
will be considered zeros.
|
transform_params
|
A Sequence of namedtuples
HyperVolumeScalarizer.PARAMS , each containing a slope and an offset
for transforming an objective to be non-negative.
|
multi_objective_transform
|
A Optional Callable that takes in a
tf.Tensor of multiple objective values, a Sequence of slopes, and a
Sequence of offsets, and returns a tf.Tensor of transformed multiple
objectives. If unset, the transform is defaulted to the standard
transform multiple_objectives * slopes + offsets.
|
Raises |
ValueError
|
if any([x < 0 for x in direction]) .
|
ValueError
|
if the 2-norm of direction is less than
HyperVolumeScalarizer.ALMOST_ZERO .
|
ValueError
|
if len(transform_params) != len(self._direction) .
|
Child Classes
class PARAMS
Methods
set_parameters
View source
set_parameters(
direction: tf.Tensor, transform_params: Dict[str, tf.Tensor]
)
Set the scalarization parameters for the HyperVolumeScalarizer.
Args |
direction
|
A tf.Tensor representing a directional vector, which will be
normalized to have unit length. Coordinates of the normalized direction
whose absolute values are less than HyperVolumeScalarizer.ALMOST_ZERO
will be considered zeros. It must be rank-2 and shaped as [batch_size,
self._num_of_objectives], where batch_size should match the batch size
of the multi objectives passed to the scalarizer call.
|
transform_params
|
A dictionary mapping self.SLOPE_KEY and/or
self.OFFSET_KEY to tf.Tensor , representing the slope and the offset
parameters for transforming an objective to be non-negative. These
tensors must satisfy the same rank and shape requirements as
direction .
|
Raises |
ValueError
|
if any input scalarization parameter tensor is not rank-2, or
has a last dimension size that does not match self._num_of_objectives .
|
__call__
View source
__call__(
multi_objectives: tf.Tensor
) -> tf.Tensor
Returns a single reward by scalarizing multiple objectives.
Args |
multi_objectives
|
A Tensor of shape [batch_size, number_of_objectives],
where each column represents an objective.
|
Returns: A Tensor
of shape [batch_size] representing scalarized rewards.
Raises |
ValueError
|
if multi_objectives.shape.rank != 2 .
|
ValueError
|
if
multi_objectives.shape.dims[1] != self._num_of_objectives .
|
Class Variables |
ALMOST_ZERO
|
1e-16
|
DIRECTION_KEY
|
'direction'
|
OFFSET_KEY
|
'offset'
|
SLOPE_KEY
|
'slope'
|
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf_agents.bandits.multi_objective.multi_objective_scalarizer.HyperVolumeScalarizer\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/multi_objective/multi_objective_scalarizer.py#L333-L488) |\n\nImplement the hypervolume scalarization.\n\nInherits From: [`Scalarizer`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/Scalarizer) \n\n tf_agents.bandits.multi_objective.multi_objective_scalarizer.HyperVolumeScalarizer(\n direction: Sequence[../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/ScalarFloat],\n transform_params: Sequence[../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer/PARAMS],\n multi_objective_transform: Optional[Callable[[tf.Tensor, Sequence[ScalarFloat], Sequence[ScalarFloat]],\n tf.Tensor]] = None\n )\n\nGiven a vector of (at least two) objectives M, a unit-length vector V with\nnon-negative coordinates, a slope vector A, and an offset vector B, all having\nthe same dimension, the hypervolume scalarization of M is defined as:\n\n`min_{i: V_i \u003e 0} max(A_i * M_i + B_i, 0) / V_i.`\n\nSee \u003chttps://arxiv.org/abs/2006.04655\u003e for more details.\nNote that it is recommended for the user to set A_i and B_i in such a way to\nensure non-negativity of the transformed objectives.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `direction` | A `Sequence` representing a directional vector, which will be normalized to have unit length. Coordinates of the normalized direction whose absolute values are less than [`HyperVolumeScalarizer.ALMOST_ZERO`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer#ALMOST_ZERO) will be considered zeros. |\n| `transform_params` | A `Sequence` of namedtuples [`HyperVolumeScalarizer.PARAMS`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer/PARAMS), each containing a slope and an offset for transforming an objective to be non-negative. |\n| `multi_objective_transform` | A `Optional` `Callable` that takes in a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of multiple objective values, a `Sequence` of slopes, and a `Sequence` of offsets, and returns a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of transformed multiple objectives. If unset, the transform is defaulted to the standard transform multiple_objectives \\* slopes + offsets. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | if `any([x \u003c 0 for x in direction])`. |\n| `ValueError` | if the 2-norm of `direction` is less than [`HyperVolumeScalarizer.ALMOST_ZERO`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer#ALMOST_ZERO). |\n| `ValueError` | if `len(transform_params) != len(self._direction)`. |\n\n\u003cbr /\u003e\n\nChild Classes\n-------------\n\n[`class PARAMS`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer/PARAMS)\n\nMethods\n-------\n\n### `set_parameters`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/multi_objective/multi_objective_scalarizer.py#L451-L488) \n\n set_parameters(\n direction: tf.Tensor, transform_params: Dict[str, tf.Tensor]\n )\n\nSet the scalarization parameters for the HyperVolumeScalarizer.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `direction` | A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) representing a directional vector, which will be normalized to have unit length. Coordinates of the normalized direction whose absolute values are less than [`HyperVolumeScalarizer.ALMOST_ZERO`](../../../../tf_agents/bandits/multi_objective/multi_objective_scalarizer/HyperVolumeScalarizer#ALMOST_ZERO) will be considered zeros. It must be rank-2 and shaped as \\[batch_size, self._num_of_objectives\\], where `batch_size` should match the batch size of the multi objectives passed to the scalarizer call. |\n| `transform_params` | A dictionary mapping `self.SLOPE_KEY` and/or `self.OFFSET_KEY` to [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor), representing the slope and the offset parameters for transforming an objective to be non-negative. These tensors must satisfy the same rank and shape requirements as `direction`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | if any input scalarization parameter tensor is not rank-2, or has a last dimension size that does not match `self._num_of_objectives`. |\n\n\u003cbr /\u003e\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/bandits/multi_objective/multi_objective_scalarizer.py#L135-L161) \n\n __call__(\n multi_objectives: tf.Tensor\n ) -\u003e tf.Tensor\n\nReturns a single reward by scalarizing multiple objectives.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------|------------------------------------------------------------------------------------------------------|\n| `multi_objectives` | A `Tensor` of shape \\[batch_size, number_of_objectives\\], where each column represents an objective. |\n\n\u003cbr /\u003e\n\nReturns: A `Tensor` of shape \\[batch_size\\] representing scalarized rewards.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|-----------------------------------------------------------------|\n| `ValueError` | if `multi_objectives.shape.rank != 2`. |\n| `ValueError` | if `multi_objectives.shape.dims[1] != self._num_of_objectives`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Class Variables --------------- ||\n|---------------|---------------|\n| ALMOST_ZERO | `1e-16` |\n| DIRECTION_KEY | `'direction'` |\n| OFFSET_KEY | `'offset'` |\n| SLOPE_KEY | `'slope'` |\n\n\u003cbr /\u003e"]]