RReLU

Contents

RReLU#

class brainstate.nn.RReLU(lower=0.125, upper=0.3333333333333333)#

Applies the randomized leaky rectified liner unit function, element-wise.

As described in the paper Empirical Evaluation of Rectified Activations in Convolutional Network.

The function is defined as:

\[\begin{split}\text{RReLU}(x) = \begin{cases} x & \text{if } x \geq 0 \\ ax & \text{ otherwise } \end{cases}\end{split}\]

where \(a\) is randomly sampled from uniform distribution \(\mathcal{U}(\text{lower}, \text{upper})\).

Parameters:
  • lower (float) – Lower bound of the uniform distribution. Default: \(\frac{1}{8}\)

  • upper (float) – Upper bound of the uniform distribution. Default: \(\frac{1}{3}\)

Notes

Unlike PyTorch’s RReLU, this layer samples a fresh random negative slope on every call (there is no separate evaluation mode that uses the fixed midpoint slope). Inference is therefore non-deterministic; fix lower == upper for a deterministic slope.

Shape#

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

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

References

Examples

>>> import brainstate.nn as nn
>>> import brainstate
>>> m = nn.RReLU(0.1, 0.3)
>>> x = brainstate.random.randn(2)
>>> output = m(x)