relu#
- class brainunit.math.relu(x)#
Rectified linear unit activation function.
Computes the element-wise function:
\[\mathrm{relu}(x) = \max(x, 0)\]except under differentiation, we take:
\[\nabla \mathrm{relu}(0) = 0\]For more information see Numerical influence of ReLU’(0) on backpropagation.
- Parameters:
x (
Quantity|Array|ndarray|bool|number|bool|int|float|complex) – Input array. If aQuantitywith physical units is provided, the units are preserved in the output.- Returns:
out – An array with the same shape as x where negative values are replaced by zero. Units are preserved when present.
- Return type:
Quantity|Array
Examples
>>> import jax.numpy as jnp >>> import saiunit.math as sumath >>> sumath.relu(jnp.array([-2., -1., 0., 1., 2.])) Array([0., 0., 0., 1., 2.], dtype=float32) >>> import saiunit as u >>> q = u.Quantity(jnp.array([-1., 0., 1.]), unit=u.meter) >>> sumath.relu(q) # units are preserved