public final class KendallTauDistance extends Object
Kendall Tau distance is sometimes also known as bubble sort distance, as it is the number of adjacent swaps necessary to transform one permutation into the other.
Another way of describing it is the number of pairs of elements whose order is inverted in one permutation relative to the other.
For example, consider p1 = [0, 1, 2, 3, 4] and p2 = [0, 3, 2, 1, 4]. The length is 5, so there are a total of 5*4/2 = 10 pairs of elements. 0 precedes all of 1, 2, 3, and 4 in both permutations. However, 1 precedes 2, 3, and 4 in p1, but only 4 in p2, so 2 adjacent swaps are needed for element 1. Elements 2 and 3 are in one order in p1, but switched in p2 relative to p1. So a total of 3 adjacent swaps are needed to transform p1 to p2. Kendall Tau distance is thus 3.
Kendall originally normalized the distance, but more recently many do not. Our implementation does not normalize.
Runtime: O(n lg n), where n is the permutation length. This runtime is achieved using a modified version of mergesort to count the inversions.
Kendall Tau distance originally described in:
M. G. Kendall, "A new measure of rank correlation," Biometrika, vol. 30, no. 1/2, pp. 81–93, June 1938.
| Constructor and Description |
|---|
KendallTauDistance()
Constructs the distance measurer as specified in the class documentation.
|
| Modifier and Type | Method and Description |
|---|---|
int |
distance(Permutation p1,
Permutation p2)
Measures the distance between two permutations.
|
double |
distancef(Permutation p1,
Permutation p2)
Measures the distance between two permutations
|
int |
max(int length)
Computes the maximum possible distance between permutations
of a specified length.
|
double |
maxf(int length)
Computes the maximum possible distance between permutations
of a specified length.
|
double |
normalizedDistance(Permutation p1,
Permutation p2)
Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
|
public KendallTauDistance()
public int distance(Permutation p1, Permutation p2)
p1 - first permutationp2 - second permutationpublic int max(int length)
length - Permutation length.public final double distancef(Permutation p1, Permutation p2)
distancef in interface PermutationDistanceMeasurerDoublep1 - first permutationp2 - second permutationpublic final double maxf(int length)
maxf in interface NormalizedPermutationDistanceMeasurerDoublelength - Permutation length.public final double normalizedDistance(Permutation p1, Permutation p2)
Measures the distance between two permutations, normalized to the interval [0.0, 1.0].
normalizedDistance in interface NormalizedPermutationDistanceMeasurerDoublep1 - first permutationp2 - second permutationCopyright © 2005-2020 Vincent A. Cicirello. All rights reserved.