soft_thresholding#
- ivy.soft_thresholding(x, /, threshold, *, out=None)[source]#
Soft-thresholding operator.
sign(tensor) * max[abs(tensor) - threshold, 0]
- Parameters:
x (
Union
[Array
,NativeArray
]) – input arraythreshold (
Union
[float
,Array
,NativeArray
]) – float or array with shape tensor.shape * If float the threshold is applied to the whole tensor * If array, one threshold is applied per elements, 0 values are ignoredout (
Optional
[Array
], default:None
) – optional output array, for writing the result to.
- Return type:
- Returns:
ivy.Array – thresholded tensor on which the operator has been applied
Examples
Basic shrinkage
>>> x = ivy.array([[1, -2, 1.5], [-4, 3, -0.5]]) >>> soft_thresholding(x, 1.1) array([[ 0. , -0.9, 0.4], [-2.9, 1.9, 0. ]])
Example with missing values
>>> mask = ivy.array([[0, 0, 1], [1, 0, 1]]) >>> soft_thresholding(x, mask*1.1) array([[ 1. , -2. , 0.4], [-2.9, 3. , 0. ]])
- Array.soft_thresholding(self, /, threshold, *, out=None)[source]#
ivy.Array instance method variant of ivy.soft_thresholding. This method simply wraps the function, and so the docstring for ivy.soft_thresholding also applies to this method with minimal changes.
- Parameters:
x – input array
threshold (
Union
[float
,Array
,NativeArray
]) – float or array with shape tensor.shape * If float the threshold is applied to the whole tensor * If array, one threshold is applied per elements, 0 values are ignoredout (
Optional
[Array
], default:None
) – optional output array, for writing the result to.
- Return type:
Array
- Returns:
ivy.Array – thresholded tensor on which the operator has been applied
- Container.soft_thresholding(self, /, threshold, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.soft_thresholding.
This method simply wraps the function, and so the docstring for ivy.soft_thresholding also applies to this method with minimal changes.
- Parameters:
x – the input tensor
threshold (
Union
[float
,Array
,NativeArray
,Container
]) – float or array with shape tensor.shape * If float the threshold is applied to the whole tensor * If array, one threshold is applied per elements, 0 values are ignoredout (
Optional
[Container
], default:None
) – optional output array, for writing the result to.
- Return type:
Container
- Returns:
ivy.Container – thresholded tensor on which the operator has been applied