Minimum Edit Distance in Computational Biology

undefined
 
Minimum Edit
Distance
 
 
Definition of Minimum
Edit Distance
How similar are two strings?
 
Spell correction
The user typed “graffe”
Which is closest?
graf
graft
grail
giraffe
 
 
 
Computational Biology
Align two sequences of nucleotides
 
 
Resulting alignment:
 
Also for Machine Translation, Information Extraction, Speech Recognition
 
AGGCTATCACCTGACCTCCAGGCCGATGCCC
TAGCTATCACGACCGCGGTCGATTTGCCCGAC
 
-
AG
G
CTATCAC
CT
GACC
T
C
CA
GG
C
CGA
--
TGCCC
---
T
AG
-
CTATCAC
--
GACC
G
C
--
GG
T
CGA
TT
TGCCC
GAC
 
Edit Distance
 
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
 
Two strings and their 
alignment
:
Minimum Edit Distance
 
If each operation has cost of 1
Distance between these is 5
If substitutions cost 2 (Levenshtein)
Distance between them is 8
Alignment in Computational Biology
 
Given a sequence of bases
 
 
An alignment:
 
 
Given two sequences, align each letter to a letter or gap
 
-
AG
G
CTATCAC
CT
GACC
T
C
CA
GG
C
CGA
--
TGCCC
---
T
AG
-
CTATCAC
--
GACC
G
C
--
GG
T
CGA
TT
TGCCC
GAC
AGGCTATCACCTGACCTCCAGGCCGATGCCC
TAGCTATCACGACCGCGGTCGATTTGCCCGAC
Other uses of Edit Distance in NLP
 
Evaluating Machine Translation and speech recognition
R 
Spokesman confirms    senior government adviser was shot
H 
Spokesman said    the senior            adviser was shot dead
              S      I              D                        I
Named Entity Extraction and Entity Coreference
IBM Inc
. announced today
IBM 
profits
Stanford President John Hennessy 
announced yesterday
for 
Stanford University President John Hennessy
 
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
8
 
Minimum Edit as Search
 
But the space of all edit sequences is huge!
We can’t afford to navigate naïvely
Lots of distinct paths wind up at the same state.
We don’t have to keep track of all of them
Just the shortest path to each of those revisted states.
 
9
Defining Min Edit Distance
 
For two strings
X of length 
n
Y of length 
m
We define D(
i,j
)
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
)
undefined
 
Minimum Edit
Distance
 
 
Definition of Minimum
Edit Distance
undefined
 
Minimum Edit
Distance
 
 
Computing Minimum
Edit Distance
 
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)
 
 
Defining Min Edit Distance (Levenshtein)
Initialization
D(i,0) = i
D(0,j) = j
Recurrence Relation
:
For each  i = 1…M
 
  For each  j = 1…N
                       
D(i-1,j) + 1
          D(i,j)= min  D(i,j-1) + 1
                       D(i-1,j-1) +   2; if X(i) ≠ Y(j)
                                      0; if X(i) = Y(j)
Termination
:
D(N,M) is distance
 
The Edit Distance Table
 
The Edit Distance Table
 
Edit Distance
 
The Edit Distance Table
undefined
 
Minimum Edit
Distance
 
 
Computing Minimum
Edit Distance
undefined
 
Minimum Edit
Distance
 
 
Backtrace for
Computing Alignments
 
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
 
Edit Distance
 
MinEdit with Backtrace
 
Adding Backtrace to Minimum Edit Distance
 
Base conditions:                                                        Termination:
D(i,0) = i         D(0,j) = j         D(N,M) is distance
Recurrence Relation
:
For each  i = 1…M
 
 For each  j = 1…N
                      
D(i-1,j) + 1
         D(i,j)= min  D(i,j-1) + 1
                      D(i-1,j-1) +  2; if X(i) ≠ Y(j)
                                    0; if X(i) = Y(j)
                     LEFT
         ptr(i,j)=   DOWN
                     DIAG
insertion
deletion
substitution
insertion
deletion
substitution
The Distance Matrix
Slide adapted from Serafim Batzoglou
y
0
 ………………………………  y
M
x
0
 ……………………  x
N
 
Every non-decreasing path
from (0,0) to (M, N)
corresponds to
an alignment
of the two sequences
 
An optimal alignment is composed
of optimal subalignments
 
Result of Backtrace
 
Two strings and their 
alignment
:
Performance
 
Time:
    
O(nm)
Space:
    
O(nm)
Backtrace
    
O(n+m)
undefined
 
Minimum Edit
Distance
 
 
Backtrace for
Computing Alignments
undefined
 
Minimum Edit
Distance
 
 
Weighted Minimum Edit
Distance
 
Weighted Edit Distance
 
Why would we add weights to the computation?
Spell Correction: some letters are more likely to be mistyped than others
Biology: certain kinds of deletions or insertions are more likely than
others
 
Confusion matrix for spelling errors
 
Weighted Min Edit Distance
Initialization:
D(0,0) = 0
D(i,0) = D(i-1,0) + del[x(i)];    1 < i ≤ N
D(0,j) = D(0,j-1) + ins[y(j)];    1 < j ≤ M
Recurrence Relation
:
             
D(i-1,j)   + del[x(i)]
D(i,j)= min  D(i,j-1)   + ins[y(j)]
             D(i-1,j-1) + sub[x(i),y(j)]
Termination
:
D(N,M) is distance
 
W
h
e
r
e
 
d
i
d
 
t
h
e
 
n
a
m
e
,
 
d
y
n
a
m
i
c
p
r
o
g
r
a
m
m
i
n
g
,
 
c
o
m
e
 
f
r
o
m
?
 
The 1950s were not good years for mathematical research. [the] Secretary of
Defense …had a pathological fear and hatred of the word, research…
 
I
 
d
e
c
i
d
e
d
 
t
h
e
r
e
f
o
r
e
 
t
o
 
u
s
e
 
t
h
e
 
w
o
r
d
,
 
p
r
o
g
r
a
m
m
i
n
g
.
 
I
 
w
a
n
t
e
d
 
t
o
 
g
e
t
 
a
c
r
o
s
s
 
t
h
e
 
i
d
e
a
 
t
h
a
t
 
t
h
i
s
 
w
a
s
 
d
y
n
a
m
i
c
,
 
t
h
i
s
 
w
a
s
 
m
u
l
t
i
s
t
a
g
e
 
I
 
t
h
o
u
g
h
t
,
l
e
t
s
 
 
t
a
k
e
 
a
 
w
o
r
d
 
t
h
a
t
 
h
a
s
 
a
n
 
a
b
s
o
l
u
t
e
l
y
 
p
r
e
c
i
s
e
 
m
e
a
n
i
n
g
,
 
n
a
m
e
l
y
 
d
y
n
a
m
i
c
 
i
t
s
i
m
p
o
s
s
i
b
l
e
 
t
o
 
u
s
e
 
t
h
e
 
w
o
r
d
,
 
d
y
n
a
m
i
c
,
 
i
n
 
a
 
p
e
j
o
r
a
t
i
v
e
 
s
e
n
s
e
.
 
T
r
y
 
t
h
i
n
k
i
n
g
 
o
f
 
s
o
m
e
c
o
m
b
i
n
a
t
i
o
n
 
t
h
a
t
 
w
i
l
l
 
p
o
s
s
i
b
l
y
 
g
i
v
e
 
i
t
 
a
 
p
e
j
o
r
a
t
i
v
e
 
m
e
a
n
i
n
g
.
 
I
t
s
 
i
m
p
o
s
s
i
b
l
e
.
 
Thus, I thought dynamic programming was a good name. It was something not even a
Congressman could object to.”
 
R
i
c
h
a
r
d
 
B
e
l
l
m
a
n
,
 
E
y
e
 
o
f
 
t
h
e
 
H
u
r
r
i
c
a
n
e
:
 
a
n
 
a
u
t
o
b
i
o
g
r
a
p
h
y
 
1
9
8
4
.
undefined
 
Minimum Edit
Distance
 
 
Weighted Minimum Edit
Distance
Slide Note
Embed
Share

Dan Jurafsky explains the concept of minimum edit distance as the minimum number of editing operations such as insertion, deletion, and substitution needed to transform one string into another. Through examples and visual representations, he illustrates how minimum edit distance plays a crucial role in tasks like spell correction, aligning nucleotide sequences, machine translation, information extraction, and speech recognition in computational biology and natural language processing.

  • Minimum Edit Distance
  • Computational Biology
  • Dan Jurafsky
  • Spell Correction
  • NLP

Uploaded on Sep 09, 2024 | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Minimum Edit Distance Definition of Minimum Edit Distance

  2. Dan Jurafsky How similar are two strings? Spell correction The user typed graffe Which is closest? graf graft grail giraffe Computational Biology Align two sequences of nucleotides AGGCTATCACCTGACCTCCAGGCCGATGCCC TAGCTATCACGACCGCGGTCGATTTGCCCGAC Resulting alignment: -AGGCTATCACCTGACCTCCAGGCCGA--TGCCC--- TAG-CTATCAC--GACCGC--GGTCGATTTGCCCGAC Also for Machine Translation, Information Extraction, Speech Recognition

  3. Dan Jurafsky Edit Distance The minimum edit distance between two strings Is the minimum number of editing operations Insertion Deletion Substitution Needed to transform one into the other

  4. Dan Jurafsky Minimum Edit Distance Two strings and their alignment:

  5. Dan Jurafsky Minimum Edit Distance If each operation has cost of 1 Distance between these is 5 If substitutions cost 2 (Levenshtein) Distance between them is 8

  6. Dan Jurafsky Alignment in Computational Biology Given a sequence of bases AGGCTATCACCTGACCTCCAGGCCGATGCCC TAGCTATCACGACCGCGGTCGATTTGCCCGAC An alignment: -AGGCTATCACCTGACCTCCAGGCCGA--TGCCC--- TAG-CTATCAC--GACCGC--GGTCGATTTGCCCGAC Given two sequences, align each letter to a letter or gap

  7. Dan Jurafsky Other uses of Edit Distance in NLP Evaluating Machine Translation and speech recognition R Spokesman confirms senior government adviser was shot H Spokesman said the senior adviser was shot dead S I D I Named Entity Extraction and Entity Coreference IBM Inc. announced today IBM profits Stanford President John Hennessy announced yesterday for Stanford University President John Hennessy

  8. Dan Jurafsky 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 8

  9. Dan Jurafsky Minimum Edit as Search But the space of all edit sequences is huge! We can t afford to navigate na vely Lots of distinct paths wind up at the same state. We don t have to keep track of all of them Just the shortest path to each of those revisted states. 9

  10. Dan Jurafsky Defining Min Edit Distance For two strings X of length n Y of length m We define D(i,j) 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)

  11. Minimum Edit Distance Definition of Minimum Edit Distance

  12. Minimum Edit Distance Computing Minimum Edit Distance

  13. Dan Jurafsky 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)

  14. Dan Jurafsky Defining Min Edit Distance (Levenshtein) Initialization D(i,0) = i D(0,j) = j Recurrence Relation: For each i = 1 M For each j = 1 N D(i-1,j) + 1 D(i,j)= min D(i,j-1) + 1 D(i-1,j-1) + 2; if X(i) Y(j) 0; if X(i) = Y(j) Termination: D(N,M) is distance

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

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

  17. Dan Jurafsky Edit Distance N O I 9 8 7 T N E T N I # 6 5 4 3 2 1 0 # 1 E 2 X 3 E 4 C 5 U 6 T 7 I 8 O 9 N

  18. Dan Jurafsky The Edit Distance Table N O I T N E T N I # 9 8 7 6 5 4 3 2 1 0 # 8 7 6 5 4 3 4 3 2 1 E 9 8 7 6 5 4 5 4 3 2 X 10 9 8 7 6 5 6 5 4 3 E 11 10 9 8 7 6 7 6 5 4 C 12 11 10 9 8 7 8 7 6 5 U 11 10 9 8 9 8 7 8 7 6 T 10 9 8 9 10 9 8 7 6 7 I 9 8 9 10 11 10 9 8 7 8 O 8 9 10 11 10 9 8 7 8 9 N

  19. Minimum Edit Distance Computing Minimum Edit Distance

  20. Minimum Edit Distance Backtrace for Computing Alignments

  21. Dan Jurafsky 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

  22. Dan Jurafsky Edit Distance N O I 9 8 7 T N E T N I # 6 5 4 3 2 1 0 # 1 E 2 X 3 E 4 C 5 U 6 T 7 I 8 O 9 N

  23. Dan Jurafsky MinEdit with Backtrace

  24. Dan Jurafsky Adding Backtrace to Minimum Edit Distance Base conditions: Termination: D(i,0) = i D(0,j) = j D(N,M) is distance Recurrence Relation: For each i = 1 M For each j = 1 N D(i-1,j) + 1 D(i,j)= min D(i,j-1) + 1 D(i-1,j-1) + 2; if X(i) Y(j) 0; if X(i) = Y(j) LEFT ptr(i,j)= DOWN DIAG substitution deletion insertion substitution insertion deletion

  25. Dan Jurafsky The Distance Matrix x0 xN Every non-decreasing path from (0,0) to (M, N) corresponds to an alignment of the two sequences An optimal alignment is composed of optimal subalignments y0 yM Slide adapted from Serafim Batzoglou

  26. Dan Jurafsky Result of Backtrace Two strings and their alignment:

  27. Dan Jurafsky Performance Time: Space: Backtrace O(nm) O(nm) O(n+m)

  28. Minimum Edit Distance Backtrace for Computing Alignments

  29. Minimum Edit Distance Weighted Minimum Edit Distance

  30. Dan Jurafsky Weighted Edit Distance Why would we add weights to the computation? Spell Correction: some letters are more likely to be mistyped than others Biology: certain kinds of deletions or insertions are more likely than others

  31. Dan Jurafsky Confusion matrix for spelling errors

  32. Dan Jurafsky

  33. Dan Jurafsky Weighted Min Edit Distance Initialization: D(0,0) = 0 D(i,0) = D(i-1,0) + del[x(i)]; 1 < i N D(0,j) = D(0,j-1) + ins[y(j)]; 1 < j M Recurrence Relation: D(i-1,j) + del[x(i)] D(i,j)= min D(i,j-1) + ins[y(j)] D(i-1,j-1) + sub[x(i),y(j)] Termination: D(N,M) is distance

  34. Dan Jurafsky Where did the name, dynamic programming, come from? The 1950s were not good years for mathematical research. [the] Secretary of Defense had a pathological fear and hatred of the word, research I decided therefore to use the word, programming . I wanted to get across the idea that this was dynamic, this was multistage I thought, let s take a word that has an absolutely precise meaning, namely dynamic it s impossible to use the word, dynamic, in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It s impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. Richard Bellman, Eye of the Hurricane: an autobiography 1984.

  35. Minimum Edit Distance Weighted Minimum Edit Distance

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#