1 / 103

Discrete Optimization Lecture 5

Discrete Optimization Lecture 5. M. Pawan Kumar pawan.kumar@ecp.fr. Exam Question Type 1. Q. Find the distance of the shortest path from s=v 0 to all vertices in the graph using Dijkstra’s method. Show the estimate of the distance at each iteration. s. v 0. 4. 2. 1. v 1. v 4. 3. 1.

kizzy
Télécharger la présentation

Discrete Optimization Lecture 5

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. Discrete OptimizationLecture 5 M. Pawan Kumar pawan.kumar@ecp.fr

  2. Exam Question Type 1 Q. Find the distance of the shortest path from s=v0 to all vertices in the graph using Dijkstra’s method. Show the estimate of the distance at each iteration. s v0 4 2 1 v1 v4 3 1 Iteration = 1 6 v2 v5 3 5 Iteration = 2 v3 2 v6 …….. 1 7 Iteration = 8 v7

  3. Exam Question Type 2 • Q. Provide the code for the following function that implements the Floyd-Warshall algorithm in O(n3) time. • void floyd_warshall(int n, double **A, double **D); • n = number of vertices in the graph • A = nxn array to store the input, • A[i][j] = length of arc (i,j), 0 ≤ i < n, 0 ≤ j < n • D = nxn array to store the output • Use the following assumptions. • The graph has no negative length directed circuit. • If (i,j) is not an arc, A[i][j] = infinity • double **allocate_memory(int n, int m) returns an nxm array • free_memory(double **D, int n, int m) frees an nxm array • …..

  4. void floyd_warshall(int n, double **A, double **D) { double **D_prev = allocate_memory(n,n); inti, j, k; for(i=0;i<n;i++) { for(j=0;j<n;j++) { D[i][j] = A[i][j]; } } for(k=0;k<n;k++) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { D_prev[i][j] = D[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(D_prev[i][k] + D_prev[k][j] < D[i][j]) { D[i][j] = D_prev[i][k] + D_prev[k][j]; } } } } free_memory(D_prev,n,n); }

  5. Exam Question Type 3 Q. Prove that Dijkstra’s algorithm is correct when the length of the arcs is non-negative. Let l(a,b) be the length of the arc from vertex a to vertex b. Let d(a) be the current estimate of the distance from the source vertex s to the vertex a. Let dist(a) be the distance of the shortest path from the source vertex s to the vertex a. By definition, d(a) ≥ dist(a). We initialize U = V, where V is the set of all vertices. At each iteration, we choose u = argminaU d(a). We set U = U – {u}, and d(v) = min{d(v),d(u)+l(u,v)} We will show that d(u) = dist(u). At the first iteration, u = s and d(u) = 0. Since all arc lengths are non-negative, it follows that d(s) = dist(s) = 0. At iteration t, let us assume that d(u) > dist(u). There exists a shortest path s, v1,v2, … vk, u from s to u. Let i be the smallest index such that i U. d(vi) ≤ d(vi-1) + l(vi-1,vi) = dist(vi-1)+l(vi-1,vi) = dist(vi) Therefore, d(vi) = dist(vi), which implies that d(vi) < d(u). This implies that u cannot be chosen at the current iteration. Hence, by contradiction d(u) = dist(u).

  6. Outline • Interactive Image Segmentation • Minimum-Cut • From MAP Estimation to Minimum-Cut • Solving Minimum-Cut

  7. Image Segmentation How ? Pose the problem as MAP estimation.

  8. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn Random Variables Each random variable va corresponds to a pixel Set of all variables = V = {v1,v2,…,vn}

  9. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn Edges Edge (va,vb) connects two neighboring pixels. Neighbors: top, down, left and right Set of all edges = E

  10. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn Labels Label set L = {l0,l1} Label l0 corresponds to “object” Label l1 corresponds to “background”

  11. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn Labeling Labeling f: V L We say va is assigned a label lf(a) 2n Number of possible labelings?

  12. Unary Potentials θa;1 θa;0 va Create a histogram of RGB values H0(R,G,B) = number of pixels with color = (R,G,B) number of pixels

  13. Unary Potentials θa;1 θa;0 va θa;0 = -log H0(R(a),G(a),B(a)) H0(R,G,B) = number of pixels with color = (R,G,B) number of pixels

  14. Unary Potentials θa;1 θa;0 va θa;0 will be low/high?

  15. Unary Potentials θa;1 θa;0 va θa;0 will be low/high?

  16. Unary Potentials θa;1 θa;0 va Create a histogram of RGB values H1(R,G,B) = number of pixels with color = (R,G,B) number of pixels

  17. Unary Potentials θa;1 θa;0 va θa;1 = -log H1(R(a),G(a),B(a)) H0(R,G,B) = number of pixels with color = (R,G,B) number of pixels

  18. Unary Potentials θa;1 θa;0 va θa;1 will be low/high?

  19. Unary Potentials θa;1 θa;0 va θa;1 will be low/high?

  20. Pairwise Potentials θab;11 θab;01 θab;10 θab;00 va vb Neighboring pixels tend to have the same label.

  21. Pairwise Potentials 0 θab;01 θab;10 0 va vb Neighboring pixels tend to have the same label.

  22. Pairwise Potentials 0 θab;01 θab;10 0 va vb Similar color tends to imply same label. D(a,b) = difference in RGB values of a and b θab;01 = θab;10 = exp(-D(a,b)).

  23. Pairwise Potentials 0 θab;01 θab;10 0 va vb θab;01 and θab;10 will be low/high?

  24. Pairwise Potentials 0 θab;01 θab;10 0 va vb θab;01 and θab;10 will be low/high?

  25. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn Energy Function Labeling f: V L We say va is assigned a label lf(a) Q(f) = ΣaVθa;f(a) + Σ(a,b)Eθab;f(a)f(b)

  26. v1 v2 v3 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. vn MAP Estimation Labeling f: V L We say va is assigned a label lf(a) minf Q(f) = ΣaVθa;f(a) + Σ(a,b)Eθab;f(a)f(b)

  27. Outline • Interactive Image Segmentation • Minimum-Cut (A Special Case) • From MAP Estimation to Minimum-Cut • Solving Minimum-Cut

  28. Directed Graph D = (V, A) 10 v1 v2 Two important restrictions 3 2 (1) Rational arc lengths (2) Positive arc lengths v3 v4 5

  29. Cut D = (V, A) • Let V1 and V2 such that • V1 “union” V2 = V • V1 “intersection” V2 = Φ 10 v1 v2 3 2 • C is a set of arcs such that • (u,v)  A • u  V1 • v  V2 v3 v4 5 C is a cut in the digraph D

  30. Cut D = (V, A) V1 What is C? 10 v1 v2 {(v1,v2),(v1,v4)} ? 3 2 {(v1,v4),(v3,v2)} ? ✓ v3 v4 {(v1,v4)} ? 5 V2

  31. Cut D = (V, A) V1 V2 What is C? 10 v1 v2 {(v1,v2),(v1,v4),(v3,v2)} ? 3 2 ✓ {(v4,v3)} ? v3 v4 {(v1,v4),(v3,v2)} ? 5

  32. Cut D = (V, A) V2 V1 What is C? 10 v1 v2 ✓ {(v1,v2),(v1,v4),(v3,v2)} ? 3 2 {(v3,v2)} ? v3 v4 {(v1,v4),(v3,v2)} ? 5

  33. Cut D = (V, A) • Let V1 and V2 such that • V1 “union” V2 = V • V1 “intersection” V2 = Φ 10 v1 v2 3 2 • C is a set of arcs such that • (u,v)  A • u  V1 • v  V2 v3 v4 5 C is a cut in the digraph D

  34. Weight of a Cut D = (V, A) 10 v1 v2 3 Sum of length of all arcs in C 2 v3 v4 5

  35. Weight of a Cut D = (V, A) 10 v1 v2 3 w(C) = Σ(u,v)  C l(u,v) 2 v3 v4 5

  36. Weight of a Cut D = (V, A) V1 What is w(C)? 10 v1 v2 3 3 2 v3 v4 5 V2

  37. Weight of a Cut D = (V, A) V1 V2 What is w(C)? 10 v1 v2 5 3 2 v3 v4 5

  38. Weight of a Cut D = (V, A) V2 V1 What is w(C)? 10 v1 v2 15 3 2 v3 v4 5

  39. st-Cut s D = (V, A) 1 2 A source vertex “s” 10 v1 v2 A sink vertex “t” 3 2 • C is a cut such that • s  V1 • t  V2 v3 v4 5 7 t 3 C is an st-cut

  40. Weight of an st-Cut s D = (V, A) 1 2 10 v1 v2 3 w(C) = Σ(u,v)  C l(u,v) 2 v3 v4 5 7 t 3

  41. Weight of an st-Cut s D = (V, A) 1 2 What is w(C)? 10 v1 v2 3 3 2 v3 v4 5 7 t 3

  42. Weight of an st-Cut s D = (V, A) 1 2 What is w(C)? 10 v1 v2 15 3 2 v3 v4 5 7 t 3

  43. Minimum Cut Problem s D = (V, A) 1 2 Find a cut with the minimum weight !! 10 v1 v2 3 2 C* = argminC w(C) v3 v4 5 7 t 3

  44. Solvers for the Minimum-Cut Problem Augmenting Path and Push-Relabel n: #nodes m: #edges U: maximum arc length [Slide credit: Andrew Goldberg]

  45. Remember … Two important restrictions (1) Rational arc lengths (2) Positive arc lengths

  46. Cut D = (V, A) • Let V1 and V2 such that • V1 “union” V2 = V • V1 “intersection” V2 = Φ 10 v1 v2 3 2 • C is a set of arcs such that • (u,v)  A • u  V1 • v  V2 v3 v4 5 C is a cut in the digraph D

  47. st-Cut s D = (V, A) 1 2 A “source” vertex s 10 v1 v2 A “sink” vertex t 3 2 • C is a cut such that • s  V1 • t  V2 v3 v4 5 7 t 3 C is an st-cut

  48. Minimum Cut Problem s D = (V, A) 1 2 Find a cut with the minimum weight !! 10 v1 v2 3 2 C* = argminC w(C) v3 v4 5 w(C) = Σ(u,v)  C l(u,v) 7 t 3

  49. Outline • Interactive Image Segmentation • Minimum-Cut • From MAP Estimation to Minimum-Cut • Solving Minimum-Cut

  50. Overview Digraph D Energy Q One vertex per random variable + Additional vertices “s” and “t” Compute Minimum Cut va V1 implies f(a) = 0 Labeling f* V = V1 U V2 va V2 implies f(a) = 1

More Related