Skip to content
fn

rrelu

→Tensor
rrelu(input: Tensor, lower: float = 1.0 / 8.0, upper: float = 1.0 / 3.0, training: bool = False, inplace: bool = False)

Randomised leaky ReLU (Xu et al. 2015).

A regularised variant of leaky_relu: during training every negative element is scaled by an i.i.d. uniform slope, injecting activation noise on the negative side. At evaluation time the expectation of that uniform draw is used, so the function becomes deterministic.

Parameters

inputTensor
Input tensor.
lowerfloat= 1.0 / 8.0
Lower bound of the uniform slope distribution. Default 1/8.
upperfloat= 1.0 / 3.0
Upper bound of the uniform slope distribution. Default 1/3.
trainingbool= False
If True sample a fresh slope per element; if False use the midpoint. Default False.
inplacebool= False
If True, input itself receives the result and is returned.

Returns

Tensor

Activated tensor with the same shape as input.

Notes

During training, with a∼Uniform(lower,upper)a \sim \mathrm{Uniform}(\text{lower}, \text{upper}) sampled element-wise:

RReLU(x)={xx≥0axx<0\text{RReLU}(x) = \begin{cases} x & x \ge 0 \\ a x & x < 0 \end{cases}

During evaluation, aa is replaced by the expectation (lower+upper)/2(\text{lower} + \text{upper}) / 2. The slope randomisation acts as a mild noise regulariser — comparable in spirit to dropout but applied to activation slope rather than activation magnitude.

Examples

>>> import lucid
>>> from lucid.nn.functional import rrelu
>>> x = lucid.tensor([-1.0, 0.0, 1.0])
>>> rrelu(x, training=False)
tensor([-0.2292, 0., 1.])

Used by 2