hard_tanh

Contents

hard_tanh#

class brainstate.nn.hard_tanh(x, min_val=-1.0, max_val=1.0)[source]#

Hard hyperbolic tangent activation function.

Computes the element-wise function:

\[\begin{split}\mathrm{hard\_tanh}(x) = \begin{cases} -1, & x < -1\\ x, & -1 \le x \le 1\\ 1, & 1 < x \end{cases}\end{split}\]
Parameters:
  • x (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Input array.

  • min_val (float) – Minimum value of the linear region range. Default is -1.

  • max_val (float) – Maximum value of the linear region range. Default is 1.

Returns:

An array with the same shape as the input.

Return type:

Array | Quantity