Skip to content

Instantly share code, notes, and snippets.

@Lyken17
Last active November 27, 2016 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lyken17/f9cdaa3219d6ff627d25b402c0396fff to your computer and use it in GitHub Desktop.
Save Lyken17/f9cdaa3219d6ff627d25b402c0396fff to your computer and use it in GitHub Desktop.
mistakes = 0
for i in range(epochs):
for nbest in nbests:
def get_sample():
sample = []
for i in range(tau):
# s1, s2 = random.sample(nbest, 2)
s1 = random.choice(nbest)
s2 = random.choice(nbest)
if math.fabs(s1[1] - s2[1]) > alpha:
if s1[1] > s2[1]:
sample.append((s1, s2))
else:
sample.append((s2, s2))
else:
continue
return sample
samples = sorted(get_sample(), key=lambda s: s[0][1] - s[1][1], reverse=True)
samples = samples[:xi]
for s in samples:
s1 = s[0][0]
s2 = s[1][0]
if np.dot(theta, s1.features) <= np.dot(theta, s2.features):
mistakes += 1
theta += eta * (s1.features - s2.features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment