tf_agents.distributions.utils.Params
Stay organized with collections
Save and categorize content based on your preferences.
The (recursive) parameters of objects exposing the parameters
property.
tf_agents.distributions.utils.Params(
type_, params
)
This includes TFP Distribution
, Bijector
, and TF LinearOperator
.
Params
objects are created with
tf_agents.distributions.utils.get_parameters
;
Params
can be converted back to original objects via
tf_agents.distributions.utils.make_from_parameters
.
In-place edits of fields are allowed, and will not modify the original
objects (with the exception of, e.g., reference objects like tf.Variable
being modified in-place).
The components of a Params
object are: type_
and params
.
type_
is the type of object.
params
is a dict
of the (non-default) non-tensor arguments passed to the
object's __init__
; and includes nests of Python objects, as well as other
Params
values representing "Param-representable" objects passed to init.
A non-trivial example:
scale_matrix = tf.Variable([[1.0, 2.0], [-1.0, 0.0]])
d = tfp.distributions.MultivariateNormalDiag(
loc=[1.0, 1.0], scale_diag=[2.0, 3.0], validate_args=True)
b = tfp.bijectors.ScaleMatvecLinearOperator(
scale=tf.linalg.LinearOperatorFullMatrix(matrix=scale_matrix),
adjoint=True)
b_d = b(d)
p = utils.get_parameters(b_d)
Then p
is:
Params(
tfp.distributions.TransformedDistribution,
params={
"bijector": Params(
tfp.bijectors.ScaleMatvecLinearOperator,
params={"adjoint": True,
"scale": Params(
tf.linalg.LinearOperatorFullMatrix,
params={"matrix": scale_matrix})}),
"distribution": Params(
tfp.distributions.MultivariateNormalDiag,
params={"validate_args": True,
"scale_diag": [2.0, 3.0],
"loc": [1.0, 1.0]})})
This structure can be manipulated and/or converted back to a Distribution
instance via make_from_parameters
:
p.params["distribution"].params["loc"] = [0.0, 0.0]
# The distribution `new_b_d` will be a MVN centered on `(0, 0)` passed through
# the `ScaleMatvecLinearOperator` bijector.
new_b_d = utils.make_from_parameters(p)
Methods
__eq__
View source
__eq__(
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.
[[["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.distributions.utils.Params\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/distributions/utils.py#L187-L270) |\n\nThe (recursive) parameters of objects exposing the `parameters` property. \n\n tf_agents.distributions.utils.Params(\n type_, params\n )\n\nThis includes TFP `Distribution`, `Bijector`, and TF `LinearOperator`.\n\n`Params` objects are created with\n[`tf_agents.distributions.utils.get_parameters`](../../../tf_agents/distributions/utils/get_parameters);\n`Params` can be converted back to original objects via\n[`tf_agents.distributions.utils.make_from_parameters`](../../../tf_agents/distributions/utils/make_from_parameters).\n\nIn-place edits of fields are allowed, and will not modify the original\nobjects (with the exception of, e.g., reference objects like [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable)\nbeing modified in-place).\n\nThe components of a `Params` object are: `type_` and `params`.\n\n- `type_` is the type of object.\n- `params` is a `dict` of the (non-default) non-tensor arguments passed to the object's `__init__`; and includes nests of Python objects, as well as other `Params` values representing \"Param-representable\" objects passed to init.\n\nA non-trivial example: \n\n scale_matrix = tf.Variable([[1.0, 2.0], [-1.0, 0.0]])\n d = tfp.distributions.MultivariateNormalDiag(\n loc=[1.0, 1.0], scale_diag=[2.0, 3.0], validate_args=True)\n b = tfp.bijectors.ScaleMatvecLinearOperator(\n scale=tf.linalg.LinearOperatorFullMatrix(matrix=scale_matrix),\n adjoint=True)\n b_d = b(d)\n p = utils.get_parameters(b_d)\n\nThen `p` is: \n\n Params(\n tfp.distributions.TransformedDistribution,\n params={\n \"bijector\": Params(\n tfp.bijectors.ScaleMatvecLinearOperator,\n params={\"adjoint\": True,\n \"scale\": Params(\n tf.linalg.LinearOperatorFullMatrix,\n params={\"matrix\": scale_matrix})}),\n \"distribution\": Params(\n tfp.distributions.MultivariateNormalDiag,\n params={\"validate_args\": True,\n \"scale_diag\": [2.0, 3.0],\n \"loc\": [1.0, 1.0]})})\n\nThis structure can be manipulated and/or converted back to a `Distribution`\ninstance via `make_from_parameters`: \n\n p.params[\"distribution\"].params[\"loc\"] = [0.0, 0.0]\n\n # The distribution `new_b_d` will be a MVN centered on `(0, 0)` passed through\n # the `ScaleMatvecLinearOperator` bijector.\n new_b_d = utils.make_from_parameters(p)\n\nMethods\n-------\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/distributions/utils.py#L261-L266) \n\n __eq__(\n other\n )\n\nReturn self==value."]]