tfp.math.clip_by_value_preserve_gradient
Stay organized with collections
Save and categorize content based on your preferences.
Clips values to a specified min and max while leaving gradient unaltered.
tfp . math . clip_by_value_preserve_gradient (
t , clip_value_min , clip_value_max , name = None
)
Like tf.clip_by_value
, this function returns a tensor of the same type and
shape as input t
but with values clamped to be no smaller than to
clip_value_min
and no larger than clip_value_max
. Unlike
tf.clip_by_value
, the gradient is unaffected by this op, i.e.,
tf . gradients ( tfp . math . clip_by_value_preserve_gradient ( x ), x )[ 0 ]
# ==> ones_like(x)
Note: clip_value_min
needs to be smaller or equal to clip_value_max
for
correct results.
Args
t
A Tensor
.
clip_value_min
A scalar Tensor
, or a Tensor
with the same shape
as t
. The minimum value to clip by.
clip_value_max
A scalar Tensor
, or a Tensor
with the same shape
as t
. The maximum value to clip by.
name
A name for the operation (optional).
Default value: 'clip_by_value_preserve_gradient'
.
Returns
clipped_t
A clipped Tensor
.
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 2023-11-21 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2023-11-21 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 2023-11-21 UTC."],[],[]]