mindspore.nn.ELU

class mindspore.nn.ELU(alpha=1.0)[source]

Exponential Linear Uint activation function.

Applies the exponential linear unit function element-wise. The activation function is defined as:

\[E_{i} = \begin{cases} x, &\text{if } x \geq 0; \cr \text{alpha} * (\exp(x_i) - 1), &\text{otherwise.} \end{cases}\]

The picture about ELU looks like this ELU.

Parameters

alpha (float) – The coefficient of negative factor whose type is float. Default: 1.0.

Inputs:
  • x (Tensor) - The input of ELU with data type of float16 or float32. The shape is \((N,*)\) where \(*\) means,any number of additional dimensions.

Outputs:

Tensor, with the same type and shape as the x.

Raises
  • TypeError – If alpha is not a float.

  • TypeError – If dtype of x is neither float16 nor float32.

  • ValueError – If alpha is not equal to 1.0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float32)
>>> elu = nn.ELU()
>>> result = elu(x)
>>> print(result)
[-0.63212055  -0.86466473  0.  2.  1.]