Skip to content
This repository was archived by the owner on May 13, 2023. It is now read-only.

Commit 00958f1

Browse files
committed
first commit
0 parents  commit 00958f1

18 files changed

+1206
-0
lines changed

Assignment2.ipynb

Lines changed: 908 additions & 0 deletions
Large diffs are not rendered by default.

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from svm_loss import svm_loss
2+
from svm_gradient import svm_gradient
3+
from svm_solver import svm_solver
319 Bytes
Binary file not shown.
1.32 KB
Binary file not shown.
1.15 KB
Binary file not shown.
1.32 KB
Binary file not shown.

assignment2/.DS_Store

6 KB
Binary file not shown.

assignment2/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from svm_loss import svm_loss
2+
from svm_gradient import svm_gradient
3+
from svm_solver import svm_solver
319 Bytes
Binary file not shown.

assignment2/svm_gradient.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
3+
4+
def svm_gradient(w, b, x, y, C):
5+
"""
6+
Compute gradient for SVM w.r.t. to the parameters w and b on a mini-batch (x, y)
7+
8+
Args:
9+
w: Parameters of shape [num_features]
10+
b: Bias (a scalar)
11+
x: A mini-batch of training example [k, num_features]
12+
y: Labels corresponding to x of size [k]
13+
14+
Returns:
15+
grad_w: The gradient of the SVM objective w.r.t. w of shape [k, num_features]
16+
grad_v: The gradient of the SVM objective w.r.t. b of shape [k, 1]
17+
18+
"""
19+
20+
grad_w = 0
21+
grad_b = 0
22+
23+
24+
#######################################################################
25+
# TODO: #
26+
# Compute the gradient for a particular choice of w and b. #
27+
# Compute the partial derivatives and set grad_w and grad_b to the #
28+
# partial derivatives of the cost w.r.t. both parameters #
29+
# #
30+
#######################################################################
31+
32+
33+
#######################################################################
34+
# END OF YOUR CODE #
35+
#######################################################################
36+
return grad_w, grad_b

0 commit comments

Comments
 (0)