Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:patelk:chapter6 [2018/03/26 16:29] – [6.2 Principles of Dynamic Programming: Memoization or Iteration over Subproblems] patelk | courses:cs211:winter2018:journals:patelk:chapter6 [2018/03/26 16:42] (current) – [6.3 Segmented Least Squares: Multi-way Choices] patelk | ||
|---|---|---|---|
| Line 129: | Line 129: | ||
| - for each segment, the error value of the optimal line through that segment | - for each segment, the error value of the optimal line through that segment | ||
| * as we increase the number of segments, we reduce the penalty in terms of 2, but we increase the term in terms of 1 | * as we increase the number of segments, we reduce the penalty in terms of 2, but we increase the term in terms of 1 | ||
| + | |||
| + | __Designing the Algorithm__ | ||
| + | * Polynomial number of subproblems, | ||
| + | * For segmented least squares, the last point pn belongs to a single segment in the optimal partition, and the segment begins at some earlier point pi. | ||
| + | * If we know the identity of the last segment, pi,...,pn, then we could remove those points from consideration and recursively sold the problem on the remaining points p1,...,pi-1 | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * If the last segment of the optimal partition is pi,...,pn, then the value of the optimal solution is OPT(n) = error of i through n + C + OPT(i-1) | ||
| + | * For the subproblem on the points p1,...,pj, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * we can trace back through array M to compute an optimum partition: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | **Analyzing the Algorithm** | ||
| + | * Runtime of Segmented-Least-Squares: | ||
| + | * compute the values of all the least-squares errors e of i through j (eij) | ||
| + | * O(n²) pairs (i,j) | ||
| + | * For each pair, we can compute the error e of i through j in O(n) time | ||
| + | * Algorithm has n iterations j=1,...,n. | ||
| + | * For each value, we have to determing the minimum in the recurrence to fill in the array entry M[j] | ||
| + | * Takes O(n) for each j -> total of O(n²) | ||
| + | * Runtime is O(n²), once all error values have been determined. | ||
| + | |||
| + | ==== Personal Thoughts ==== | ||
| + | |||
| + | The section did a really good job laying out the algorithms in a way that was easy to follow. I think the least squares problem is also inherently easier to understand because we have worked with similar problems in math classes before. Overall, I think the algorithms and the data structures needed to solve this problem are pretty intuitive. | ||
| + | |||
| + | Readability: | ||
| + | Interesting: | ||
| + | |||
| + | |||
| + | ---- | ||
