softplus#
- ivy.softplus(x, /, *, beta=None, threshold=None, out=None)[source]#
Apply the softplus function element-wise.
- Parameters:
x (
Union
[Array
,NativeArray
]) – input array.beta (
Optional
[Union
[int
,float
]]) – The beta value for the softplus formation. Default:None
. (default:None
)threshold (
Optional
[Union
[int
,float
]]) – values above this revert to a linear function. Default:None
. (default:None
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that the (default:None
) inputs broadcast to.
- Return type:
- Returns:
ret – an array containing the softplus activation of each element in
x
.
Functional Examples
With
ivy.Array
input:>>> x = ivy.array([-0.3461, -0.6491]) >>> y = ivy.softplus(x) >>> print(y) ivy.array([0.535,0.42])
>>> x = ivy.array([-0.3461, -0.6491]) >>> y = ivy.softplus(x, beta=0.5) >>> print(y) ivy.array([1.22, 1.09])
>>> x = ivy.array([1., 2., 3.]) >>> y = ivy.softplus(x, threshold=2) >>> print(y) ivy.array([1.31, 2.13, 3. ])
- Array.softplus(self, /, *, beta=None, threshold=None, out=None)#
ivy.Array instance method variant of ivy.softplus. This method simply wraps the function, and so the docstring for ivy.softplus also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.beta (
Optional
[Union
[int
,float
]]) – the beta parameter of the softplus function. (default:None
)threshold (
Optional
[Union
[int
,float
]]) – the threshold parameter of the softplus function. (default:None
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape (default:None
)
- Return type:
Array
- Returns:
ret – an array with the softplus activation function applied element-wise.
Examples
>>> x = ivy.array([-0.3461, -0.6491]) >>> y = x.softplus() >>> print(y) ivy.array([0.535,0.42])
>>> x = ivy.array([-0.3461, -0.6491]) >>> y = x.softplus(beta=0.5) >>> print(y) ivy.array([1.22, 1.09])
>>> x = ivy.array([1.31, 2., 2.]) >>> y = x.softplus(threshold=2, out=x) >>> print(x) ivy.array([1.55, 2.13, 2.13])
- Container.softplus(self, /, *, beta=None, threshold=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.softplus. This method simply wraps the function, and so the docstring for ivy.softplus also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.beta (
Optional
[Union
[int
,float
]]) – The beta value for the softplus formation. Default:None
. (default:None
)threshold (
Optional
[Union
[int
,float
]]) – values above this revert to a linear function. Default:None
. (default:None
)key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container with the softplus unit function applied element-wise.
Examples
>>> x = ivy.Container(a=ivy.array([-0.3461, -0.6491])) >>> y = x.softplus() >>> print(y) { a: ivy.array([0.535, 0.42]) }
>>> x = ivy.Container(a=ivy.array([-1., 2., 4.])) >>> y = x.softplus(beta=0.5, threshold=2) >>> print(y) { a: ivy.array([0.948, 2.63, 4.25]) }