softshrink#

ivy.softshrink(x, /, *, lambd=0.5, out=None)[source]#

Apply the softshrink function element-wise.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • lambd (float, default: 0.5) – the value of the lower bound of the linear region range.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the softshrink activation of each element in x.

Examples

With ivy.Array input: >>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = ivy.softshrink(x) >>> print(y) ivy.array([-0.5, 0.5, 1.5])

>>> x = ivy.array([-1.0, 1.0, 2.0])
>>> y = x.softshrink()
>>> print(y)
ivy.array([-0.5,  0.5,  1.5])
>>> x = ivy.array([[-1.3, 3.8, 2.1], [1.7, 4.2, -6.6]])
>>> y = ivy.softshrink(x)
>>> print(y)
ivy.array([[-0.79999995,  3.29999995,  1.59999991],
   [ 1.20000005,  3.69999981, -6.0999999 ]])
Array.softshrink(self, /, *, lambd=0.5, out=None)[source]#

ivy.Array instance method variant of ivy.softshrink. This method simply wraps the function, and so the docstring for ivy.softshrink also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array.

  • lambd (float, default: 0.5) – the value of the lower bound of the linear region range.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array with the softshrink activation function applied element-wise.

Examples

>>> x = ivy.array([-1., 0., 1.])
>>> y = x.softshrink()
>>> print(y)
ivy.array([-0.5,  0. ,  0.5])
>>> x = ivy.array([-1., 0., 1.])
>>> y = x.softshrink(lambd=1.0)
>>> print(y)
ivy.array([0., 0., 0.])
Container.softshrink(self, /, *, lambd=0.5, key_chains=None, to_apply=False, prune_unapplied=True, map_sequences=False, out=None)[source]#

Apply the soft shrinkage function element-wise.

Parameters:
  • self (Container) – Input container.

  • lambd (Container, default: 0.5) – Lambda value for soft shrinkage calculation.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to.

  • to_apply (Union[bool, Container], default: False) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped.

  • prune_unapplied (Union[bool, Container], default: True) – Whether to prune key_chains for which the function was not applied.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples).

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – Container with soft shrinkage applied to the leaves.

Examples

>>> import ivy.numpy as np
>>> x = ivy.Container(a=np.array([1., -2.]), b=np.array([0.4, -0.2]))
>>> y = ivy.Container.softshrink(x)
>>> print(y)
{
    a: ivy.array([0.5, -1.5]),
    b: ivy.array([0., 0.])
}