Skip to content

Commit 63efc11

Browse files
committed
one part
1 parent dbca7af commit 63efc11

File tree

2 files changed

+153
-24
lines changed

2 files changed

+153
-24
lines changed

assignment1/cs231n/classifiers/linear_svm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ def svm_loss_naive(W, X, y, reg):
3737
margin = scores[j] - correct_class_score + 1 # note delta = 1
3838
if margin > 0:
3939
loss += margin
40+
dW[:, j] += X[i]
41+
dW[:, y[i]] -= X[i]
4042

41-
# Right now the loss is a sum over all training examples, but we want it
43+
# Right now the loss is a sum over all training examples, but we want it
4244
# to be an average instead so we divide by num_train.
45+
# X.T (D,N) loss (N,C)
46+
# dW = (X.T @ loss) / num_train + reg * W * W
47+
dW /= num_train
48+
dW += reg * W
4349
loss /= num_train
4450

4551
# Add regularization to the loss.
@@ -55,8 +61,6 @@ def svm_loss_naive(W, X, y, reg):
5561
#############################################################################
5662
# *****START OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
5763

58-
pass
59-
6064
# *****END OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
6165

6266
return loss, dW

assignment1/svm.ipynb

Lines changed: 146 additions & 21 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)