简体   繁体   English

如何将成对距离矩阵中的大值转换为小值?

[英]How to convert a large value within a pairwise distance matrix into a small value?

let D be a pairwise distance between two sets of observations. D为两组观测值之间的成对距离。 I used a custom distance function to represent similarity. 我使用自定义距离函数来表示相似性。 Unlike the most of similarity measures, the way that I have chosen for calculating the distance gives large value for similar pairs. 与大多数相似性度量方法不同,我选择的计算距离的方法为相似对提供了很大的价值。

    0 1 2

0   0 4 6
1   5 9 7
2   2 1 4

In normal cases we will consider the 0 and 0 points are the most similar pair, since the distance value between them is 0 . 在正常情况下,我们将00点视为最相似的对,因为它们之间的距离值为0 In my case the 1 and 1 are the most similar pair, since they have the largest value 9 . 在我的情况下, 11是最相似的对,因为它们的值最大9 I need to use the pairwise distance matrix to perform clustering. 我需要使用成对距离矩阵来执行聚类。 I need a way to convert the large values into small values that can be used by a clustering method. 我需要一种将大值转换为可以由聚类方法使用的小值的方法。

If I understand correctly, you just need to reverse the sort order of the elements. 如果我理解正确,则只需要反转元素的排序顺序即可。 The following equation converts the biggest elements into the smallest elements of a new matrix and vice-versa: 以下等式将新矩阵的最大元素转换为最小元素,反之亦然:

distance = max(max(D))*ones(size(D)) - D

where D is the matrix from your custom distance function. 其中D是自定义距离函数的矩阵。 For your example above, this would result in 对于上面的示例,这将导致

9 9 9   0 4 6   9 5 3
9 9 9 - 5 9 7 = 4 0 2
9 9 9   2 1 4   7 8 5

If you know that there are no negative numbers in your custom distance matrix, you could instead use the following equation, which simply offsets all elements of your matrix (to avoid division by zero) and them inverts them: 如果您知道自定义距离矩阵中没有负数,则可以改用以下方程式,该方程式仅使矩阵的所有元素偏移(以避免除以零)并将它们求逆:

distance = 1./(D+1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM