Hardtanh

Hardtanh#

class brainpy.dnn.Hardtanh(min_val=-1.0, max_val=1.0, inplace=False)[source]#

Applies the HardTanh function element-wise.

HardTanh is defined as:

\[\begin{split}\text{HardTanh}(x) = \begin{cases} \text{max\_val} & \text{ if } x > \text{ max\_val } \\ \text{min\_val} & \text{ if } x < \text{ min\_val } \\ x & \text{ otherwise } \\ \end{cases}\end{split}\]
Parameters:
  • min_val (float) – minimum value of the linear region range. Default: -1

  • max_val (float) – maximum value of the linear region range. Default: 1

  • inplace (bool) – can optionally do the operation in-place. Default: False

Keyword arguments min_value and max_value have been deprecated in favor of min_val and max_val.

Shape:
  • Input: \((*)\), where \(*\) means any number of dimensions.

  • Output: \((*)\), same shape as the input.

Examples:

>>> import brainpy as bp
>>> import brainpy.math as bm
>>> m = bp.dnn.Hardtanh(-2, 2)
>>> input = bm.random.randn(2)
>>> output = m(input)
update(input)[source]#

The function to specify the updating rule.

Return type:

TypeVar(ArrayType, Array, Variable, TrainVar, Array, ndarray)