Implement the ELU (Exponential Linear Unit) activation function. ELU is defined as x for x > 0 and alpha * (exp(x) - 1) for x <= 0, where alpha is a hyperparameter (default 1.0).
import numpy as np
def elu(x: np.ndarray, alpha: float = 1.0) -> np.ndarray:
return np.where(x > 0, x, alpha * (np.exp(x) - 1))alpha * (exp(x) - 1).-alpha for large negative values, which helps push mean activations closer to zero and improves learning.alpha parameter controls the saturation value for negative inputs.