编辑问题
在 Levenshtein Distance 算法中,这条线的作用是什么?:
d[i][j] = Minimum (d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1] + cost);
虽然它得到了所有距离中的最小值在这些值中,为什么成本添加到末尾,为什么我们在每个数组索引器(前两个参数)的末尾有 + 1?
In the Levenshtein Distance algorithm, what does this line do?:
d[i][j] = Minimum (d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1] + cost);
Although it gets the minimum of all of those values, why is cost added to the end, and why do we have + 1 at the end of each array indexer (first two parameters)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个公式:
带“min”的行是递归公式本身,其他情况是递归导致的非递归情况。
您的线路正在使用数组中的“缓存”结果。尝试将其视为:
cost
为m(a,b)
,如果a==b
则为零,并且在其他情况Here is a formula:
The line with "min" is the recursive formula itself, the others are non-recursive cases to which the recursion leads.
Your line is using "caching" the results in array. Try to look at it as at:
cost
ism(a,b)
, and it's zero ifa==b
and one in the other case摘自文章:
该算法的目的是找到将一个字符串(或列表)转换为另一个字符串的最便宜的路径。任何给定操作的“成本”都在您引用的行中考虑。在你的系统中,“删除”被认为是成本 1,“插入”也是 1,而“替换”则被认为是可变成本。
From the article:
The algorithm's purpose is to find the cheapest path to convert one string (or list) to another string. The "cost" for any given operation is considered in the line you've referenced. In yours, "deletes" are considered to be a cost of 1, "inserts" also 1, and "substitution" at a variable cost.
如果您进一步阅读,您会知道:我们可以对插入、删除和替换给予不同的惩罚成本。我们还可以根据插入、删除或替换的字符给出惩罚成本。
例如,如果您认为删除字母会导致比字母替换更大的区别
if you readed further, you'd know: We can give different penalty costs to insertion, deletion and substitution. We can also give penalty costs that depend on which characters are inserted, deleted or substituted.
you'd e.g. include some >0 cost value in the deletion part of the formula, if you suppose than a letter deletion makes a bigger difference than a letter replacement