简体   繁体   中英

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. 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 . In my case the 1 and 1 are the most similar pair, since they have the largest value 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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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