Created
November 6, 2015 00:31
-
-
Save dela3499/7856cf4927bec14d0438 to your computer and use it in GitHub Desktop.
Cosine distance between two random vectors is normally distributed around 0.75
This file contains hidden or 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
import numpy as np | |
mag = np.linalg.norm | |
r = np.random.random | |
def cosdist(x,y): | |
return sum(x * y) / (mag(x) * mag(y)) | |
def repeat(f,n): | |
return [f() for _ in range(n)] | |
d = repeat(lambda: cosdist(r(100),r(100)),100000) | |
plt.hist(d,bins = 100); # cosine distance centered on 0.75 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment