Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| courses:cs211:winter2018:journals:beckg:ch6 [2018/03/26 21:20] – created beckg | courses:cs211:winter2018:journals:beckg:ch6 [2018/03/27 03:50] (current) – beckg | ||
|---|---|---|---|
| Line 64: | Line 64: | ||
| ===== 6.3: Segmented Least Squares: Multi-way Choices ===== | ===== 6.3: Segmented Least Squares: Multi-way Choices ===== | ||
| + | For this next problem, we introduce another variable to the decision making, rather than a simple binary " | ||
| + | ==== The Problem ==== | ||
| + | Essentially, | ||
| + | * the number of segments into which we partition //P// (the full set of points) multiplied by a fixed given multiplier //C>0// | ||
| + | * for each segment, the error value of the optimal line through it. | ||
| + | So, the goal of this Segmented Least Squares Problem is to find a partition of minimal penalty. Note that varying the value of //C// and such can yield entirely different solutions. | ||
| + | |||
| + | As in the previous section, we can begin with a simple observation: | ||
| + | * OPT(n) = // | ||
| + | |||
| + | Further, we have the following recurrence for any point //j//: | ||
| + | * OPT(j) = min< | ||
| + | |||
| + | So, the algorithm that follows is thus: | ||
| + | |||
| + | Segmented-Least-Squares(n) | ||
| + | * Array M[0...n] | ||
| + | * Set M[0]=0 | ||
| + | * For all pairs i=<j: | ||
| + | * Compute the least squares error // | ||
| + | * For j=1,2,...,n | ||
| + | * Use the recurrence above to compute M[j] | ||
| + | * Return M[n] | ||
| + | |||
| + | The correctness of this algorithm can be proved with induction. We can also trace back through the array M to find the optimal partition: | ||
| + | |||
| + | Find-Segments(j) | ||
| + | * If j=0: | ||
| + | * output nothing | ||
| + | * Else: | ||
| + | * Find an i that minimizes // | ||
| + | * Output the segment from point //i// to point //j// and the result of Find-Segments(i-1) | ||
| + | |||
| + | The total running time of computing all of the // | ||
| + | |||
| + | Another very good section. They went over everything extremely well and explained the nuance thoroughly. 9/10. | ||
