SELU: ELU With Self-Normalising Constants

Activation FunctionsEasy+10 XP+10

SELU: ELU With Self-Normalising Constants

SELU is ELU with two very specific numbers bolted on:

SELU(x)=λ⋅{xx>0α (ex−1)x≤0\text{SELU}(x) = \lambda \cdot \begin{cases} x & x > 0 \\ \alpha\,(e^{x} - 1) & x \le 0 \end{cases}SELU(x)=λ⋅{xα(ex−1)​x>0x≤0​

with

λ=1.0507009873554805,α=1.6732632423543772\lambda = 1.0507009873554805, \qquad \alpha = 1.6732632423543772λ=1.0507009873554805,α=1.6732632423543772

Task: write selu(values) returning one output per input, each rounded to 4 decimal places.

  • Compute the ELU part first with that fixed alpha, then multiply the whole thing by lambda. The scale applies to both branches, positive and negative.
  • alpha and lambda are constants here — the function takes no extra arguments.
  • x = 0 maps to exactly 0.0.

Those two ugly constants are not arbitrary: they're solved for, so that activations with mean 0 and variance 1 going into a layer come out with mean 0 and variance 1 again. Stack SELU layers and the signal neither explodes nor fades as it goes deeper — the network is self-normalising, which is where the extra S comes from. Change either constant and that property quietly disappears, which is why you'll always see them written out to full precision.

Examples

values = [1, -1, 0]
returns [1.0507, -1.1113, 0.0]
values = [0.5]
returns [0.5254]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run