Skip to content
Snippets Groups Projects
Commit 6e282546 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add a function to the LexicalSimilarities to compute the projection of a...

Add a function to the LexicalSimilarities to compute the projection of a vector on the subspace it shares with another vector (useful to explain how keysIntersection can be lower than colinearity)
parent 09712adc
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ def keysIntersection(d1, d2): ...@@ -10,6 +10,10 @@ def keysIntersection(d1, d2):
def scalarProduct(d1, d2): def scalarProduct(d1, d2):
return sum([d1[k] * d2[k] for k in set(d1.keys()).intersection(d2)]) return sum([d1[k] * d2[k] for k in set(d1.keys()).intersection(d2)])
def commonProjection(d1, d2):
s2 = set(d2)
return {k: v for k, v in d1.items() if k in s2}
def norm(d): def norm(d):
return math.sqrt(scalarProduct(d, d)) return math.sqrt(scalarProduct(d, d))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment