You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# In the above example, when we call _best_match(1, 1).# value information:# self.edit_matrix[row][col].bounds() = (2,2)# self.edit_matrix[0][col].bounds() = (2,2)# ucost = (2, 1)# dcost = (0, 0)# lcost = (1, 1)
brow = row, bcol = col-1 (condition3 success) because self.edit_matrix[row][col].bounds() == self.edit_matrix[0][col].bounds() (condition1 fail) and ucost > dcost (condition2 fail).
But actually self.costs[row][col-1] + self.edit_matrix[0][col].bounds().upper_bound > self.costs[row-1][col-1] + self.edit_matrix[row][col].bounds().upper_bound. The optimal self.costs[row][col] should be self.costs[row-1][col-1] + self.edit_matrix[row][col].bounds().upper_bound.
Here is a fix (success in the above example, may need further testing):
output:
But the minimal cost should be 3.
output:
I found the problem is in
EditDistance._best_match
:brow = row, bcol = col-1
(condition3 success) becauseself.edit_matrix[row][col].bounds() == self.edit_matrix[0][col].bounds()
(condition1 fail) anducost > dcost
(condition2 fail).But actually
self.costs[row][col-1] + self.edit_matrix[0][col].bounds().upper_bound > self.costs[row-1][col-1] + self.edit_matrix[row][col].bounds().upper_bound
. The optimalself.costs[row][col]
should beself.costs[row-1][col-1] + self.edit_matrix[row][col].bounds().upper_bound
.Here is a fix (success in the above example, may need further testing):
In summary, we should use the final real cost to guide transition. Like the canonical implementation of the Levenshtein distance metric:
If this is a bug, I would be happy to provide a PR.
The text was updated successfully, but these errors were encountered: