Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
courses:cs211:winter2012:journals:jeanpaul:chaptersixsectioniii [2012/03/28 02:24] – [The Problem] mugabejcourses:cs211:winter2012:journals:jeanpaul:chaptersixsectioniii [2012/03/28 02:39] (current) – [Algorithm Analysis] mugabej
Line 27: Line 27:
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.\\
 >>>>>>>>>>>>>>>>>> Our goal is to find the a partition of minimum penalty.\\ >>>>>>>>>>>>>>>>>> Our goal is to find the a partition of minimum penalty.\\
 +=====  Designing the Algorithm =====
 +
 +>>>>>>>>>>>>>>>>>> INPUT: n, p<sub>1</sub>,...,p<sub>N</sub>, C\\
 +>>>>>>>>>>>>>>>>>> Segmented-Least-Squares()\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> M[0] = 0\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> e[0][0] = 0\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> for j = 1 to n\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> for i = 1 to j\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> e[i][j] = least square error for the segment p<sub>i</sub>,...,p<sub>j</sub>\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> for j = 1 to n\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> M[j] = min <sub>1 ≤ i ≤ j</sub> (e[i][j] + c + M[i-1])\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> return M[n]\\
 +\\ 
 +Just like the Weighted Interval Scheduling Problem, we need to find an algorithm that gives us the solution itself.\\
 +** Algorithm to give for the solution itself**
 +\\
 +>>>>>>>>>>>>>>>>>> FindSegments(j):\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if j = 0:\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> output nothing\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> else:\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Find an i that minimizes e<sub>i,j</sub> + C + M[i-1]\\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Output the segment {p<sub>i</sub>, …, p<sub>j</sub>} and the result of \\
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FindSegments(i-1)
 +>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> End if
 +
 +=====  Algorithm Analysis =====
 +\\
 +The running time of the algorithm is O(n<sup>2</sup>) since filling in the array M[j] takes us O(n) time for each j.\\
 +
 +I give this section 7/10.
 +
 +
  
courses/cs211/winter2012/journals/jeanpaul/chaptersixsectioniii.1332901495.txt.gz · Last modified: 2012/03/28 02:24 by mugabej
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0