Implement the Softplus activation function. Softplus is a smooth approximation of ReLU defined as f(x) = ln(1 + exp(x)).
import numpy as np
def softplus(x: np.ndarray) -> np.ndarray:
# Numerically stable: for large x, softplus(x) ≈ x
return np.where(x > 20, x, np.log1p(np.exp(x)))ln(1 + exp(x)), which smoothly approximates max(0, x) (ReLU).x, exp(x) overflows, but ln(1 + exp(x)) ≈ x, so we return x directly for numerical stability.np.log1p computes ln(1 + z) with better numerical precision for small z.