MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / euclidean_distance_matrix

Function euclidean_distance_matrix

mogen/core/evaluation/utils.py:12–26  ·  view source on GitHub ↗

Params: -- matrix1: N1 x D -- matrix2: N2 x D Returns: -- dist: N1 x N2 dist[i, j] == distance(matrix1[i], matrix2[j])

(matrix1, matrix2)

Source from the content-addressed store, hash-verified

10
11
12def euclidean_distance_matrix(matrix1, matrix2):
13 """
14 Params:
15 -- matrix1: N1 x D
16 -- matrix2: N2 x D
17 Returns:
18 -- dist: N1 x N2
19 dist[i, j] == distance(matrix1[i], matrix2[j])
20 """
21 assert matrix1.shape[1] == matrix2.shape[1]
22 d1 = -2 * np.dot(matrix1, matrix2.T)
23 d2 = np.sum(np.square(matrix1), axis=1, keepdims=True)
24 d3 = np.sum(np.square(matrix2), axis=1)
25 dists = np.sqrt(d1 + d2 + d3)
26 return dists
27
28
29def calculate_top_k(mat, top_k):

Callers 2

single_evaluateMethod · 0.85
single_evaluateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected