-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivationFunctions.py
46 lines (36 loc) · 1 KB
/
ActivationFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from Constants import e
def sigmoid(x: float) -> float:
"""
Calculate sigmoid function
:param x: Input to the sigmoid function
:return: Value computed by the sigmoid function
"""
return 1 / (1 + (e ** (-x)))
def sigmoid_prime(x: float) -> float:
"""
Calculate the prime of the sigmoid function
:param x: Number to apply the prime sigmoid function
:return: Value of the prime sigmoid
"""
return (e ** x) / ((1 + (e ** x)) ** 2)
def relu(x: float) -> float:
"""
Relu activation function
:param x: Number to apply the activation function
:return: Value after relu
"""
return max(0.0, x)
def relu_prime(x: float) -> float:
"""
Calculate the the prime of the relu function
:param x: Number to apply the prime relu function
:return: Value of the prime relu
"""
if x > 0:
return 1
return 0
# Dictionary of activation functions
functionList = {
"sigmoid": [sigmoid, sigmoid_prime],
"relu": [relu, relu_prime]
}