-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparison.py
29 lines (25 loc) · 1.07 KB
/
comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from scipy.spatial.distance import hamming
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.metrics.pairwise import euclidean_distances
import numpy as np
class pairwiseComparison:
def __init__ (self, mode="auto"):
self.mode = mode
self.maxValue = 0
def evaluateSimilarity(self, inputFeatures):
S = np.zeros((inputFeatures.shape[0],inputFeatures.shape[0]), dtype=float)
self.maxValue = 0
for idx1 in range(inputFeatures.shape[0]):
v1 = inputFeatures[idx1,:]
for idx2 in range(idx1,inputFeatures.shape[0]):
v2 = inputFeatures[idx2,:]
#dist = euclidean_distances(v1.reshape(1, -1),v2.reshape(1, -1))
dist = cosine_similarity(v1.reshape(1, -1),v2.reshape(1, -1))
#dist = hamming(v1,v2)
if dist != 0:
S[idx1,idx2] = dist
if dist > self.maxValue:
self.maxValue = dist
else:
S[idx1,idx2] = 0
return S