public final class LeeDistance extends Object
Lee Distance is closely related to deviation distance. However, Lee Distance considers the permutation to be a cyclic structure when computing positional deviations. That is, an element's deviation between permutations is the minimum of its deviation to the right or to the left (wrapping around ends cyclicly).
Consider p1 = [0, 1, 2, 3, 4, 5] and p2 = [5, 1, 0, 2, 3, 4]. Element 0 is 2 positions displaced (as in deviation distance). Elements 2, 3, and 4 are a 1 position displaced (as in deviation distance). Element 1 is stationary. Element 5 is 1 position displaced (for Lee Distance) whereas for Deviation Distance it would be 5 positions displaced. For Lee distance, the displacement is the minimum of how far it is displaced in either of the two directions. In this case element 5 is at the right most end in p1 and left most end of p2, which as a cyclic structure are adjacent positions.
Runtime: O(n), where n is the permutation length.
Described in:
C. Lee, "Some properties of nonbinary error-correcting codes," in IRE Transactions on Information Theory, vol. 4, no. 2, pp. 77-82, June 1958.
| Constructor and Description |
|---|
LeeDistance()
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 LeeDistance()
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.