hardshrink#
- ivy.hardshrink(x, /, *, lambd=0.5, out=None)[source]#
Apply the hardshrink function element-wise.
- Parameters:
- Return type:
- Returns:
ret – an array containing the hardshrink activation of each element in
x.
Examples
With
ivy.Arrayinput: >>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = ivy.hardshrink(x) >>> print(y) ivy.array([-1., 1., 2.]) >>> x = ivy.array([-1.0, 1.0, 2.0]) >>> y = x.hardshrink() >>> print(y) ivy.array([-1., 1., 2.]) >>> x = ivy.array([[-1.3, 3.8, 2.1], [1.7, 4.2, -6.6]]) >>> y = ivy.hardshrink(x) >>> print(y) ivy.array([[-1.29999995, 3.79999995, 2.0999999 ],[ 1.70000005, 4.19999981, -6.5999999 ]])
- Array.hardshrink(self, /, *, lambd=0.5, out=None)[source]#
ivy.Array instance method variant of ivy.hardshrink. This method simply wraps the function, and so the docstring for ivy.hardshrink also applies to this method with minimal changes.
- Parameters:
self (
Array) – input array.lambd (
float, default:0.5) – the lambd value for the Hardshrink formulationout (
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 hardshrink activation function applied element-wise.
Examples
>>> x = ivy.array([-1., 0., 1.]) >>> y = x.hardshrink() >>> print(y) ivy.array([-1., 0., 1.]) >>> x = ivy.array([-1., 0., 1.]) >>> y = x.hardshrink(lambd=1.0) >>> print(y) ivy.array([0., 0., 0.])
- Container.hardshrink(self, /, *, lambd=0.5, key_chains=None, to_apply=False, prune_unapplied=True, map_sequences=False, out=None)[source]#
Apply the hard shrinkage function element-wise.
- Parameters:
self (
Container) – Input container.lambd (
Container, default:0.5) – Lambda value for hard 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 hard shrinkage applied to the leaves.
Examples
>>> x = ivy.Container(a=ivy.array([1., -2.]), b=ivy.array([0.4, -0.2])) >>> y = ivy.Container.hardshrink(x) >>> print(y) { a: ivy.array([1., -2.]), b: ivy.array([0., 0.]) }