MCPcopy Index your code
hub / github.com/clips/pattern / cosine_similarity

Function cosine_similarity

pattern/vector/__init__.py:694–699  ·  view source on GitHub ↗

Returns the cosine similarity of the given vectors.

(v1, v2)

Source from the content-addressed store, hash-verified

692norm = l2 = L2 = L2norm = l2norm = L2_norm = l2_norm
693
694def cosine_similarity(v1, v2):
695 """ Returns the cosine similarity of the given vectors.
696 """
697 s = sum(v1.get(f, 0) * w for f, w in v2.iteritems())
698 s = float(s) / (l2_norm(v1) * l2_norm(v2) or 1)
699 return s
700
701cos = cosine_similarity
702

Callers 3

cosine_similarityMethod · 0.85
distanceFunction · 0.85
cosine_similarityMethod · 0.85

Calls 4

sumFunction · 0.85
l2_normFunction · 0.85
iteritemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…