-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotfunctions.py
More file actions
65 lines (42 loc) · 1.18 KB
/
plotfunctions.py
File metadata and controls
65 lines (42 loc) · 1.18 KB
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
from numpy import *
import math
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-4,4,10000)
fig, ax = plt.subplots()
# ax.plot(x, np.maximum(np.zeros(len(x)),x),label="ReLU",linewidth=3)
# lrelu=x.copy()
# for i in range(len(x)):
# if lrelu[i]<0:
# lrelu[i]=lrelu[i]*0.2
# ax.plot(x, lrelu,label="LReLU",linewidth=1)
# ax.plot(x, (1-np.exp(-2*x))/(1+np.exp(-2*x)),label="Tanh")
# new=x.copy()
# for i in range(len(x)):
# if new[i]<0:
# new[i]=new[i]*exp(new[i])
# ax.plot(x, new,label="New activation function",linewidth=3)
# ax.plot(x, x/(1+exp(-x)),label="Swish")
new=x.copy()
for i in range(len(x)):
if new[i]<0:
new[i]=(1+new[i])*exp(new[i])
else:
new[i]=1
ax.plot(x, new,label="New activation function",linewidth=1)
def sig(x):
return 1/(1+exp(-x))
ax.plot(x, sig(x)+x*sig(x)*(1-sig(x)),label="Swish")
# elu=x.copy()
# for i in range(len(x)):
# if elu[i]<0:
# elu[i]=np.exp(elu[i])-1
# ax.plot(x, elu,label="ELU")
ax.axhline(y=0, color='k',alpha=0.5)
ax.axvline(x=0, color='k',alpha=0.5)
legend = ax.legend(loc='upper left',fontsize=14)
plt.xlabel("x",fontsize=15)
plt.ylabel("y",fontsize=15)
plt.ylim(ymax=1.5)
plt.ylim(ymin=-0.5)
plt.show()