1 / 46

Chapter 6: Dynamic Programming Algorithms July/18/2012 Name: Xuanyu Hu Professor: Elise de Doncker

Chapter 6: Dynamic Programming Algorithms July/18/2012 Name: Xuanyu Hu Professor: Elise de Doncker. Outline. The power of DNA Sequence Comparison The Change Problem The Manhattan Tourist Problem Edit Distance. DNA Sequence Comparison.

derex
Download Presentation

Chapter 6: Dynamic Programming Algorithms July/18/2012 Name: Xuanyu Hu Professor: Elise de Doncker

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. Chapter 6: Dynamic Programming AlgorithmsJuly/18/2012Name: Xuanyu HuProfessor: Elise de Doncker

  2. Outline • The power of DNA Sequence Comparison • The Change Problem • The Manhattan Tourist Problem • Edit Distance

  3. DNA Sequence Comparison • Finding sequence similarities with genes of known function is a common approach to infer a newly sequenced gene’s function • First Success Story: In 1984 Russell Doolittle and colleagues found similarities between cancer-causing gene and normal growth factor (PDGF) gene

  4. Bring in the Bioinformaticians • Gene similarities between two genes with known and unknown function alert biologists to some possibilities • Computing a similarity score between two genes tells how likely it is that they have similar functions • Dynamic programming is a technique for revealing similarities between genes • The Change Problem is a good problem to introduce the idea of dynamic programming

  5. The Change Problem Goal: Convert some amount of money M into given denominations, using the fewest possible number of coins Input: An amount of money M, and an array of d denominations c= (c1, c2, …, cd), in a decreasing order of value (c1 > c2 > … > cd) Output: A list of d integers i1, i2, …, id such that c1i1 + c2i2 + … + cdid = M and i1 + i2 + … + id is minimal

  6. Value 1 2 3 4 5 6 7 8 9 10 Min # of coins 1 1 1 Change Problem: Example Given the denominations 1, 3, and 5, what is the minimum number of coins needed to make change for a given value? Only one coin is needed to make change for the values 1, 3, and 5

  7. Given the denominations 1, 3, and 5, what is the minimum number of coins needed to make change for a given value? Value 1 2 3 4 5 6 7 8 9 10 Min # of coins 1 2 1 2 1 2 2 2 However, two coins are needed to make change for the values 2, 4, 6, 8, and 10.

  8. Given the denominations 1, 3, and 5, what is the minimum number of coins needed to make change for a given value? Value 1 2 3 4 5 6 7 8 9 10 Min # of coins 1 2 1 2 1 2 3 2 3 2 Lastly, three coins are needed to make change for the values 7 and 9

  9. minNumCoins(M-1) + 1 minNumCoins(M-3) + 1 minNumCoins(M-5) + 1 min of minNumCoins(M) = Change Problem: Recurrence This example is expressed by the following recurrence relation:

  10. minNumCoins(M-c1) + 1 minNumCoins(M-c2) + 1 … minNumCoins(M-cd) + 1 min of minNumCoins(M) = Given the denominations c: c1, c2, …, cd, the recurrence relation is:

  11. RecursiveChange(M,c,d) • ifM = 0 • return 0 • bestNumCoins infinity • for i 1 to d • ifM ≥ ci • numCoins RecursiveChange(M – ci , c, d) • ifnumCoins + 1 < bestNumCoins • bestNumCoins numCoins + 1 • returnbestNumCoins

  12. RecursiveChange Is Not Efficient • It recalculates the optimal coin combination for a given amount of money repeatedly • i.e., M = 77, c = (1,3,7): • Optimal coin combo for 70 cents is computed 9 times!

  13. The RecursiveChange Tree 77 76 74 70 75 73 69 73 71 67 69 67 63 74 72 68 68 66 62 70 68 64 68 66 62 62 60 56 72 70 66 72 70 66 66 64 60 66 64 60 . . . . . . 70 70 70 70 70

  14. We Can Do Better • We’re re-computing values in our algorithm more than once • Save results of each computation for 0 to M • This way, we can do a reference call to find an already computed value, instead of re-computing each time • Running time M*d, where M is the value of money and d is the number of denominations

  15. DPChange(M,c,d) • bestNumCoins0 0 • form 1 to M • bestNumCoinsm infinity • for i  1 to d • ifm ≥ ci • if bestNumCoinsm – ci+ 1< bestNumCoinsm • bestNumCoinsmbestNumCoinsm – ci+ 1 • returnbestNumCoinsM

  16. Manhattan Tourist Problem (MTP) Imagine seeking a path (from source to sink) to travel (only eastward and southward) with the most number of attractions (*) in the Manhattan grid Source * * * * * * * * * * * * Sink

  17. Manhattan Tourist Problem (MTP) Imagine seeking a path (from source to sink) to travel (only eastward and southward) with the most number of attractions (*) in the Manhattan grid Source * * * * * * * * * * * * Sink

  18. Manhattan Tourist Problem: Formulation Goal: Find the longest path in a weighted grid. Input: A weighted grid G with two distinct vertices, one labeled “source” and the other labeled “sink” Output: A longest path in Gfrom “source” to “sink”

  19. MTP: Dynamic Programming j 0 1 2 3 source 1 2 5 0 i 5 3 10 -5 -5 1 -5 1 5 3 -3 2 3 3 -5 2 0 0 -5 1 0 0 0 3 sink

  20. MTP: Dynamic Programming j 0 1 2 3 source 1 2 5 0 1 3 8 Done! i 5 3 10 -5 -5 1 -5 1 5 4 13 8 (showing all back-traces) 5 3 -3 2 3 3 -5 2 8 9 12 15 0 0 -5 1 0 0 0 3 8 9 9 16 S3,3 = 16

  21. si-1, j + weight of the edge between (i-1, j) and (i, j) si, j-1 + weight of the edge between (i, j-1) and (i, j) max si, j = MTP: Recurrence Computing the score for a point (i,j) by the recurrence relation: The running time is n x m for a n by mgrid (n = # of rows, m = # of columns)

  22. A2 A3 sA1 + weight of the edge (A1, B) sA2 + weight of the edge (A2, B) sA3 + weight of the edge (A3, B) max of sB = A1 B Manhattan Is Not A Perfect Grid What about diagonals? • The score at point B is given by:

  23. DAG: Directed Acyclic Graph • Since Manhattan is not a perfect regular grid, we represent it as a DAG • DAG for Dressing in the morning problem

  24. Topological Ordering • A numbering of vertices of the graph is called topological ordering of the DAG if every edge of the DAG connects a vertex with a smaller label to a vertex with a larger label • In other words, if vertices are positioned on a line in an increasing order of labels then all edges go from left to right.

  25. Topological ordering • 2 different topological orderings of the DAG

  26. Longest Path in DAG Problem • Goal: Find a longest path between two vertices in a weighted DAG • Input: A weighted DAG G with source and sink vertices • Output: A longest path in G from source to sink

  27. max of sv= Longest Path in DAG: Dynamic Programming • Suppose vertex v has indegree 3 and predecessors {u1, u2, u3} • Longest path to v from source is: • In General: • sv = maxu (su + weight of edge from uto v) su1 + weight of edge fromu1to v su2 + weight of edge fromu2to v su3+ weight of edge fromu3to v

  28. Edit Distance • Levenshtein (1966) introduced edit distance between two strings as the minimum number of elementary operations (insertions, deletions, and substitutions) to transform one string into the other d(v,w) = MIN number of elementary operations to transform v w

  29. Aligning DNA Sequences Given 2 DNA sequences v and w: n = 8 V = ATCTGATG matches mismatches insertions deletions 4 m = 7 1 W = TGCATAC 2 match 2 mismatch V W insertions indels deletions

  30. Every Path in the Grid Corresponds to an Alignment W A T C G 0 1 2 2 3 4 V = A T - G T | | | W= A T C G – 0 1 2 3 4 4 V A T G T

  31. A T T A A T A T T A T A A T T A Aligning Sequences without Insertions and Deletions: Hamming Distance Given two DNA sequences vand w : v : w: • The Hamming distance: dH(v, w) = 8 is large but the sequences are very similar

  32. T A T A A T T A A T A T T A T A Aligning Sequences with Insertions and Deletions By shifting one sequence over one position: v : -- w: -- • The edit distance: dH(v, w) = 2. • Hamming distance neglects insertions and deletions in DNA

  33. Edit Distance vs Hamming Distance Hamming distance always compares i-th letter of v with i-th letter of w V = ATATATAT W= TATATATA Hamming distance: d(v, w)=8 Computing Hamming distance is a trivial task.

  34. Edit distance may compare i-th letter of v with j-th letter of w Hamming distance always compares i-th letter of v with i-th letter of w V = - ATATATAT V = ATATATAT Just one shift Make it all line up W= TATATATA W = TATATATA Hamming distance: Edit distance: d(v, w)=8d(v, w)=2 Computing Hamming distance Computing edit distance is a trivial task is a non-trivial task

  35. Edit distance may compare i-th letter of v with j-th letter of w Hamming distance always compares i-th letter of v with i-th letter of w V = - ATATATAT V = ATATATAT W= TATATATA W = TATATATA Hamming distance: Edit distance: d(v, w)=8d(v, w)=2 (one insertion and one deletion)

  36. Edit Distance: Example TGCATAT  ATCCGAT in 5 steps TGCATAT  (delete last T) TGCATA  (delete last A) TGCAT  (insert A at front) ATGCAT  (substitute C for 3rdG) ATCCAT  (insert G before last A) ATCCGAT (Done)

  37. TGCATAT  ATCCGAT in 5 steps TGCATAT  (delete last T) TGCATA  (delete last A) TGCAT  (insert A at front) ATGCAT  (substitute C for 3rdG) ATCCAT  (insert G before last A) ATCCGAT (Done) What is the edit distance? 5?

  38. TGCATAT  ATCCGAT in 4 steps • TGCATAT  (insert A at front) • ATGCATAT  (delete 6thT) • ATGCATA  (substitute G for 5thA) • ATGCGTA  (substitute C for 3rdG) • ATCCGAT (Done) • Actually, the edit distance between them is 4

  39. The Alignment Grid • Every alignment path is from source to sink

  40. v A T C G T A C w A 1 2 3 4 5 6 7 0 T 0 G 1 T 2 T 3 A 4 T 5 6 7 Alignment as a Path in the Edit Graph 0 1 2 2 3 4 5 6 7 7 A T _ G T T A T _ A T C G T _ A _ C 0 1 2 3 4 5 5 6 6 7 (0,0) , (1,1) , (2,2), (2,3), (3,4), (4,5), (5,5), (6,6), (7,6), (7,7) - Corresponding path -

  41. v A T C G T A C w A 1 2 3 4 5 6 7 0 T 0 G 1 T 2 T 3 A 4 T 5 6 7 • and represent indels in v and w with score 0. • represent matches with score 1. • The score of the alignment path is 5.

  42. v A T C G T A C w A 1 2 3 4 5 6 7 0 T 0 G 1 T 2 T 3 A 4 T 5 6 7 Alignment as a Path in the Edit Graph Every path in the edit graph corresponds to an alignment:

  43. v A T C G T A C w A 1 2 3 4 5 6 7 0 T 0 G 1 T 2 T 3 A 4 T 5 6 7 Old Alignment 0122345677 v= AT_GTTAT_ w= ATCGT_A_C 0123455667 New Alignment 0122345677 v= AT_GTTAT_ w= ATCG_TA_C 0123445667

  44. v A T C G T A C w A 1 2 3 4 5 6 7 0 T 0 G 1 T 2 T 3 A 4 T 5 6 7 0122345677 v= AT_GTTAT_ w= ATCGT_A_C 0123455667 (0,0) , (1,1) , (2,2), (2,3), (3,4), (4,5), (5,5), (6,6), (7,6),(7,7)

  45. Conclusion and Question? • The power of DNA Sequence Comparison • The Change Problem • The Manhattan Tourist Problem • Edit Distance

  46. References 1.http://bix.ucsd.edu/bioalgorithms/presentations/Ch06_EditDist.pdf 2.http://en.wikipedia.org/wiki/Change-making_problem 3.http://chinmaylokesh.wordpress.com/2011/02/19/manhattan-tourist-problem-good-problem-to-understand-dynamic-programming/ 4.http://www.itu.dk/courses/AVA/E2005/StringEditDistance.pdf 5.http://en.wikipedia.org/wiki/DNA_sequencing 6.http://www.algorithmist.com/index.php/Coin_Change

More Related