Skip to content

Commit 54f1a13

Browse files
TMGA-WAYpre-commit-ci[bot]cclauss
authored andcommitted
The ELU activation is added (TheAlgorithms#8699)
* tanh function been added * tanh function been added * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * tanh function is added * tanh function is added * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * tanh function added * tanh function added * tanh function is added * Apply suggestions from code review * ELU activation function is added * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * elu activation is added * ELU activation is added * Update maths/elu_activation.py Co-authored-by: Christian Clauss <[email protected]> * Exponential_linear_unit activation is added * Exponential_linear_unit activation is added --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 22101d5 commit 54f1a13

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Implements the Exponential Linear Unit or ELU function.
3+
4+
The function takes a vector of K real numbers and a real number alpha as
5+
input and then applies the ELU function to each element of the vector.
6+
7+
Script inspired from its corresponding Wikipedia article
8+
https://en.wikipedia.org/wiki/Rectifier_(neural_networks)
9+
"""
10+
11+
import numpy as np
12+
13+
14+
def exponential_linear_unit(vector: np.ndarray, alpha: float) -> np.ndarray:
15+
"""
16+
Implements the ELU activation function.
17+
Parameters:
18+
vector: the array containing input of elu activation
19+
alpha: hyper-parameter
20+
return:
21+
elu (np.array): The input numpy array after applying elu.
22+
23+
Mathematically, f(x) = x, x>0 else (alpha * (e^x -1)), x<=0, alpha >=0
24+
25+
Examples:
26+
>>> exponential_linear_unit(vector=np.array([2.3,0.6,-2,-3.8]), alpha=0.3)
27+
array([ 2.3 , 0.6 , -0.25939942, -0.29328877])
28+
29+
>>> exponential_linear_unit(vector=np.array([-9.2,-0.3,0.45,-4.56]), alpha=0.067)
30+
array([-0.06699323, -0.01736518, 0.45 , -0.06629904])
31+
32+
33+
"""
34+
return np.where(vector > 0, vector, (alpha * (np.exp(vector) - 1)))
35+
36+
37+
if __name__ == "__main__":
38+
import doctest
39+
40+
doctest.testmod()

0 commit comments

Comments
 (0)