Created
July 4, 2017 20:54
-
-
Save tomkowz/51ed289ce8260694e46f996d385cecac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def loss(X, Y, W): | |
delta = 1 | |
scores = np.dot(W, X.T) | |
rows = np.arange(Y.shape[0]) | |
margins = np.maximum(0, scores - scores[Y, rows] + delta) | |
# Find indices that need to be set to zero. | |
# Case when j == y in loss_i_v. | |
subtract_Y_indices = np.zeros(shape=margins.shape, dtype=bool) | |
subtract_Y_indices[Y, rows] = True | |
# Set proper indices to 0. | |
margins[subtract_Y_indices] = 0 | |
return np.sum(margins) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment