Last active
November 27, 2016 11:20
-
-
Save Lyken17/f9cdaa3219d6ff627d25b402c0396fff 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
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