您的位置:首页 > 其它

Standford NLP Course(2) - Edit Distance

2015-09-01 17:35 477 查看

Minimum edit distance

How similar are two strings? letter scale / word scale

- Insertion

- Deletion

- Substitution

For two strings

X of length n

Y of length m

Define D(i,j)

the edit distance between X[1 … i] and Y[1 … j]

the edit distance between X and Y is D(n,m)

Dynamic Programming for Minimum edit distance动态规划计算最小编辑距离

Levenshtein 莱文斯顿距离

Bottom-up



1. 第一行 第一列加#,表示空字符

2. 空字符和任意x个字符距离都是x,因此第一行第一列直接填1 2 3…

3. 如果第i行第j列字母相同,比较左侧+1(insertion),下面+1(deletion),左下三个数字,取最小值

4. 如果第i行第j列字母不同,比较左侧+1,下面+1,左下+2三个数字(substitution),取最小值



Backtrace

得到距离,还需要知道它是怎么得来的

左侧:Insertion

下方:Deletion

左下:Substitution

Performance

Time: O(nm)

Space: O(mn)

Backtrace: O(m+n)

Weighted Minimum edit distance

Spell Correction: some letters are more likely to be mistyped than others

Biology: certain kinds of deletions or insertions are more likely than others



Minimum Edit Distance in Computational Biology

加了两种情况

所求的不是两者间的距离,而是两者的相似度

可以掐头去尾

但从视频里看更多地用于基因链条分析等等,算法也相对类似,就不仔细贴了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nlp