0% found this document useful (0 votes)
3 views

Edit Distance

Uploaded by

divyamanjari1604
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Edit Distance

Uploaded by

divyamanjari1604
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Minimu

m Edit Definition of Minimum Edit


Distance Distance
How similar are two strings?

Spell correction • Computational Biology


◦ The user typed “graffe” • Align two sequences of nucleotides
Which is closest? AGGCTATCACCTGACCTCCAGGCCGATGCCC
◦ graf TAGCTATCACGACCGCGGTCGATTTGCCCGAC
◦ graft • Resulting alignment:
◦ grail
◦ giraffe -AGGCTATCACCTGACCTCCAGGCCGA--TGCCC---
TAG-CTATCAC--GACCGC--GGTCGATTTGCCCGAC

• Also for Machine Translation, Information Extraction, Speech Recognition


Edit Distance
Natural language processing is concerned with measuring how similar two
strings are.

The minimum edit distance between two strings


Is the minimum number of editing operations
◦ Insertion
◦ Deletion
◦ Substitution

Needed to transform one into the other

Minimum edit distance between two strings is defined as the minimum number
of editing operations (operations like insertion, deletion, substitution) needed
to transform one string into another.
Minimum Edit Distance
Two strings and their alignment: Given two sequences, an alignment is a
correspondence between substrings of the two sequences.

The Levenshtein distance between two sequences is the simplest weighting


factor in which each of the three operations has a cost

If each operation has cost of 1


Distance between these is 5

If substitutions cost 2 (Levenshtein)


Distance between them is 8
How to find the Min Edit Distance?
Searching for a path (sequence of edits) from the start string to the final
string:
◦ Initial state: the word we’re transforming
◦ Operators: insert, delete, substitute
◦ Goal state: the word we’re trying to get to
◦ Path cost: what we want to minimize: the number of edits
shortest path of transformed words that represents the minimum edit
distance between the strings intention and execution
Defining the minimum edit distance
Given two strings,
the source string X of length n,
and target string Y of length m,
we’ll define D[i, j] as the edit distance between X[1..i] and Y[1.. j],
i.e., the first i characters of X and
the first j characters of Y.

•The edit distance between X and Y is thus D[n,m].

•We’ll use dynamic programming to compute D[n,m] bottom up, combining solutions to
sub problems.
The value of D[i, j] is computed by taking the minimum of the three possible paths through
the matrix which arrive there:

If we assume the version of Levenshtein distance in which the insertions and deletions
each have a cost of 1 (ins-cost(·) = del-cost(·) = 1), and substitutions have a cost of 2
(except substitution of identical letters have zero cost), the computation for D[i,j] becomes:
Min Edit Distance Algorithm
Dynamic Programming for Minimum Edit Distance

Dynamic programming: A tabular computation of D(n,m)


Solving problems by combining solutions to
subproblems.
Bottom-up
◦ We compute D(i,j) for small i,j
◦ And compute larger D(i,j) based on previously computed
smaller values
◦ i.e., compute D(i,j) for all i (0 < i < n) and j (0 < j < m)
The Edit Distance Table
N 9
O 8
I 7

T 6
N 5
E 4
T 3
N 2
I 1
# 0 1 2 3 4 5 6 7 8 9
# E X E C U T I O N
The Edit Distance Table
N 9
O 8
I 7
T 6
N 5
E 4
T 3
N 2
I 1
# 0 1 2 3 4 5 6 7 8 9
# E X E C U T I O N
Edit Distance
N 9
O 8
I 7

T 6
N 5
E 4
T 3
N 2
I 1
# 0 1 2 3 4 5 6 7 8 9
# E X E C U T I O N
The Edit Distance Table
N 9 8 9 10 11 12 11 10 9 8
O 8 7 8 9 10 11 10 9 8 9
I 7 6 7 8 9 10 9 8 9 10
T 6 5 6 7 8 9 8 9 10 11
N 5 4 5 6 7 8 9 10 11 10
E 4 3 4 5 6 7 8 9 10 9
T 3 4 5 6 7 8 7 8 9 8
N 2 3 4 5 6 7 8 7 8 7
I 1 2 3 4 5 6 7 6 7 8
# 0 1 2 3 4 5 6 7 8 9
# E X E C U T I O N
Minimu
m Edit Back trace for Computing
Alignments
Distance
Computing alignments

Edit distance isn’t sufficient


◦ We often need to align each character of the two strings to
each other
We do this by keeping a “backtrace”
Every time we enter a cell, remember where we came
from
When we reach the end,
◦ Trace back the path from the upper right corner to read off
the alignment
MinEdit with Backtrace
starting at the 8 in the lower-right corner and following the arrows back.
The sequence of bold cells represents one possible minimum cost alignment
between the two strings.
Result of Backtrace
Two strings and their alignment:
Performance

Time:
O(nm)
Space:
O(nm)
Backtrace
O(n+m)

You might also like