Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Last active April 6, 2017 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmcli/575e84eddfcde139b5c45f586ba269c5 to your computer and use it in GitHub Desktop.
Save adrianmcli/575e84eddfcde139b5c45f586ba269c5 to your computer and use it in GitHub Desktop.
Storing stuff I'm learning from Udacity's deep learning course.
"""Softmax."""
scores = [3.0, 1.0, 0.2]
import numpy as np
from math import e
def softmax(scores):
denominator = sum([e ** x for x in scores])
result = [e ** x / denominator for x in scores]
is_1d_array = isinstance(result[0], float);
return result if is_1d_array else np.array(result)
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).T, linewidth=2)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment