implements the scaled exponential linear unit or selu function the function takes a vector of k real numbers and two real numbers alphadefault 1 6732 lambda default 1 0507 as input and then applies the selu function to each element of the vector selu is a selfnormalizing activation function it is a variant of the elu the main advantage of selu is that we can be sure that the output will always be standardized due to its selfnormalizing behavior that means there is no need to include batchnormalization layers references https iq opengenus orgscaledexponentiallinearunit applies the scaled exponential linear unit function to each element of the vector parameters vector np ndarray alpha float default 1 6732 lambda float default 1 0507 returns np ndarray formula fx lambda x if x 0 lambda alpha ex 1 if x 0 examples scaledexponentiallinearunitvectornp array1 3 3 7 2 4 array1 36591 3 88759 2 52168 scaledexponentiallinearunitvectornp array1 3 4 7 8 2 array1 36591 4 93829 8 61574 applies the scaled exponential linear unit function to each element of the vector parameters vector np ndarray alpha float default 1 6732 lambda_ float default 1 0507 returns np ndarray formula f x lambda_ x if x 0 lambda_ alpha e x 1 if x 0 examples scaled_exponential_linear_unit vector np array 1 3 3 7 2 4 array 1 36591 3 88759 2 52168 scaled_exponential_linear_unit vector np array 1 3 4 7 8 2 array 1 36591 4 93829 8 61574
import numpy as np


def scaled_exponential_linear_unit(
    vector: np.ndarray, alpha: float = 1.6732, lambda_: float = 1.0507
) -> np.ndarray:
    
    return lambda_ * np.where(vector > 0, vector, alpha * (np.exp(vector) - 1))


if __name__ == "__main__":
    import doctest

    doctest.testmod()