Hamming distance |
![]() |
![]() |
![]() |
Algorithms - Similarity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Written by Jan Schulz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Thursday, 15 May 2008 19:22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hamming distance
ObjectiveThe Hamming distance (Hamming 1950) is a metric expressing the distance between two objects by the number of mismatches among their pairs of variables. It is mainly used for string and bitwise analyses, but can also be useful for numerical variables. Although the basic Hamming distance is a metric, the here presented version allows to define a threshold. Variables having an absolute difference below the threshold are considered as equal. Using values larger than 0 for this threshold the triangle inequality could be violated for some calculated distances. Using 0 as threshold it is the original and metric Hamming distance, thresholds below 0 are not defined.
EquationIn the equation dHAD is the Hamming distance between the objects i and j, k is the index of the respective variable reading y out of the total number of variables n. The Hamming distance itself gives the number of mismatches between the variables paired by k.
SynonymsThere are no common synonyms.
UsageThe Hamming distance is an important measurement for the detection of errors in information transmission (Hamming 1950). Beyond this application its usage is valuable for the investigation of e.g. ranked variables of entities coded by numerical tokens.
AlgorithmThe algorithm controls whether the data input matrix is rectangular or not. If not the function returns FALSE and a defined, but empty output matrix. When the matrix is rectangular the Hamming distance is calculated. Therefore the dimensions of the respective arrays of the output matrix and the titles for the rows and columns set. As the result is a square matrix, which is mirrored along the diagonal only values for one triangular half and the diagonal are computed. When errors occur during computation the function returns FALSE.
SourceFunction dist_Hamming (InputMatrix : t2dVariantArrayDouble; aMaxDiff: Double; Var OutputMatrix : t2dVariantArrayDouble) : Boolean;
ExampleFor a data matrix aInputMatrix of the type t2dVariantArrayDouble, populated with:
the call of: aBooleanVar := dist_Hamming (aInputMatrix, 0, aOutputMatrix); returns the respective matrix of the original Hamming distance in aOutputMatrix:
The Hamming distance simply counts the number of differences between the paired variables. Thus the distances are unaffected by the distance of the object from the origin.
LiteratureHamming R.W. (1950): Error detecting and error correcting codes. Bell System Technical Journal 26(2):147-160.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Updated on Friday, 18 March 2011 18:17 |