Created
April 12, 2017 09:30
-
-
Save pratos/f59cddc275711176e176527ade0417f1 to your computer and use it in GitHub Desktop.
CS231n Hinge Loss SVM Snippet - Vectorized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
#comp = (sj - syi) | |
# sj = y[:y.size-1] | |
# syi = y[y.size-1] | |
comp = np.sum((y[:y.size-1],-y[y.size-1]), axis=0) | |
# li = summation(max(0, sj-syi+delta)) | |
li = np.sum(np.max((np.zeros((y.size-1,)), np.sum((comp,delta), axis=0)), axis=0)) | |
# li = 1.5800000000000018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment