In [1]:
### Load packages
import matplotlib.pyplot as plt
import numpy as np
In [2]:
### Define softmax function
def softmax(scores):
"""Compute softmax values for scores"""
expscores = np.exp(scores)
return expscores/np.sum(expscores)
In [3]:
### Generate a set of scores
x = np.arange(-2.0, 6.0, 0.1)
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)])
softmaxvalues = np.empty(scores.shape)
for i in np.arange(0, scores.shape[1]):
softmaxvalues[:, i] = softmax(scores[:, i])
In [4]:
### Plot softmax curves
colors = ('red', 'green', 'blue')
for i in np.arange(0, softmaxvalues.shape[0]):
plt.plot(x, softmaxvalues[i, :], color=colors[i], linewidth=2)
plt.show()