Manhattan Distance for Permutations
Manhattan distance for permutations, scaled to values between 0 and 1:
d(x,y) = 1/r * ∑_{i=1}^n |x_i - y_i|
where n is the length of the permutations x and y, and scaling factor r=(n^2-1)/2 (if n is odd) or r=((n^2)/2 (if n is even).
distancePermutationManhattan(x, y)
x |
first permutation (integer vector) |
y |
second permutation (integer vector) |
numeric distance value
d(x,y)
, scaled to values between 0 and 1 (based on the maximum possible distance between two permutations)
x <- 1:5 y <- c(5,1,2,3,4) distancePermutationManhattan(x,y) p <- replicate(10,sample(1:5),simplify=FALSE) distanceMatrix(p,distancePermutationManhattan)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.