Skip to content
class

SELU

extends_InplaceActivation
SELU(inplace: bool = False)

Scaled Exponential Linear Unit activation function.

Applies element-wise:

SELU(x)=λ{xif x>0α(ex−1)otherwise\text{SELU}(x) = \lambda \begin{cases} x & \text{if } x > 0 \\ \alpha \left(e^{x} - 1\right) & \text{otherwise} \end{cases}

where λ≈1.0507\lambda \approx 1.0507 and α≈1.6733\alpha \approx 1.6733 are fixed constants derived from the self-normalising property. When weights are initialised with lecun_normal and the network uses only SELU activations, the mean and variance of each layer's output converge to 0 and 1, enabling stable training of very deep fully-connected networks without batch normalisation.

Parameters

inplacebool= False
If True, modifies the input tensor in-place. Default: False.

Notes

  • Input: (∗)(*) — any shape.
  • Output: (∗)(*) — same shape as input.

The self-normalising guarantee holds strictly only for networks with no skip connections, no convolutional layers, and Lecun-normal weight initialisation. In practice SELU is used more broadly as a drop-in for ELU.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.SELU()
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([-1.52, -1.111, 0., 1.051, 2.101])
>>> # Suitable for deep fully-connected architectures
>>> layers = nn.Sequential(nn.Linear(128, 64), nn.SELU(), nn.Linear(64, 10))
>>> x = lucid.randn(8, 128)
>>> out = layers(x)
>>> out.shape
(8, 10)

Used by 1

Instance methods

1
fn

forward

→Tensor
forward(input: Tensor)

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.