Applications of Dynamic programming ppt

dynamic programming ppt slides and dynamic programming ppt presentation
Dr.AlexanderTyler Profile Pic
Dr.AlexanderTyler,India,Teacher
Published Date:21-07-2017
Your Website URL(Optional)
Comment
6. DYNAMIC PROGRAMMING I weighted interval scheduling ‣ segmented least squares ‣ knapsack problem ‣ RNA secondary structure ‣ Lecture slides by Kevin Wayne
 Copyright © 2005 Pearson-Addison Wesley
 http://www.cs.princeton.edu/wayne/kleinberg-tardos Last updated on 2/10/16 9:26 AMAlgorithmic paradigms Greedy. Build up a solution incrementally, myopically optimizing
 some local criterion.
 Divide-and-conquer. Break up a problem into independent subproblems,
 solve each subproblem, and combine solution to subproblems to form solution to original problem. 
 Dynamic programming. Break up a problem into a series of overlapping subproblems, and build up solutions to larger and larger subproblems. fancy name for caching away intermediate results in a table for later reuse 2Dynamic programming history Bellman. Pioneered the systematic study of dynamic programming in 1950s. 
 Etymology. Dynamic programming = planning over time. Secretary of Defense was hostile to mathematical research. Bellman sought an impressive name to avoid confrontation. THE THEORY OF DYNAMIC PROGRAMMING RICHARD BELLMAN 1. Introduction. Before turning to a discussion of some representa- tive problems which will permit us to exhibit various mathematical features of the theory, let us present a brief survey of the funda- mental concepts, hopes, and aspirations of dynamic programming. To begin with, the theory was created to treat the mathematical problems arising from the study of various multi-stage decision processes, which may roughly be described in the following way: We have a physical system whose state at any time / is determined by a set of quantities which we call state parameters, or state variables. At certain times, which may be prescribed in advance, or which may be determined by the process itself, we are called upon to make de- cisions which will affect the state of the system. These decisions are equivalent to transformations of the state variables, the choice of a decision being identical with the choice of a transformation. The out- come of the preceding decisions is to be used to guide the choice of future ones, with the purpose of the whole process that of maximizing some function of the parameters describing the final state. Examples of processes fitting this loose description are furnished by virtually every phase of modern life, from the planning of indus- trial production lines to the scheduling of patients at a medical clinic ; from the determination of long-term investment programs for universities to the determination of a replacement policy for ma- chinery in factories; from the programming of training policies for skilled and unskilled labor to the choice of optimal purchasing and in- ventory policies for department stores and military establishments. It is abundantly clear from the very brief description of possible applications that the problems arising from the study of these 3 processes are problems of the future as well as of the immediate present. Turning to a more precise discussion, let us introduce a small amount of terminology. A sequence of decisions will be called a policy, and a policy which is most advantageous according to some preassigned criterion will be called an optimal policy. The classical approach to the mathematical problems arising from the processes described above is to consider the set of all possible An address delivered before the Summer Meeting of the Society in Laramie on September 3, 1953 by invitation of the Committee to Select Hour Speakers for An- nual and Summer meetings; received by the editors August 27,1954. 503 Dynamic programming applications Areas. Bioinformatics. Control theory. Information theory. Operations research. Computer science: theory, graphics, AI, compilers, systems, …. ... 
 Some famous dynamic programming algorithms. Unix diff for comparing two files. Viterbi for hidden Markov models. De Boor for evaluating spline curves. Smith-Waterman for genetic sequence alignment. Bellman-Ford for shortest path routing in networks. Cocke-Kasami-Younger for parsing context-free grammars. ... 46. DYNAMIC PROGRAMMING I weighted interval scheduling ‣ segmented least squares ‣ knapsack problem ‣ RNA secondary structure ‣Weighted interval scheduling Weighted interval scheduling problem. Job j starts at s , finishes at f , and has weight or value v . j j j Two jobs compatible if they don't overlap. Goal: find maximum weight subset of mutually compatible jobs. a b c d e f g h time 0 1 2 3 4 5 6 7 8 9 10 11 6Earliest-finish-time first algorithm Earliest finish-time first. Consider jobs in ascending order of finish time. Add job to subset if it is compatible with previously chosen jobs. Recall. Greedy algorithm is correct if all weights are 1. 
 
 Observation. Greedy algorithm fails spectacularly for weighted version. b weight = 999 weight = 1 a h time 0 1 2 3 4 5 6 7 8 9 10 11 7Weighted interval scheduling Notation. Label jobs by finishing time: f ≤ f ≤ . . . ≤ f . 1 2 n 
 Def. p ( j ) = largest index i j such that job i is compatible with j.
 Ex. p(8) = 5, p(7) = 3, p(2) = 0. 1 2 3 4 5 6 7 8 time 0 1 2 3 4 5 6 7 8 9 10 11 8Dynamic programming: binary choice Notation. OPT(j) = value of optimal solution to the problem consisting of
 job requests 1, 2, ..., j. 
 Case 1. OPT selects job j. Collect profit v . j Can't use incompatible jobs p(j) + 1, p(j) + 2, ..., j – 1 . Must include optimal solution to problem consisting of remaining compatible jobs 1, 2, ..., p(j). optimal substructure property 
 (proof via exchange argument) Case 2. OPT does not select job j. Must include optimal solution to problem consisting of remaining compatible jobs 1, 2, ..., j – 1. 0 if j = 0 OPT( j) = max v + OPT( p( j)), OPT( j−1) otherwise j % 9 € Weighted interval scheduling: brute force Input: n, s1..n, f1..n, v1..n Sort jobs by finish time so that f1 ≤ f2 ≤ … ≤ fn. Compute p1, p2, …, pn. Compute-Opt(j) if j = 0 return 0. else return max(vj + Compute-Opt(pj), Compute-Opt(j–1)). 10Weighted interval scheduling: brute force Observation. Recursive algorithm fails spectacularly because of redundant subproblems ⇒ exponential algorithms. 
 Ex. Number of recursive calls for family of "layered" instances grows like Fibonacci sequence. 5 4 3 1 2 3 2 2 1 3 4 2 1 1 0 1 0 5 1 0 p(1) = 0, p(j) = j-2 recursion tree 11Weighted interval scheduling: memoization Memoization. Cache results of each subproblem; lookup as needed. Input: n, s1..n, f1..n, v1..n Sort jobs by finish time so that f1 ≤ f2 ≤ … ≤ fn. Compute p1, p2, …, pn. for j = 1 to n Mj ← empty. global array M0 ← 0. M-Compute-Opt(j) if Mj is empty Mj ← max(vj + M-Compute-Opt(pj), M-Compute-Opt(j – 1)). return Mj. 12Weighted interval scheduling: running time Claim. Memoized version of algorithm takes O(n log n) time. Sort by finish time: O(n log n). Computing p(⋅) : O(n log n) via sorting by start time.
 M-COMPUTE-OPT(j): each invocation takes O(1) time and either (i) returns an existing value Mj (ii) fills in one new entry Mj and makes two recursive calls
 Progress measure Φ = nonempty entries of M. initially Φ = 0, throughout Φ ≤ n. (ii) increases Φ by 1 ⇒ at most 2n recursive calls.
 Overall running time of M-COMPUTE-OPT(n) is O(n). ▪ 
 Remark. O(n) if jobs are presorted by start and finish times. 13Weighted interval scheduling: finding a solution Q. DP algorithm computes optimal value. How to find solution itself? A. Make a second pass. 
 
 
 Find-Solution(j) 
 if j = 0 
 return ∅. 
 else if (vj + Mpj Mj–1) 
 return j ∪ Find-Solution(pj). else 
 return Find-Solution(j–1). 
 
 
 
 
 Analysis. of recursive calls ≤ n ⇒ O(n). 14Weighted interval scheduling: bottom-up Bottom-up dynamic programming. Unwind recursion. BOTTOM-UP (n, s , …, s , f , …, f , v , …, v ) 1 n 1 n 1 n _________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ Sort jobs by finish time so that f ≤ f ≤ … ≤ f . 1 2 n Compute p(1), p(2), …, p(n). M 0 ← 0. FOR j = 1 TO n M j ← max v + M p(j) , M j – 1 . j _________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ 156. DYNAMIC PROGRAMMING I weighted interval scheduling ‣ segmented least squares ‣ knapsack problem ‣ RNA secondary structure ‣Least squares Least squares. Foundational problem in statistics. Given n points in the plane: (x , y ), (x , y ) , …, (x , y ). 1 1 2 2 n n Find a line y = ax + b that minimizes the sum of the squared error: 
 n 2 SSE = ( y − ax − b) ∑ 
 i i y i=1 
 
 
 € 
 
 x 
 
 Solution. Calculus ⇒ min error is achieved when y − a x n x y − ( x ) ( y ) ∑ ∑ ∑ ∑ ∑ i i i i i i i i i i i a = , b = 2 2 n n x − ( x ) ∑ ∑ i i i i 17 € Segmented least squares Segmented least squares. Points lie roughly on a sequence of several line segments. Given n points in the plane: (x , y ), (x , y ) , …, (x , y ) with
 1 1 2 2 n n x x ... x , find a sequence of lines that minimizes f (x). 1 2 n 
 Q. What is a reasonable choice for f (x) to balance accuracy and parsimony? goodness of fit number of lines y x 18Segmented least squares Given n points in the plane: (x , y ), (x , y ) , …, (x , y ) with x x ... x and a 1 1 2 2 n n 1 2 n constant c 0, find a sequence of lines that minimizes f (x) = E + c L: E = the sum of the sums of the squared errors in each segment. L = the number of lines. y x 19Dynamic programming: multiway choice Notation. OPT(j) = minimum cost for points p , p , …, p . 1 2 j e(i, j) = minimum sum of squares for points p , p , …, p . i i+1 j 
 To compute OPT(j): Last segment uses points p , p , …, p for some i. i i+1 j Cost = e(i, j) + c + OPT(i – 1). optimal substructure property (proof via exchange argument) 0 if j = 0 & OPT( j) = % min e(i, j) + c + OPT(i−1) otherwise & '1 ≤ i≤ j € 20