Class KendallTauDistance

  • All Implemented Interfaces:
    NormalizedPermutationDistanceMeasurer, NormalizedPermutationDistanceMeasurerDouble, PermutationDistanceMeasurer, PermutationDistanceMeasurerDouble

    public final class KendallTauDistance
    extends Object
    implements NormalizedPermutationDistanceMeasurer
    Kendall Tau Distance:

    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 Detail

      • KendallTauDistance

        public KendallTauDistance()
        Constructs the distance measurer as specified in the class documentation.