1 / 104

Two Different Approximate String Matching Problems and Their Algorithms

Two Different Approximate String Matching Problems and Their Algorithms. Speakers: C. W. Lu and Y. K. Shie Advisor: Richard Chia-Tung Lee. Two different definitions of approximate string matching problem:

arin
Télécharger la présentation

Two Different Approximate String Matching Problems and Their Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two Different Approximate String Matching Problems and Their Algorithms Speakers: C. W. Lu and Y. K. Shie Advisor: Richard Chia-Tung Lee

  2. Two different definitions of approximate string matching problem: • Given a text , a pattern and a error bound k, find all the substrings of T whose edit distances with P are less than or equal to k. (Denoted as Problem 1) • Given a text , a pattern and a error bound k, find all positions i of T such that there exists a suffix of T(1, i) whose edit distances with P are less than or equal to k. (Denoted as Problem 2)

  3. An example of Problem 1: T: a b a b c d b c d d P: abcd k = 1 Output: T(2, 6)=babcd T(4, 6)=bcd T(3, 6)=abcd T(6, 9)=dbcd T(3, 7)=abcdb T(7, 9)=bcd

  4. An example of Problem 2: T: a b a b c d b c d d P: abcd k = 1 Output: Positions of T: 6, 7 and 9.

  5. Computing the edit distance between two strings X and Y by using dynamic programming method: Let us denote this method to be DP1. (Delete) (Insert) (Substitute)

  6. Example: We can find the edit distances between all prefixes of Y and all prefixes of X from this table.

  7. Problem 1 can be solved by computing the edit distance between T(i, i+m-1+k) and P for all 0<i<n, and the time complexity is O(m2n). (m=size of P and n=size of T) • That is, for every i, we perform DP1 on T(i, i+m-1+k) and P, for i=1 to n. • Thus, we open a window with size m+k all the time and slide the window.

  8. T: a b a b c d b c m+k P: a b c d k = 1 Output: ψ

  9. T: a b a b c d b c m+k P: a b c d k = 1 Output: T(2, 6)=babcd

  10. T: a b a b c d b c m+k P: a b c d k = 1 Output: T(3, 5)=abc T(3, 6)=abcd T(3, 7)=abcdb

  11. T: a b a b c d b c m+k P: a b c d k = 1 Output: T(4, 6)=bcd

  12. T: a b a b c d b c m+k P: a b c d k = 1 Output: ψ

  13. T: a b a b c d b c m+k P: a b c d k = 1 Output: ψ

  14. Some algorithms try to avoid exhaustive computing in this way. • For example, Navarro and Baeza-Yates Algorithm [NB2000], Fredriksson and Navarro Algorithm [FN2004], Lu and Lee Algorithm [LL2008]. We shall explain those algorithm later.

  15. Another approach which does not use this sliding window approach is the Wu and Manber Algorithm [WM92]. • Actually, in [WM92], the idea proposed in [NB2000] was mentioned, but barely, as if this is trivial.

  16. To solve Problem 2, we may use another DP algorithm, called DP2, which will be explained as follows.

  17. Given strings Y and X, computing the minimal ED(S, X) where S is a suffix of the substring Y(1, i) for all 0<i<|Y|: Let us denote this method to be DP2. Note that SE[i. 0]=i in DP1 and SE[i, 0]=0 in DP2.

  18. Example:

  19. Table (5,6)=2 indicates that there is a substring, namely accga, ending at Location 5 of Y, whose edit distance with P is the smallest, among all substrings of T ending at location 5.

  20. Example: We need to trace back if we want to know which substring of Y is our solution.

  21. If we set k=3, then from the above table, we can see that locations 4,5,6 are the solutions for Problem 2. If k=4, the solutions are 2~8.

  22. Obviously, Problem 2 can be solved by DP2, and the time complexity is O(mn). It is to be noted that we do not use any window sliding method if DP2 is used directly. • Again, if some of the positions of T could be ignored, this method would be more efficient. Some Algorithms try to do this. For example, Navarro and Baeza-Yates Algorithm [NB99], Tarhio and Ukkonen Algorithm [TU93] and Z. H. Pan’s thesis. • We shall explain them later.

  23. HN Algorithm (Bit-parallel Witnesses and their Applications to Approximate String Matching, Heikki Hyyro and Gonzalo Navarro, Algorithmica, 2005 Vol 4, No 3.) • HN Algorithm solves Problem 1. But, they also use the DP2 method. We will explain in the next slide. • For a substring S of T, they use the DP2 method to find the minimum ED(S, P’) among all substring P’ of P.

  24. HN Algorithm (This paper has not been reported yet. It is rumored Mr. Ou-Dee should study and report this. Obviously, he is busily doing some crazy things. m - k T: P: For a window of size m-k, if there exists a substring Sin this window such that its edit distance with every substring of P is greater than k, we move P to S. This rule is called Rule 5 by Lee’s group.

  25. T k=1 m-k In this case, both patterns and texts are reversed. P P P DP2: >k

  26. Both DP1 and DP2 can be improved by the LV algorithm, “Fast Parallel and Serial Approximate String Matching, G. Landau and U. Vishkin, Journal of Algorithms, Vol.10 (1989), pp.157-169.”, which takes O(nk) time complexity. • This algorithm tries not to do the entire computation of the DP table.

  27. i 1 2 3 a b c 0 0 0 0 j 1 2 b 1 1 0 1 c 2 2 1 0 • Diagonald is defined as all of the Di,j’s where d = i–j ,where Di,j is the value of (i, j) in DP table. Diagonal 2 Diagonal 0

  28. This algorithm is based on the following observations: • The values of the elements on the same diagonal are non-decreasing. • The value of every element on the diagonal dis decided by the elements on diagonals d, d-1 and d+1. Di, j-1 Di-1, j-1 substitution delete d+1 Di, j Di-1, j insert d d-1

  29. The values of the elements on the same diagonal are non-decreasing. Proof: Assume these exists a value Di, j such that Di, j>Di+1, j+1. Then, we have Di, j≧Di+1, j+1+1. By definition of DP, we have either Di+1, j+1= Di+1, j + 1 or Di+1, j+1= Di, j+1+ 1. That is, Di+1, j = Di+1, j+1-1 or Di, j+1= Di+1, j+1-1. Thus, Di, j - Di+1, j ≧2 or Di, j - Di, j+1≧2 The two cases all contradict to another property that the value of any location in the DP table can be only 1 larger than that of its neighbors.

  30. Di, j Di+1, j Di, j+1 Di+1, j+1 3 1 1 2

  31. Besides, the value of any location in the DP table can be only 1 larger than that of its neighbors. Di, j-1 Di-1, j-1 substitution delete d+1 Di, j Di-1, j insert d d-1

  32. Let us consider the following table. Question: Assuming that we have already found all locations of i and j such that Di, j=0, what is largest j on diagonal 1 such that Di, j=1? i 1 2 3 4 5 6 7 g g g t c t a 0 0 0 0 0 0 0 0 j 1 2 3 4 g 0 0 0 0 t 0 0 t 0 ? c 0 d =1

  33. Let us consider the following table. Certainly D4, 3≠0 because we have found all 0’s. D4, 3 must be greater than 0 and can be only 1 larger than D4, 2. Thus D4, 3=1. i 1 2 3 4 5 6 7 g g g t c t a 0 0 0 0 0 0 0 0 j 1 2 3 4 g 0 0 0 0 t 0 0 t 0 ? c 0 d =1

  34. i 1 2 3 4 5 6 7 g g g t c t a 0 0 0 0 0 0 0 0 j 1 2 3 4 g 0 0 0 0 t 0 0 t 0 1 c 0 ? d =1 • Question: Can D(5,4)=1? • Since T5 =P4, D5,4 =D4,3 =1. • This step can be found by a lowest common ancestor query which takes O(1) time [BF2000]. We explain it in next slide.

  35. i 1 2 3 4 5 6 7 8 g g g t c t a c j 1 2 3 4 5 0 0 0 0 0 0 0 0 0 g 0 0 0 0 t 0 0 1 t 0 1 a 0 1 a 0 d=3 Question: What is the longest common prefix of tac and taa? Answer: It is ta whose length is 2. This means that D6, 3 and D7, 4 are all 1. We find this longest common prefix by using a suffix tree.

  36. S1 S2 i 1 2 3 4 5 6 7 8 S2=tacgttaa g g g t c t a c j 1 2 3 4 5 0 0 0 0 0 0 0 0 0 S1=taa g 0 0 0 0 t 0 0 1 t 0 1 a 0 1 a 0 d=3 We concatenate the two strings gggtctac and gttaa and construct its suffix tree for finding the LCA of S1 and S2.

  37. S= gggtctacgttac ta is found. S1 S2

  38. Algorithms using the DP1 method to solve Problem 1.

  39. A Hybrid Indexing Method for Approximate String Matching Journal of Discrete Algorithms, No. 1, Vol. 1, 2000, pp. 205-239, Gonzalo Navarro and Ricardo Baeza-Yates Advisor: Prof. R. C. T. Lee Speaker: Y. K. Shieh

  40. We divide P into several pieces. After the pattern is divided, it has a property as shown in the following Lemma 1. Lemma 1 Let A and B are two strings such that ed(A,B) ≦k. Let , for any j≧1. Then at least one string appears in B with at most errors. By the above lemma, when j = k+1, we want to find whether any piece of P exactly appears in T or not.

  41. P T P1 = CA P2 = AG k = 1 After we find all probable positions in T, we verify every substring of those positions. The probable positions of T are: 3, 10, 13, 15 and 16 We use DP1 with window size m+k to verify whether any approximate string matching occurs between T and P at the above locations.

  42. The algorithm would open windows whose sizes are all equal to m+k step by step. If a window does not contain any piece of P, that window is ignored. Thus it avoids an exhaustive search.

  43. k = 1 The probable positions of T are 3, 10, 13, 15, 16 i=1. Window size=m+k m+k T P No approximate matching with k=1 found. DP1 is used.

  44. k = 1 The probable positions of T are: 3, 10, 13, 15, 16 i=2. m+k T P No approximate matching with k=1 found. DP1 is used.

  45. The probable positions of T are: 3, 10, 13, 15, 16 k = 1 i=3. m+k T P CACG is found. DP1 is used.

  46. The probable positions of T are: 3, 10, 13, 15, 16. k=1. i=4. m+k T P This window does not include any probable position. Therefore we can ignore this window.

  47. The probable positions of T are: 3, 10, 13, 15, 16. i=5. m+k T P The window does not include any probable position. Therefore we can shift the window directly.

  48. The probable positions of T are: 3, 10, 13, 15, 16 k = 1. i=12. m+k T P AAG is found. DP1 is used.

  49. Average-Optimal Multiple Approximate String Matching Kimmo Fredriksson , Gonzalo Navarro ACM Journal of Experimental Algorithmics, Vol 9, Article No. 1.4,2004, Pages 1-47 Professor R.C.T Lee Speaker K.W.Liu

  50. Our algorithm scans from the right as shown below: m - k T: P: This algorithm uses a checking window. For a checking window of size m-k, if there exists a substring Sin this window such that its edit distance with every substring of P is greater than k, we move P to S. We are using Rule 5 now.

More Related