Computation of Cosine Distance in Python
Closed this issue · 0 comments
Deleted user commented
The Cosine Distance in python yields different result than the C++ implementation.
It appears that in C++
d(x,y) = 1/pi * acos(dot(x,y)/(norm(x)*norm(y))
is computed whereas in Python
d(x,y) = dot(x,y)/(norm(x)*norm(y))
is computed.
I tried it with
a = np.array([[1.0], [3.0]])
b = np.array([[4.0], [2.0]])
distance = Cosine()
print(distance(a, b))
and
vector<double> a = {1.0, 3.0};
vector<double> b = {4.0, 2.0};
auto distance = Cosine<double>();
auto result = distance(a, b);
cout << result << endl;