cs3000: algorithms & data jonathan ullman · 2018-12-06 · image segmentation •separate...

30
CS3000: Algorithms & Data Jonathan Ullman Lecture 21: More Applications of Network Flow Nov 30, 2018

Upload: others

Post on 05-Jan-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

CS3000:Algorithms&DataJonathanUllman

Lecture21:MoreApplicationsofNetworkFlow

Nov30,2018

Page 2: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ImageSegmentation

Page 3: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ImageSegmentation

• Separateimageintoforegroundandbackground• Wehavesomeideaof:• whetherpixeliisintheforegroundorbackground• whetherpair(i,j)arelikelytogotogether

Page 4: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ImageSegmentation

• Input:• adirectedgraph! = ($, &);$ =“pixels”,& =“pairs”• likelihoods(), *) ≥ 0 forevery- ∈ $• separationpenalty/)0 ≥ 0 forevery -, 1 ∈ &

• Output:• apartitionof$ into 2, 3 thatmaximizes

4 2, 3 = 6()�

)∈8+6*0

0∈:− 6 /)0

),0 ∈<=>?@8A?:

O O OI F IOes O O OF I I0 O O O

foreggand background

Lquality

Page 5: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• DifferencesbetweenSEGandMINCUT:• SEGasksustomaximize,MINCUTasksustominimize

• SEG allowsanypartition,MINCUTrequiresB ∈ 2,C ∈ 3

max8,: 6()�

)∈8+6*0

0∈:− 6 /)0

),0 ∈<=>?@8A?:

min8,: 6*)�

)∈8+6(0

0∈:+ 6 /)0

),0 ∈<=>?@8A?:

max g ASB nfib g ASBA B

miner graph has nodeVoss 13

MinA B partitioning

cap A0553 Bose

Add two nodes sit

Page 6: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• Howshouldthereductionwork?• capacityofthecutshouldcorrespondtothefunctionwe’retryingtominimize

min8,: 6*)�

)∈8+6(0

0∈:+ 6 /)0

),0 ∈<=>?@8A?:

min 2 cap i ji j EEA B fromA to B

Page 7: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• Howshouldthereductionwork?• capacityofthecutshouldcorrespondtothefunctionwe’retryingtominimize

min8,: 6*)�

)∈8+6(0

0∈:+ 6 /)0

),0 ∈<=>?@8A?:

A AB cap Auss Busts

IzabitjEsa's PijfromAtoB

Assume Gonly has nodes

i j3

Page 8: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• Howshouldthereductionwork?• capacityofthecutshouldcorrespondtothefunctionwe’retryingtominimize

min8,: 6*)�

)∈8+6(0

0∈:+ 6 /)0

),0 ∈<=>?@8A?:

A B

so

Page 9: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step1:TransformtheInput

InputG,{a,b,p}forSEG

InputG’forMINCUT

so

time 0 mtn

Page 10: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step2:ReceivetheOutput

Solve

InputG’forMINCUT

Output(A,B)forMINCUTA

time time to solveMsn art on a graph

ath

Nt 2 nodes

B2n t m edges

0 nm time

Page 11: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step3:TransformtheOutput

Output(A,B)forSEG

Output(A,B)forMINCUT

i

on

Page 12: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• correctness?

• runningtime?

Max gCA BA B

itransform its Y 3 thief D0 ntm t O nm t 0 n

O nm

Page 13: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

DensestSubgraph

Page 14: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ImageSegmentation

• Wanttoidentifycommunitiesinanetwork• “Community”:asetofnodesthathavealotofconnectionsinsideandfewoutside

MMMMMMMe Community Detection

Page 15: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

DensestSubgraph

• Input:• anundirectedgraph! = $, &

• Output:• asubsetofnodes2 ⊆ $ thatmaximizesJ < 8,8

|8|

Fund AB

E AB u u c E o UEA E B

IECA A I

why not maxmax.m.zed.by on edgeA

Page 16: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut• Differentobjectives

• find 2, 3 tomaximizeJ < 8,88

• find 2, 3 tominimize & 2, 3

• SupposeJ < 8,88 ≥ Landseewhatthatimplies

⇔ 2 & 2, 2 ≥ L 2⇔ ΣP∈8 deg T − & 2, 3 ≥ L 2⇔ ΣP∈U deg T − ΣP∈: deg T − & 2, 3 ≥ L 2⇔ 2 & − ΣP∈: deg T − & 2, 3 ≥ L 2⇔ ΣP∈: deg T + L 2 + & 2, 3 ≤ 2 &

We will solve the yeshoquestion is there a communitywith density s S

r

Mincut if c e i

Ea ai t.E.bit.ci eeiaiii

Page 17: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut

ΣP∈WX deg T + Y Z + & Z, Z[ ≤ 2 &

Ive the yeshoquestion is there a communitywith density 8

MinCut if c e i

Ea ai Fersbi t.ci eeiaiiiO

If deg v

21ECA A IIECA B I

Page 18: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

ReductiontoMinCut

ΣP∈WX deg T + Y Z + & Z, Z[ ≤ 2 &

We will solve the yeshoquestion is there a communitywith density s S

r

Mincut if c e i

Ea ai t.E.bit.ci eeiaiij

Zpsdeg r uEa8 e.iFeECaiD I

Page 19: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Edge-DisjointPaths

Ezeizagsxoffft ff ffff.BE

Page 20: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

(Edge)DisjointPaths• Input: directedgraph! = $, &, B, C• Output: alargestsetofedge-disjoints-tpaths• Asetofs-tpaths\],… , \_ isedgedisjointifthepathsdonotshareanyedges

Alargesetofdisjointpathsmeanswecantolerateedgefailures.

s t

EBAY.IR tHBF AfEfsd2E

Page 21: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

BipartiteMatching

• Thereisareductionthatusesintegermaximums-tflow tosolveedgedisjointpaths.

Page 22: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step1:TransformtheInput

InputGforEDP InputG’forMAXFLOW

s t s t

Page 23: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step2:ReceivetheOutput

SolveA

InputG’forMAXFLOW

OutputfforMAXFLOW

Red arrowmeansf(e)=1Blackmeans f(e)=0

s t

Page 24: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step3:TransformtheOutput

OutputMforMCBM

OutputfforMAXFLOW

Page 25: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Correctness• EasyDirection:Iftherearekedgedisjointpathsthenthereisaflowofvaluek

s t

Page 26: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Correctness• HarderDirection:Ifthereisaflowofvaluek,thentherearekedgedisjointpaths

s t

Page 27: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

RunningTime• Needtoanalyzethetimefor:• (1)ProducingG’givenG• (2)FindingamaximumflowinG’• (3)ProducingMgivenG’

Page 28: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Summary

• CansolveedgedisjointpathsintimeO(nm)usingFord-Fulkerson

Solvingmaximums-tflowinagraphwithnnodesandmedgesandc(e)=1 intimeT

SolvingedgedisjointpathsinagraphwithnnodesandmedgesintimeT+O(mn)

Page 29: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

(Node)DisjointPaths• Input: directedgraph! = $, &, B, C• Output: alargestsetofnode-disjoints-tpaths• Asetofs-tpaths\],… , \_ isnode-disjointifthepathsdonotshareanynodes

Alargesetofdisjointpathsmeanswecantolerateedge failures.

s t

Page 30: CS3000: Algorithms & Data Jonathan Ullman · 2018-12-06 · Image Segmentation •Separate image into foreground and background •We have some idea of: •whether pixel i is in the

Step1:TransformtheInput

InputGforNDP InputG’forEDP

s t s t