Manhattan distance

Definition
Given a number set $$E$$, the Manhattan distance is a function $$ManhattanDis:E^n\times E^n \longrightarrow \mathbb{R}$$ defined as

$$ ManhattanDis(u,v)=\sum_{i=1}^{n}|u[i]-v[i]|. $$

Examples

 * $$ManhattanDis((1,2,3,4),(4,3,2,1)) = 3+1+1+3 = 8$$.
 * $$ManhattanDis((1,0,1,0,1),(1,1,0,0,1)) = 0+1+1+0+0 = 2$$.

Normalization
If $$E$$ is a bounded set, it is possible to normalize the difference dividing by the range of $$E$$, then normalization is

$$ ManhattanSim(u,v)=1-\frac{\sum_{i=1}^{n}|u[i]-v[i]|}{n}. $$

that is the arithmetic mean of the normalized differences.

Examples

 * If $$E=[0,10]$$, $$ManhattanSim((1,2,3,4),(4,3,2,1)) = 1-\frac{0.3+0.1+0.1+0.3}{4} = 0.8$$.
 * If $$E=\{0,1\}$$, $$ManhattanSim((1,0,1,0,1),(1,1,0,0,1)) = 1-\frac{0+1+1+0+0}{5} = 0.6$$.

Variations

 * Manhattan distance is a particular case of Minkowski distance when $$p=1$$.
 * If $$E=\{0,1\}$$, we have the Hamming similarity.

Applications

 * Numeric vectors (codes).
 * Vectors of boolean features.