Neural Mastery
← Practice
SELU (Scaled Exponential Linear Unit)medium

SELU (Scaled Exponential Linear Unit)

mediumDeep Learning⏱ 12 min
Libraries allowed · Pure Python earns +10 bonus XP
🎯 Mission
Implement SELU activation function for self-normalizing neural networks.

Task

Implement `selu(x)` returning element-wise scaled exponential linear activation values.

Function Signature

selu(x: list[float], scale: float, alpha: float) -> list[float]

Examples

Example 1: Positive and Zero
Input: {"x":[0,1,2]}
Output: [0,1.0507009873554805,2.101401974710961]
Example 2: Negative Input
Input: {"x":[-1]}
Output: [-1.111330737812562]

Constraints

  • If x > 0, return scale * x. Else return scale * alpha * (exp(x) - 1).
Python3Saved ✓
import math

def selu(x, scale=1.0507009873554805, alpha=1.6732632423543772):
"""
Computes SELU activation: scale * x if x > 0 else scale * alpha * (exp(x) - 1).
"""
# Your implementation here
pass

Case 1: Positive and Zero
Input: {"x":[0,1,2]}
Expected: [0,1.0507009873554805,2.101401974710961]
Case 2: Negative Input
Input: {"x":[-1]}
Expected: [-1.111330737812562]