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
def plotComplexPointsAndVectors(locations, derivatives): | |
X,Y = zip(*map(lambda x: (x.real, x.imag), locations)) | |
U,V = zip(*map(lambda x: (x.real, x.imag), derivatives)) | |
plt.plot(X,Y, "ro-", label="python") | |
limit = np.max(np.ceil(np.absolute(points))) | |
plt.xlim((-limit, limit)) | |
plt.ylim((-limit, limit)) | |
plt.xlabel("Real") | |
plt.ylabel("Imaginary") | |
plt.quiver(X,Y,U,V, linewidths = 2) |
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
from math import pow, sqrt | |
def cosine(ratings1, ratings2): | |
norm1 = sum([pow(rating,2) for rating in ratings1.values()]) | |
norm2 = sum([pow(rating,2) for rating in ratings2.values()]) | |
intersect_keys = filter(lambda x: x in ratings1.keys(), ratings2.keys()) | |
dot_product = sum([ratings1[key]*ratings2[key] for key in intersect_keys]) | |
cosine_distance = dot_product/(sqrt(norm1*norm2)) | |
return cosine_distance |