Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 585fc10

Browse files
author
zhoufeng3
committed
新增17,测试是否成功
1 parent 6963772 commit 585fc10

File tree

4 files changed

+593
-457
lines changed

4 files changed

+593
-457
lines changed

12_plot_activations.py

100755100644
Lines changed: 143 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,144 @@
1-
import numpy as np
2-
import matplotlib.pyplot as plt
3-
4-
##### Sigmoid
5-
sigmoid = lambda x: 1 / (1 + np.exp(-x))
6-
7-
x=np.linspace(-10,10,10)
8-
9-
y=np.linspace(-10,10,100)
10-
11-
fig = plt.figure()
12-
plt.plot(y,sigmoid(y),'b', label='linspace(-10,10,100)')
13-
14-
plt.grid(linestyle='--')
15-
16-
plt.xlabel('X Axis')
17-
18-
plt.ylabel('Y Axis')
19-
20-
plt.title('Sigmoid Function')
21-
22-
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
23-
plt.yticks([-2, -1, 0, 1, 2])
24-
25-
plt.ylim(-2, 2)
26-
plt.xlim(-4, 4)
27-
28-
plt.show()
29-
#plt.savefig('sigmoid.png')
30-
31-
fig = plt.figure()
32-
33-
##### TanH
34-
tanh = lambda x: 2*sigmoid(2*x)-1
35-
36-
x=np.linspace(-10,10,10)
37-
38-
y=np.linspace(-10,10,100)
39-
40-
plt.plot(y,tanh(y),'b', label='linspace(-10,10,100)')
41-
42-
plt.grid(linestyle='--')
43-
44-
plt.xlabel('X Axis')
45-
46-
plt.ylabel('Y Axis')
47-
48-
plt.title('TanH Function')
49-
50-
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
51-
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
52-
53-
plt.ylim(-4, 4)
54-
plt.xlim(-4, 4)
55-
56-
plt.show()
57-
#plt.savefig('tanh.png')
58-
59-
fig = plt.figure()
60-
61-
##### ReLU
62-
relu = lambda x: np.where(x>=0, x, 0)
63-
64-
x=np.linspace(-10,10,10)
65-
66-
y=np.linspace(-10,10,1000)
67-
68-
plt.plot(y,relu(y),'b', label='linspace(-10,10,100)')
69-
70-
plt.grid(linestyle='--')
71-
72-
plt.xlabel('X Axis')
73-
74-
plt.ylabel('Y Axis')
75-
76-
plt.title('ReLU')
77-
78-
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
79-
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
80-
81-
plt.ylim(-4, 4)
82-
plt.xlim(-4, 4)
83-
84-
plt.show()
85-
#plt.savefig('relu.png')
86-
87-
fig = plt.figure()
88-
89-
##### Leaky ReLU
90-
leakyrelu = lambda x: np.where(x>=0, x, 0.1*x)
91-
92-
x=np.linspace(-10,10,10)
93-
94-
y=np.linspace(-10,10,1000)
95-
96-
plt.plot(y,leakyrelu(y),'b', label='linspace(-10,10,100)')
97-
98-
plt.grid(linestyle='--')
99-
100-
plt.xlabel('X Axis')
101-
102-
plt.ylabel('Y Axis')
103-
104-
plt.title('Leaky ReLU')
105-
106-
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
107-
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
108-
109-
plt.ylim(-4, 4)
110-
plt.xlim(-4, 4)
111-
112-
plt.show()
113-
#plt.savefig('lrelu.png')
114-
115-
fig = plt.figure()
116-
117-
118-
##### Binary Step
119-
bstep = lambda x: np.where(x>=0, 1, 0)
120-
121-
x=np.linspace(-10,10,10)
122-
123-
y=np.linspace(-10,10,1000)
124-
125-
plt.plot(y,bstep(y),'b', label='linspace(-10,10,100)')
126-
127-
plt.grid(linestyle='--')
128-
129-
plt.xlabel('X Axis')
130-
131-
plt.ylabel('Y Axis')
132-
133-
plt.title('Step Function')
134-
135-
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
136-
plt.yticks([-2, -1, 0, 1, 2])
137-
138-
plt.ylim(-2, 2)
139-
plt.xlim(-4, 4)
140-
141-
plt.show()
142-
#plt.savefig('step.png')
143-
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
##### Sigmoid
5+
sigmoid = lambda x: 1 / (1 + np.exp(-x))
6+
7+
x=np.linspace(-10,10,10)
8+
9+
y=np.linspace(-10,10,100)
10+
11+
fig = plt.figure()
12+
plt.plot(y,sigmoid(y),'b', label='linspace(-10,10,100)')
13+
14+
plt.grid(linestyle='--')
15+
16+
plt.xlabel('X Axis')
17+
18+
plt.ylabel('Y Axis')
19+
20+
plt.title('Sigmoid Function')
21+
22+
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
23+
plt.yticks([-2, -1, 0, 1, 2])
24+
25+
plt.ylim(-2, 2)
26+
plt.xlim(-4, 4)
27+
28+
plt.show()
29+
#plt.savefig('sigmoid.png')
30+
31+
fig = plt.figure()
32+
33+
##### TanH
34+
tanh = lambda x: 2*sigmoid(2*x)-1
35+
36+
x=np.linspace(-10,10,10)
37+
38+
y=np.linspace(-10,10,100)
39+
40+
plt.plot(y,tanh(y),'b', label='linspace(-10,10,100)')
41+
42+
plt.grid(linestyle='--')
43+
44+
plt.xlabel('X Axis')
45+
46+
plt.ylabel('Y Axis')
47+
48+
plt.title('TanH Function')
49+
50+
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
51+
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
52+
53+
plt.ylim(-4, 4)
54+
plt.xlim(-4, 4)
55+
56+
plt.show()
57+
#plt.savefig('tanh.png')
58+
59+
fig = plt.figure()
60+
61+
##### ReLU
62+
relu = lambda x: np.where(x>=0, x, 0)
63+
64+
x=np.linspace(-10,10,10)
65+
66+
y=np.linspace(-10,10,1000)
67+
68+
plt.plot(y,relu(y),'b', label='linspace(-10,10,100)')
69+
70+
plt.grid(linestyle='--')
71+
72+
plt.xlabel('X Axis')
73+
74+
plt.ylabel('Y Axis')
75+
76+
plt.title('ReLU')
77+
78+
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
79+
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
80+
81+
plt.ylim(-4, 4)
82+
plt.xlim(-4, 4)
83+
84+
plt.show()
85+
#plt.savefig('relu.png')
86+
87+
fig = plt.figure()
88+
89+
##### Leaky ReLU
90+
leakyrelu = lambda x: np.where(x>=0, x, 0.1*x)
91+
92+
x=np.linspace(-10,10,10)
93+
94+
y=np.linspace(-10,10,1000)
95+
96+
plt.plot(y,leakyrelu(y),'b', label='linspace(-10,10,100)')
97+
98+
plt.grid(linestyle='--')
99+
100+
plt.xlabel('X Axis')
101+
102+
plt.ylabel('Y Axis')
103+
104+
plt.title('Leaky ReLU')
105+
106+
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
107+
plt.yticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
108+
109+
plt.ylim(-4, 4)
110+
plt.xlim(-4, 4)
111+
112+
plt.show()
113+
#plt.savefig('lrelu.png')
114+
115+
fig = plt.figure()
116+
117+
118+
##### Binary Step
119+
bstep = lambda x: np.where(x>=0, 1, 0)
120+
121+
x=np.linspace(-10,10,10)
122+
123+
y=np.linspace(-10,10,1000)
124+
125+
plt.plot(y,bstep(y),'b', label='linspace(-10,10,100)')
126+
127+
plt.grid(linestyle='--')
128+
129+
plt.xlabel('X Axis')
130+
131+
plt.ylabel('Y Axis')
132+
133+
plt.title('Step Function')
134+
135+
plt.xticks([-4, -3, -2, -1, 0, 1, 2, 3, 4])
136+
plt.yticks([-2, -1, 0, 1, 2])
137+
138+
plt.ylim(-2, 2)
139+
plt.xlim(-4, 4)
140+
141+
plt.show()
142+
#plt.savefig('step.png')
143+
144144
print('done')

0 commit comments

Comments
 (0)