cse 521: design and analysis of algorithms time & place t, th 1200-120 pm in cse 203 people...

27
cse 521: design and analysis of algorithms ime & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) gorithm Design by Kleinberg and Tardos ng homework (approx. bi-weekly problem sets) take-home midterm in-class final exam te: http://www.cs.washington.edu/521/

Upload: davis-silver

Post on 15-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

cse 521: design and analysis of algorithms

Time & place T, Th 1200-120 pm in CSE 203

People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs)

Book Algorithm Design by Kleinberg and Tardos

Grading 50% homework (approx. bi-weekly problem sets) 20% take-home midterm 30% in-class final exam

Website: http://www.cs.washington.edu/521/

Page 2: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something a little bit different

assume you know: asymptotic analysis basic probability basic linear algebra dynamic programming recursion / divide-and-conquer graph traversal (BFS, DFS, shortest paths)

so that we can cover: nearest-neighbor search spectral algorithms (e.g. pagerank) online algorithms (multiplicative update) geometric hashing + graph algorithms, data structures, network flow, hashing, NP-completeness, linear programming, approx. algorithmsdue: april 9th

Page 3: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

case study: nearest-neighbor search

universe of objects

subset of objects forms the database

query

Goal: Quickly respond with the database object most similar to the query.

AAACAACTTCCGTAAGTATAridiculousse

Page 4: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

formal model

subset of objects forms the database

query

Goal: Quickly respond with the database object most similar to the query.

U = universe (set of objects)d(x,y) = distance between two objects

Assumptions:

d(x,y) = d(y,x) for all x,y 2 U(symmetry)

d(x,y) · d(x,z) + d(z,y) for all x,y,z 2 U

(triangle inequality)

d(x,x) = 0 for all x 2 U

Problem: Given an input database D µ U: preprocess D (fast, space efficiently) so that queries q 2 U can be answered very quickly, i.e. return a* 2 D such that d(q,a*) = min { d(q, x) : x 2 D }

Page 5: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

other considerations

subset of objects forms the database

query

Problem: Given an input database D µ U: preprocess D (fast, space efficiently) so that queries q 2 U can be answered very quickly, i.e. return a* 2 D such that d(q,a*) = min { d(q, x) : x 2 D }

Is it expensive to compute d(x,y)?AAACAACTTC

CGTAAGTATA

ridiculousse

Should we treat the distance functionand objects as a black box?

Page 6: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

primitive methods

query

[Brute force: Time]Compute d(query, x) for everyobject x 2 D, and return the closest.

Takes time ¼ |D| ¢ (distance comp. time)

[Brute force: Space]Pre-compute best response to everypossible query q 2 U.

Takes space ¼ |U| ¢ (object size)

Dream performance: query timeO(log jDj)

O(jD j)space

Page 7: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something hard, something easy

Page 8: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something hard, something easy

Page 9: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something hard, something easy

All pairwise distances are equal: d(x,y) = 1 for all x,y 2 D

0.91.0

1.01.0

1.0 1.0

“CURSE OF DIMENSIONALITY”

Problem: … so that queries q 2 U can be answerd quickly, i.e. return a* 2 D such that d(q,a*) = min { d(q, x) : x 2 D }

Page 10: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something hard, something easy

All pairwise distances are equal: d(x,y) = 1 for all x,y 2 D

0.91.0

1.01.0

1.0 1.0

“CURSE OF DIMENSIONALITY”

²-Problem: … so that queries q 2 U can be answerd quickly, i.e. return a 2 D such that d(q,a) · (1+²) d(q,D)

Can sometimes solve exact NNS byfirst finding a good approximation

Page 11: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

something easier

Let’s suppose that U = [0,1] (real numbers between 0 and 1).

0 1

Answer: Sort the points D µ U in the preprocessing stage.To answer a query q 2 U, we can just do binary search.

To support insertions/deletions in time, can use a BST. (balanced search tree)

How much power did we need?Can we do this just using distance computations d(x,y)? (for x,y 2 D)

Basic idea: Make progress by throwing “a lot” of stuff away.

Page 12: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

extending the basic idea

Definition: The ball of radius ® around x 2 D is

®

Page 13: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

extending the basic idea

Definition: The ball of radius ® around x 2 D is

®

Page 14: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

extending the basic idea

Definition: An ®-net in D is a subset N µ D such that1) Separation: For all x,y 2 N, d(x,y) ¸ ®2) Covering: For all x 2 D, d(x,N) · ®

Greedy construction algorithm:

Start with N = ;.As long as there exists an x 2 Dwith d(x,N) > ®, add x to N.

So for every ® > 0, we can constructan ®-net N(®) in O(n2) time, wheren = |D|.

Page 15: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

basic data structure: hierarchical nets

N(1)

N(2)

N(2i)

N(2i+1)

…w

ith p

oin

ters b

etw

een th

e le

vels

Search algorithm: Use the ®-net to find a radius 2® ball. Use the ®/2-net to find a radius ® ball. Use the ®/4-net to find a radius ®/2 ball.

Page 16: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

basic data structure: hierarchical nets

Data structure:

Page 17: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

algorithm: traverse the nets

Data structure:

Algorithm: Given input query q 2 U,

Page 18: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

algorithm: traverse the nets

Algorithm: Given input query q 2 U,

Page 19: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

running time analysis?

Algorithm: Given input query q 2 U,

Query time =

Nearly uniform point set:For u,v 2 Lx,i, d(u,v) 2 [2i-1, 2i+2]

Page 20: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

curs’ed hamsters

All pairwise distances are equal: d(x,y) = 1 for all x,y 2 D

0.91.0

1.01.0

1.0 1.0

“CURSE OF DIMENSIONALITY”

Page 21: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

Given a metric space (X,d), let ¸(X,d) be the smallest constant ¸ such thatevery ball in X can be covered by ¸ balls of half the radius.

r

= 5

The intrinsic dimension of (X,d) is the value

Page 22: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

We can bound the query time of our algorithm in terms of the intrinsicdimension of the data…

Query time =

Claim: |Lx,i| · [¸(X,d)]3

Proof: Suppose that k = |Lx,i|. Then we need at least k balls of radius 2i-2 to cover B(x,2i+1), because a ball of radius 2i-2 can cover at most one point of Ni-1. But now we claim that (for any r) every ball of radius r in X can be covered by at most [¸(X,d)]3 balls of radius r/8, hence k · [¸(X,d)]3.

Page 23: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

But now we claim that (for any r) every ball of radius r in X can becovered by at most [¸(X,d)]3 balls of radius r/8, hence k · [¸(X,d)]3.

r

A ball of radius r can be covered ¸ balls of radius r/2, hence by ¸2 balls of radius r/4, hence by ¸3 balls of radius r/8.

Page 24: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

We can bound the query time of our algorithm in terms of the intrinsicdimension of the data…

Query time =

Claim: |Lx,i| · [¸(X,d)]3

Proof: Suppose that k = |Lx,i|. Then we need at least k balls of radius 2i-2 to cover B(x,2i+1), because a ball of radius 2i-2 can cover at most one point of Ni-1. But now we claim that (for any r) every ball of radius r in X can be covered by at most [¸(X,d)]3 balls of radius r/8, hence k · [¸(X,d)]3.

Page 25: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

We can bound the query time of our algorithm in terms of the intrinsicdimension of the data…

Query time =

Claim: |Lx,i| · [¸(X,d)]3

Proof: Suppose that k = |Lx,i|. Then we need at least k balls of radius 2i-2 to cover B(x,2i+1), because a ball of radius 2i-2 can cover at most one point of Ni-1. But now we claim that (for any r) every ball of radius r in X can be covered by at most [¸(X,d)]3 balls of radius r/8, hence k · [¸(X,d)]3.

Page 26: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

intrinsic dimensionality

We can bound the query time of our algorithm in terms of the intrinsicdimension of the data…

Query time =

- Generalization of binary search (where dimension = 1)- Works in arbitrary metric spaces with small intrinsic dimension- Didn’t have to think in order to “index” our database- Shows that the hardest part of nearest-neighbor search is

0.91.0

1.01.01.0 1.0

Page 27: Cse 521: design and analysis of algorithms Time & place T, Th 1200-120 pm in CSE 203 People Prof: James Lee (jrl@cs) TA: Thach Nguyen (ncthach@cs) Book

wrap up

- Only gives approximation to the nearest neighbor- Next time: Fix this; fix time, fix space + data structure prowess- In the future: Opening the black box; NNS in high dimensional spaces- Bonus: Algorithm is completely intrinsic (e.g. isomap)