-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
79 lines (60 loc) · 1.42 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
72
73
74
75
76
77
78
79
#Functions gotten from https://en.wikipedia.org/wiki/Activation_function - "Activation function" by Wikipedia
#Most are probably wrong
#See Neural-Net-2/functions.py for "new" version, may actually be the same
import numpy as np #www.numpy.org
def linear(x):
return x
def linear_der(x):
return 1
def relu(inp):
if (inp < 0):
return 0
else:
return inp
def relu_der(inp):
if (inp < 0):
return 0
else:
return 1
def prelu(inp, leak_rate):
if (inp < 0):
return ((leak_rate)*inp)
else:
return inp
def prelu_der(inp, leak_rate):
if (inp < 0):
return leak_rate
else:
return 1
def elu(inp, leak_rate):
if (inp < 0):
return (leak_rate * (np.exp(inp) - 1))
else:
return inp
def elu_der(inp, leak_rate):
if (inp < 0):
return (leak_rate * np.exp(inp))
else:
return 1
def identity(inp):
return inp
def identity_der(inp):
return 1
def arctan(inp):
return np.arctan(inp)
def arctan_der(inp):
return (1/(1+(x**2)))
def arctan_inv(inp):
return np.tan(inp)
def tanh(inp):
return np.tanh(inp)
def tanh_der(inp):
return 1 - (np.tanh(inp))**2
def softplus(inp):
return np.log(1 + np.exp(inp))
def softplus_der(inp):
return (1/(1 + np.exp(-inp)))
def sigmoid(inp):
return (1/(1 + np.exp(-inp)))
def sigmoid_der(inp):
return sigmoid(inp) * (1 - sigmoid(inp))