Skip to content

Instantly share code, notes, and snippets.

@amkatrutsa
Created April 14, 2015 19:35
Show Gist options
  • Save amkatrutsa/5e816d7b7dff6d9e14ac to your computer and use it in GitHub Desktop.
Save amkatrutsa/5e816d7b7dff6d9e14ac to your computer and use it in GitHub Desktop.
def compute_grad_metric(w, x1, x2, label1, label2):
y = label1 == label2
dx = (x1 - x2).reshape(64, 1)
mod_x = w.dot(dx)
if y:
return 2 * np.dot(w, np.dot(dx, dx.T))
elif (1 - np.dot(mod_x.T, mod_x) > 0):
return -2 * np.dot(w, np.dot(dx, dx.T))
else:
return np.zeros(w.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment