Skip to content

Instantly share code, notes, and snippets.

@pratos
Created April 12, 2017 09:42
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 pratos/689f28f43e5dc473dee79175bfe065a6 to your computer and use it in GitHub Desktop.
Save pratos/689f28f43e5dc473dee79175bfe065a6 to your computer and use it in GitHub Desktop.
CS231n Softmax (Cross-entropy loss) - Vectorized
import numpy as np
W = np.array([(0.01,-0.05,0.1,0.05),(0.7,0.2,0.05,0.16),(0.0,-0.45,-0.2, 0.03)]) #Weights
xi = np.array([-15,22,-44,56]) #Input
b = np.array([0.0,0.2,-0.3]) #Bias
delta = 1
y = np.sum((np.dot(W,xi),b), axis=0)
p = np.exp(y)/np.sum(np.exp(y))
final = -np.log(p[p.size-1])
# final = 1.0401905694301092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment