我有一组曲线定义为二维数组(点数,坐标数)。我正在使用 Hausdorff 距离为他们计算距离矩阵。我当前的代码如下。不幸的是,它太慢了,500-600 条曲线每条有 50-100 个 3D 点。有没有更快的方法呢?
def distanceBetweenCurves(C1, C2):
D = scipy.spatial.distance.cdist(C1, C2, 'euclidean')
#none symmetric Hausdorff distances
H1 = np.max(np.min(D, axis=1))
H2 = np.max(np.min(D, axis=0))
return (H1 + H2) / 2.
def distanceMatrixOfCurves(Curves):
numC = len(Curves)
D = np.zeros((numC, numC))
for i in range(0, numC-1):
for j in range(i+1, numC):
D[i, j] = D[j, i] = distanceBetweenCurves(Curves[i], Curves[j])
return D