-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoftmax.py
More file actions
40 lines (30 loc) · 823 Bytes
/
softmax.py
File metadata and controls
40 lines (30 loc) · 823 Bytes
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
"""Softmax."""
scores = [3.0, 1.0, 0.2]
import numpy as np
def softmax(x):
"""Compute softmax values for each sets of scores in x."""
print "x", x
denm = 0
#sum = 0
ret_list = []
for num in x:
print "num", num
denm += np.exp(num)
print "denm", denm
for num1 in x:
print np.exp(num1)/denm
ret_list.append(np.exp(num1)/denm)
return np.array(ret_list)
# ret = np.empty_like(x)
# print "shape", x
# for col in range(x.shape[1]):
# denm = np.sum(np.exp(x[:, col]))
# print ret[:, col]
# print "hello", x
# print(softmax(scores))
# Plot softmax curves
import matplotlib.pyplot as plt
x = np.arange(-2.0, 6.0, 0.1)
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)])
plt.plot(x, softmax(scores*10).T, linewidth=2)
plt.show()