relu6

Contents

relu6#

class brainunit.math.relu6(x, unit_to_scale=None)#

Rectified Linear Unit 6 activation function.

Computes the element-wise function

\[\mathrm{relu6}(x) = \min(\max(x, 0), 6)\]

except under differentiation, we take:

\[\nabla \mathrm{relu}(0) = 0\]

and

\[\nabla \mathrm{relu}(6) = 0\]
Parameters:
  • x (Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input array. Must be unitless if a Quantity.

  • unit_to_scale (Unit | None) – Unit used to convert x to a dimensionless number before applying the activation.

Returns:

out – An array with the same shape as x, clipped to the range [0, 6].

Return type:

Array

Examples

>>> import jax.numpy as jnp
>>> import saiunit.math as sumath
>>> sumath.relu6(jnp.array([-1., 0., 3., 7.]))
Array([0., 0., 3., 6.], dtype=float32)