Convex Hull for Dynamic Data - Carnegie Mellon University · Convex Hull”: Have a working...

64
June 12, 2003 (joint work with Umut Acar, and Guy Blelloch) Convex Hull for Dynamic Data Convex Hull and Parallel Tree Contraction Jorge L. Vittes

Transcript of Convex Hull for Dynamic Data - Carnegie Mellon University · Convex Hull”: Have a working...

  • June 12, 2003(joint work with Umut Acar, and Guy Blelloch)

    Convex Hull for Dynamic DataConvex Hull and Parallel Tree Contraction

    Jorge L. Vittes

  • 07/15/03 Convex Hull for Dynamic Data 2

    Motivation

    ! Application data is dynamic! word processors: slowly changing text! graphics: render similar images! mobile phone networks: continuously moving hosts

    ! Important to handle dynamic data efficiently

  • 07/15/03 Convex Hull for Dynamic Data 3

    Dynamic Algorithms: Changing Data

    a b

    d

    c

    a b

    d

    c

    e

    a b

    d

    ce

  • 07/15/03 Convex Hull for Dynamic Data 4

    Kinetic Algorithms: Moving Data

    a b

    d

    c

    a b

    c

    d

    ab

    c

    d

    Time = 0Time = 1

    Time = 1+ε ... ∞

  • 07/15/03 Convex Hull for Dynamic Data 5

    How to invent Dynamic/Kinetic Algorithms! Just like any other algorithm. Think, ponder, divide, conquer...! Or, use adaptivity...

  • 07/15/03 Convex Hull for Dynamic Data 6

    Adaptivity! Makes a standard algorithm dynamic or kinetic! Requires little change to the standard algorithm! Can be done semi-automatically! Not all algorithms yield efficient adaptive algorithms

    ! Will talk about this more

  • 07/15/03 Convex Hull for Dynamic Data 7

    How does Adaptivity Work?! Represent a computation with a dynamic dependency graph! nodes = data, edges = dependencies! Sources = input, sinks = output, ! The user can

    ! change the input,! update the output

    ! Update: ! Take a changed node, ! Update all its children (the children are now changed)! Repeat until no more changed nodes

  • 07/15/03 Convex Hull for Dynamic Data 8

    Adaptivity Example

    fun f (a,b,c) = let u = a+b in if (u > 0) then g(u) else g(b+c) end

    u 3

    a b c

    a+b 1+b

    g(u)

    r

    if u>0 then g(u) else g(b+c)

    0.33

    1 32

  • 07/15/03 Convex Hull for Dynamic Data 9

    Adaptivity Example: Change

    u 3

    a b c

    a+b 1+b

    g(u)

    r0.33

    32-2 fun f (a,b,c) = let u = a+b in if (u > 0) then g(u) else g(b+c) end

    if u>0 then g(u) else g(b+c)

  • 07/15/03 Convex Hull for Dynamic Data 10

    Update

    u 0

    a b c

    a+b -2+b

    g(u)

    r0.5

    v 5

    g(v)

    -2 32 fun f (a,b,c) = let u = a+b in if (u > 0) then g(u) else g(b+c) end

    if u>0 then g(u) else g(b+c)

  • 07/15/03 Convex Hull for Dynamic Data 11

    Update

    u 0 5

    -2

    a32

    a+b -2+b b+c 2+c

    g(v)

    r0.5

    g'(v)

    b c

    v

    fun f (a,b,c) = let u = a+b in if (u > 0) then g(u) else g(b+c) end

    if u>0 then g(u) else g(b+c)

  • 07/15/03 Convex Hull for Dynamic Data 12

    Adaptivity and Stability! Adaptivity updates the result by rerunning the parts of the

    computation affected by the input change! It is efficient when the computation is “stable”,I.e.,

    computations on “similar” inputs are “similar”

    ! We apply the adaptivity technique to convex hulls! Result: Efficient Dynamic and Kinetic convex hulls

  • 07/15/03 Convex Hull for Dynamic Data 13

    1-D Convex Hull: Max and Min

    ! Just consider upper hull: Finding the maximum

    ! Consider two algorithms:! The March: March through the list ! The Tournament: pair up the elements and take the max of each pair

  • 07/15/03 Convex Hull for Dynamic Data 14

    Kinetic Maximum

    ! Numbers increase/decrease continuously in time ni(t) = ni + ci t

    time

    ni

    tgreen = 1 tblue = 3tred = 0

    n3(t) = 6-t

    n2(t) = 5

    n1(t) = 2+t

  • 07/15/03 Convex Hull for Dynamic Data 15

    Sampling

    time

    ni

    tgreen = 1 tblue = 3tred = 0

    n1(t) = 2+t

    n2(t) = 5

    n3(t) = 6-t

  • 07/15/03 Convex Hull for Dynamic Data 16

    Internal and External Events

    External event: Final result changes

    Internal event: Final result does not change but a test fails

  • 07/15/03 Convex Hull for Dynamic Data 17

    Proof Simulation via Certificates! A set of comparisons that prove the current maximum! Associate a certificate with each comparison

    ! certificate = comparison result + failure time ! Consider the times that a certificate fails

    ! We need an algorithm that updates the result as well as the certificates

    ! Use adaptivity to obtain to do the update efficiently

  • 07/15/03 Convex Hull for Dynamic Data 18

    Kinetic March

    4+t 5-t 1 7+1.5t 6 3 8 4

    0.5

    Time=0

    4+t 5-t 1 7+1.5t 6 3 8 4

    4 0.66

    0.66

    Time=0.5+ε

    4+t 5-t 1 7+1.5t 6 3 8 4Time=0.66+ε

  • 07/15/03 Convex Hull for Dynamic Data 19

    Kinetic March Performance

    ! O(n): Because an item in the beginning of the list could become the maximum and it will be compared to the rest of the list

    ! Not acceptable because computing from scratch takes O(n)

  • 07/15/03 Convex Hull for Dynamic Data 20

    The Kinetic Tournament

    7 4 1+t 5-t 6 3 8 4

    7 5-t 6 8

    7 8

    8Time = 0

    f = 2

  • 07/15/03 Convex Hull for Dynamic Data 21

    1+t

    The Kinetic Tournament

    7 4 1+t 5-t 6 3 8 4

    7 6 8

    7 8

    8Time=2+ε

    f=6

  • 07/15/03 Convex Hull for Dynamic Data 22

    1+t

    The Kinetic Tournament

    7 4 1+t 5-t 6 3 8 4

    7 6 8

    1+t 8

    8Time=6+ε f=7

  • 07/15/03 Convex Hull for Dynamic Data 23

    1+t

    The Kinetic Tournament

    7 4 1+t 5-t 6 3 8 4

    7 6 8

    1+t 8

    1+tTime=7+ε f=7

  • 07/15/03 Convex Hull for Dynamic Data 24

    Performance of Kinetic Tournament! Worst case log n time per event

    ! This kinetic algorithm is an adaptive version of the standard tournament algorithm for finding maximum

  • 07/15/03 Convex Hull for Dynamic Data 25

    2-D Convex Hull

    ! Many algorithms: Quick Hull, Graham Scan, Incremental, Merge Hull, Ultimate, Improved Ultimate...

    ! We will focus on the Quick Hull algorithm! Input: A list of points P! Output: The boundary points on the hull of P! Example: Input = [a,b,c,d] Output = [a,b,d]

    a b

    d

    c

  • 07/15/03 Convex Hull for Dynamic Data 26

    Quick Hull Example

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [A B C D E F G H I J K L M N O P]

  • 07/15/03 Convex Hull for Dynamic Data 27

    Quick Hull Example - Filter

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [ A B D F G H J K M O P]

  • 07/15/03 Convex Hull for Dynamic Data 28

    Quick Hull Example - Maximum

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G H J K M O P]

  • 07/15/03 Convex Hull for Dynamic Data 29

    Quick Hull Example - Filter

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [ [A B F J ] [J O P] ]

  • 07/15/03 Convex Hull for Dynamic Data 30

    Quick Hull Example - Maximum

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [[A B F J] [J O P] ]

  • 07/15/03 Convex Hull for Dynamic Data 31

    Quick Hull Example - Base Case

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [ [A B] [B J] [J O P] ]

  • 07/15/03 Convex Hull for Dynamic Data 32

    Quick Hull Example - Done

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [ [A B] [B J] [J O] [O P] ]

  • 07/15/03 Convex Hull for Dynamic Data 33

    Kinetic Quick Hull

    ! Two kinds of tests: Line-side and distance comparisons

    ! Filtering => Line Side ! Finding the furthest point => Distance comparisons

    ! Have certificates for these two events that is all

  • 07/15/03 Convex Hull for Dynamic Data 34

    Line Side Test Fails

    A

    C

    B

    D

    F

    G

    H

    IE

    J

    M

    K

    L

    N

    O

    P

    [ A B D F G H J K M O P]

  • 07/15/03 Convex Hull for Dynamic Data 35

    “I” is inserted in the middle of the list

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G I H J K M O P]

  • 07/15/03 Convex Hull for Dynamic Data 36

    Recompute Maximum

    A

    C

    B

    D

    F

    G

    H

    I

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G I H J K M O P]

  • 07/15/03 Convex Hull for Dynamic Data 37

    Dynamic Tournament - Random Trees

    7 4

    1

    5

    6 3 8 47

    6 87

    8

    8

    7

  • 07/15/03 Convex Hull for Dynamic Data 38

    Dynamic Tournament - Random Trees

    6 97 4

    1

    5

    6 3 8 47

    6 87

    8

    8

    7

  • 07/15/03 Convex Hull for Dynamic Data 39

    Dynamic Tournament - Random Trees

    6 97 4

    1

    5

    3 8 47

    87

    7

    9

    9

    9

    9

  • 07/15/03 Convex Hull for Dynamic Data 40

    Distance Comparison Fails - Case 1

    A

    C

    B

    D

    F

    G

    H

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G H J K M O P]

    I

  • 07/15/03 Convex Hull for Dynamic Data 41

    Distance Comparison Fails - Case 2

    A

    C

    B

    D

    F

    G

    H

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G H J K M O P]

    I

  • 07/15/03 Convex Hull for Dynamic Data 42

    “B” is the new maximum

    A

    C

    D

    F

    G

    H

    E

    J

    M

    K

    L

    N

    O

    P

    [A B D F G H J K M O P]

    I

    B

  • 07/15/03 Convex Hull for Dynamic Data 43

    New recursive calls

    A

    C

    D

    F

    G

    H

    E

    J

    M

    K

    L

    N

    O

    P

    [[A B] [J M O]]

    I

    B

  • 07/15/03 Convex Hull for Dynamic Data 44

    Experiments

  • 07/15/03 Convex Hull for Dynamic Data 45

    Summary of ConvexHull Work! Kinetic Algorithms for convex hulls using adaptivity

    ! Timothy Chan’s O(h log n) algorithm: Improved “Ultimate Convex Hull”: Have a working version

    ! QuickHull! Bounce events: Can maintain convex hull of points in a box -

    the points bounce off of the walls of the box! Streamlined library for kinetic convex hulls in the SML language

    ! A standard algorithm can be made kinetic in a few hours of work

  • 07/15/03 Convex Hull for Dynamic Data 46

    Parallel Tree Contraction

    Fundamental technique [Miller & Reif ‘85] Contraction proceeeds in rounds

    Each round shrinks the tree by a constant factor Expected O(logn) rounds

    Innovative Idea: Shrink the tree by local operations

  • 07/15/03 Convex Hull for Dynamic Data 47

    Parallel Tree Contraction

    ! Start with a tree! In each round:

    ! Each node flips a coin! If leaf node then rake! If degree=2 and flip = H, and neighbors = T then

    contract! Expected O(logn) rounds.

  • 07/15/03 Convex Hull for Dynamic Data 48

    Example

    HH T

    H

    T

    T

    H T H

  • 07/15/03 Convex Hull for Dynamic Data 49

    Contracting and Raking

    HH T

    H

    T

    T

    H T H

  • 07/15/03 Convex Hull for Dynamic Data 50

    H T T

    Contracting and Raking

  • 07/15/03 Convex Hull for Dynamic Data 51

    H T T

    Contracting and Raking (cont.)

  • 07/15/03 Convex Hull for Dynamic Data 52

    Done

    H

  • 07/15/03 Convex Hull for Dynamic Data 53

    Dynamic Trees Problem

    "Given a forest of weighted trees"Operations1.Link: edge insertion

    2.cut: edge deletion3.Queries" Heaviest edge in a subtree?" Heaviest edge on a path?

  • 07/15/03 Convex Hull for Dynamic Data 54

    " Sleator Tarjan ‘85" Amortized O(logn) and worst-case O(logn)

    " Topology Trees [Frederickson ‘93]" Ternary (degree-tree) trees" Worst case O(logn)

    " Top Trees [AlstrupHoLiTh ‘97]" Generalize Topology Trees for arbitrary degree

    " Idea: Trees as paths

    Data Structures for Dynamic Trees

  • 07/15/03 Convex Hull for Dynamic Data 55

    Dynamic Parallel Tree Contraction

    ! Keep a copy of each round of the initial run.! Each round affects next round.! The nodes that “live” to the next round copy their

    neighbors scars, and pointers to them.! Dependencies are based on what the node reads to do

    its work.

  • 07/15/03 Convex Hull for Dynamic Data 56

    Dynamic Parallel Tree Contraction

    HH TH

    TT H T HHH TH

    TT H T H

    T

    H

    TTT H T T

    xx x

    x xH

    x xT T

  • 07/15/03 Convex Hull for Dynamic Data 57

    Propagation! If any data changes nodes whose action depend on

    that data are woken up.! Wake-up only those nodes that get affected by a

    change.! Run same code as in original run.! Expected constant amount of nodes woken up per

    round.

  • 07/15/03 Convex Hull for Dynamic Data 58

    Change an edge

    HH TH

    TT H T HHH TH

    TT H T H

    T

    H

    TTT H T T

    xx x

    x xH

    x xT T

  • 07/15/03 Convex Hull for Dynamic Data 59

    Three nodes woken up

    HH TH

    TT H T HHH TH

    TT H T H

    T

    H

    TTT H T T

    xx x

    x xH

    x xT T

  • 07/15/03 Convex Hull for Dynamic Data 60

    Nodes rerun code, more nodes woken up

    HH TH

    TT H T HHH TH

    TT H T H

    T

    H

    TTT H T T

    xx x

    x xH

    x xT T

  • 07/15/03 Convex Hull for Dynamic Data 61

    Propagation continued

    HH TH

    TT H T HHH TH

    TT H T H

    T

    H

    TTT H T T

    xx x

    x xH

    x xT T

  • 07/15/03 Convex Hull for Dynamic Data 62

    Experimental ResultsNumber Queued when remarking Nodes

    y = 17.566Ln(x) - 25.282R2 = 0.9987

    0.00

    50.00

    100.00

    150.00

    200.00

    250.00

    0 50000 100000 150000 200000 250000 300000 350000

    Total number of Nodes

    Num

    ber Q

    ueue

    d

    Number in QueueLog. (Number in Queue)

  • 07/15/03 Convex Hull for Dynamic Data 63

    Work In Progress! Analyzing Power of the data structure (what it can and cannot

    do)! Different Applications! Analyzing Running times for:

    ! Different changes.! Unbalanced Trees.

  • 07/15/03 Convex Hull for Dynamic Data 64

    Conclusion and Future Work! ConvexHull

    ! Used adaptivity to solve the kinetic convex hull problem. ! Encouraging results.! Adaptivity makes writing dynamic/kinetic algorithms a simple

    edition on the standard algorithm! The quickhull algorithm updates based on events efficiently

    in the expected case. ! Parrallel Tree Contraction

    ! Efficient times O(log(n)) expected time for an update.! Future Work:

    ! More Applications