Activations#
- class ivy.data_classes.array.activations._ArrayWithActivations[source]#
Bases:
ABC
- _abc_impl = <_abc._abc_data object>#
- gelu(*, approximate=False, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.gelu. This method simply wraps the function, and so the docstring for ivy.gelu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.approximate (
bool
, default:False
) – whether to use the approximate version of the gelu function.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 gelu activation function applied element-wise.
Examples
>>> x = ivy.array([-1.2, -0.6, 1.5]) >>> y = x.gelu() >>> print(y) ivy.array([-0.138, -0.165, 1.4])
- hardswish(*, complex_mode='jax', out=None)[source]#
Apply the hardswish activation function element-wise.
- Parameters:
x – input array
complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 hardswish activation of each element in
x
.
Examples
With
ivy.Array
input:>>> x = ivy.array([0., 0., 4.]) >>> y = ivy.hardswish(x) >>> y ivy.array([0., 0., 4.])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([-3., 4., 5.]), b=ivy.array([0., 5.])) >>> x = ivy.hardswish(x, out=x) >>> x { a: ivy.array([-0., 4., 5.]), b: ivy.array([0., 5.]) }
- leaky_relu(*, alpha=0.2, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.leaky_relu. This method simply wraps the function, and so the docstring for ivy.leaky_relu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.alpha (
float
, default:0.2
) – the slope of the negative section.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 leaky relu activation function applied element-wise.
Examples
>>> x = ivy.array([0.39, -0.85]) >>> y = x.leaky_relu() >>> print(y) ivy.array([ 0.39, -0.17])
- log_softmax(*, axis=-1, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.log_softmax. This method simply wraps the function, and so the docstring for ivy.log_softmax also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.axis (
Optional
[int
], default:-1
) – the axis or axes along which the log_softmax should be computedcomplex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 log_softmax activation function applied element-wise.
Examples
>>> x = ivy.array([-1.0, -0.98, 2.3]) >>> y = x.log_softmax() >>> print(y) ivy.array([-3.37, -3.35, -0.0719])
>>> x = ivy.array([2.0, 3.4, -4.2]) >>> y = x.log_softmax(x) ivy.array([-1.62, -0.221, -7.82 ])
- mish(*, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.mish. This method simply wraps the function, and so the docstring for ivy.mish also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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
Examples
>>> x = ivy.array([-1., 0., 1.]) >>> y = x.mish() >>> print(y) ivy.array([-0.30340147, 0. , 0.86509842])
- relu(*, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.relu. This method simply wraps the function, and so the docstring for ivy.relu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 relu activation function applied element-wise.
Examples
>>> x = ivy.array([-1., 0., 1.]) >>> y = x.relu() >>> print(y) ivy.array([0., 0., 1.])
- sigmoid(*, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.sigmoid.
This method simply wraps the function, and so the docstring for ivy.sigmoid also applies to this method with minimal changes.
- Parameters:
self (
Array
) – Input arraycomplex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.out (
Optional
[Array
], default:None
) – optional output array for writing the result to. It must have the same shape the input broadcast to default: None
- Return type:
Array
- Returns:
ret – an array with the sigmoid activation function applied element-wise.
Examples
>>> x = ivy.array([-1., 1., 2.]) >>> y = x.sigmoid() >>> print(y) ivy.array([0.269, 0.731, 0.881])
- softmax(*, axis=None, complex_mode='jax', out=None)[source]#
ivy.Array instance method variant of ivy.softmax. This method simply wraps the function, and so the docstring for ivy.softmax also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.axis (
Optional
[int
], default:None
) – the axis or axes along which the softmax should be computedcomplex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.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 softmax activation function applied element-wise.
Examples
>>> x = ivy.array([1.0, 0, 1.0]) >>> y = x.softmax() >>> print(y) ivy.array([0.422, 0.155, 0.422])
- softplus(*, beta=None, threshold=None, complex_mode='jax', out=None)[source]#
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
]], default:None
) – the beta parameter of the softplus function.threshold (
Optional
[Union
[int
,float
]], default:None
) – the threshold parameter of the softplus function.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) –- optional specifier for how to handle complex data types. See
ivy.func_wrapper.handle_complex_input
for more detail.
out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape
- 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])
This should have hopefully given you an overview of the activations submodule, if you have any questions, please feel free to reach out on our discord!