11 ms·
Ah, I mistook the - at the beginning for a separator. It does fail the triangle inequality, though, as the following python snippit demonstrates: import num
by tlb 8y ago
Ah, I mistook the - at the beginning for a separator.
It does fail the triangle inequality, though, as the following python snippit demonstrates:
import numpy as np
def randomvec():
return np.random.rand(4)*2-1
def cossim(a, b):
return np.dot(a,b) / np.sqrt(np.dot(a, a) * np.dot(b, b))
def metric(a, b):
return -np.log((1+cossim(a, b))/2)
def main():
for i in range(20):
a = randomvec()
b = randomvec()
c = randomvec()
a2b = metric(a, b)
b2c = metric(b, c)
a2c = metric(a, c)
print a2b, b2c, a2c
if a2b + b2c < a2c:
print ' *** fails triangle inequality'
main()
- DoctorOetker 8y agogood catch! upvoted