View source on GitHub |
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)
Returns | |
---|---|
clipped_t
|
A clipped Tensor .
|