Hardtanh#
- class brainstate.nn.Hardtanh(min_val=-1.0, max_val=1.0)#
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:
Notes
Keyword arguments
min_valueandmax_valuehave been deprecated in favor ofmin_valandmax_val.Shape#
Input: \((*)\), where \(*\) means any number of dimensions.
Output: \((*)\), same shape as the input.
Examples
>>> import brainstate.nn as nn >>> import brainstate >>> m = nn.Hardtanh(-2, 2) >>> x = brainstate.random.randn(2) >>> output = m(x)