I do not understand how the values in the levenshtein matrix is calculated According to this article. I do know how we arrive at the edit distance of 3. Could someone explain in lay man terms how we arrive at each value in each cell?
levenshtein matrix cell calculation
247 views Asked by jxn At
2
There are 2 answers
0
On
Hover your mouse above each value with the dots underneath in that matrix in the wikipedia article and it describes in layman's terms what each value means.
e.g. using (x,y)
notation
- element
(0,0)
comparesNone
toNone
.(0,0) = 0
because they are equal - element
(0,1)
compares'k'
toNone
.(0,1) = 1
because:insert 'k'
to transformNone
to'k'
so+1
- element
(3,2)
compares'kit'
to'si'
.(3,2) = 2
because of ``None
==None
so+0
-Lev = 0
see element(0,0)
swap 's','k'
so+1
-Lev = 1
see element(1,1)
'i' == 'i'
so+0
-Lev = 1
see element(2,2)
insert 't'
so+1
-Lev = 2
see element(3,2)
Hi I just had a look at the link of the Wikipedia article you shared:
The way the matrix is built is described in "Definition". Now I will just translate that into what it means and what you need to do to built the matrix all by yourself:
Just to be sure that no basic information is missing: i denotes the row number and j denotes the column number.
So lets start with the first definition line of the matrix: It says that the matrix is max(i, j), if min(i,j) = 0 The condition will be fulfilled only for elements of the 0-th row and the 0-th column. (Then min(0, j) is 0 and min(i, 0) is 0). So for the 0-th row and the 0-th column you enter the value of max(i,j), which corresponds to the row number for the 0-th column and the column number for the 0-th row. So far so good:
All the other values are built as the minimum of one of these three values:
Where lev corresponds to the already existing levenshtein matrix elements. The lev(i, j-1) is simply the matrix component to the left of the one, that we want to determine. lev(i-1, j) is the component above and lev(i-1, j-1) is the element left and above. Here, 1_(a_i != b_i) means, that if the letters on this space do not equal 1 is added, otherwise 0.
If we jump right into the matrix element (1, 1), wich corresponds to letters (s, k): We determine the 3 components:
Now, we take the minimum of these three values and we found the next entry of the Levenshtein matrix.
Do this evaluation for each single element row OR columnwise and the result is the full Levenshtein matrix.