Created
March 21, 2020 17:43
-
-
Save tarlanahad/11c36432d371e6ba16ad30c70c12aa3c to your computer and use it in GitHub Desktop.
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
def get_cost_grads(self, X, w, y): | |
distances = self.distances(w) | |
# Get current cost | |
L = 1 / 2 * np.dot(w, w) - self.C * np.sum(distances) | |
dw = np.zeros(len(w)) | |
for ind, d in enumerate(distances): | |
if d == 0: # if sample is not on the support vector | |
di = w # (alpha * y[ind] * X[ind]) = 0 | |
else: | |
# (alpha * y[ind] * X[ind]) = y[ind] * X[ind] | |
di = w - (self.C * y[ind] * X[ind]) | |
dw += di | |
return L, dw / len(X) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment