-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
71 lines (45 loc) · 1.04 KB
/
functions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import math
def step(x):
return 1 if x >= 0 else 0
def sigmoid(x):
return 1 / (1 + math.exp(-x))
def tanh(x):
return (2 / (1 + math.exp(-x))) - 1
def ReLU(x):
return x if x >= 0 else 0
def linear(x):
return x
def derv_tanh(x):
return 1 - x ** 2
def derv_sigmoid(x):
return x * (1 - x)
def derv_linear(x):
return 1
def derv_ReLU(x):
return 1 if x >= 0 else 0
def derv_step(x):
return 0
def determine_activation_function(name):
if name == 'step':
return step
elif name == 'linear':
return linear
elif name == 'sigmoid':
return sigmoid
elif name == 'tanh':
return tanh
elif name == 'ReLU':
return ReLU
def match_derivative(func):
if func == step:
return derv_step
elif func == ReLU:
return derv_ReLU
elif func == linear:
return derv_linear
elif func == tanh:
return derv_tanh
elif func == sigmoid:
return derv_sigmoid
def my_formatter(num):
return float('{0:.3f}'.format(num))