In [21]:
# import the modules
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [9]:
x = np.asmatrix([scores,scores])
print x, np.exp(x)/np.sum(np.exp(x),axis=1)
In [18]:
def softmax(x):
"""Compute softmax values for each sets of scores in x."""
x = np.asarray(x)
return np.exp(x)/np.sum(np.exp(x),axis=0)
In [19]:
# analysis 1
scores = [3.0, 1.0, 0.2]
print(softmax(scores))
In [23]:
# Plot softmax curves
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).T, linewidth=2)
plt.legend(['x','1','0.2'])
plt.show()
In [ ]: